0

I am using the latest GLScene trunk for Delphi XE2 and I have worked on a GUI-ish type of project which uses 3D instead of 2D to draw GUI elements on screen.

It works, but the graphics placement isn't pixel-perfect for obvious reasons.

I have managed to map the 3D view so that 1 pixel on TGLSceneViewer is more or less 1 pixel on screen. That's good enough for me.

However I am giving up the idea of using 3D for my GUI and I will instead focus on using GLScene for2D graphics-representation exclusively since it is GPU accelerated.

Then I remember using Projective Transformation in a previous project where I used Graphics32 for my GUI.

With projective transformation I could simply plot points in a 3D space, read the 3D-coordinates of those points, convert the coordinates to 2D-coordinates and apply those to the TBitmap32 Projective Transformation parameters, and viola, I had 3D capabilites in my software.

So, my question is:

Is it possible to "stretch" a texture in GLScene or OpenGL so that the texture fits between 4 points, or within a plane, so that whenever I move the corner of a plane to a new position, the texture will be stretched accordingly?

That way I could use GLScene for 2D graphics, but do some simple trickery to make things look like it's 3D.

The link below is pointed to an image on the internet which is a visual representation of what I am looking for: https://i.stack.imgur.com/hDdqa.png

genpfault
  • 51,148
  • 11
  • 85
  • 139
xaid
  • 740
  • 6
  • 18
  • Why not use FireMonkey? It's native, 2D and 3D, and is hardware accelerated (including the 2D version.) Pretty much everything you want, without the effort of writing it from scratch yourself. – David Sep 30 '14 at 13:54
  • The performance of Firemonkey isn't that good if I recall it correctly. Or am I wrong here? – xaid Sep 30 '14 at 14:39
  • There were issues when it fell back to GDI+ when it was unable to use Direct2D in early versions (XE4 and below I think.) So long as you're using Vista or above you should be fine. I'm using it in XE6 daily for 2D work and it's great. Like any library you need to know a few things, eg it's handy to cache your text objects if you draw them to screen a lot, etc. There are similar things you need to know for the VCL too! Overall it works well and is fast, and I'm happy. – David Sep 30 '14 at 14:42
  • 1
    I have a copy of XE6 at the office but I haven't used it much. I will look at it and see what performances I get – xaid Sep 30 '14 at 15:31
  • 1
    Alright so I am playing with Delphi XE6 right now. I will post a new question as it seems that firemonkey is the way to go instead of me re-inventing the wheel. Thank you for the information. – xaid Sep 30 '14 at 21:53
  • @DavidM I tried Firemonkey on XE6 and I am not pleased at all. The performance is terrible IMHO. When I add a 3D Viewport and then add 512 small TLayer3D and animate them I get around 10 frames per second. However when I use my own framework that I've been working on for the past 1.5 months I can add 1024 small planes (equivalent to TLayer3D in Firemonkey) and I get around 60 FPS. – xaid Oct 01 '14 at 10:40
  • That's quite a lot! Why do you need so many? Remember FMX's TLayer3D is intended to contain controls, ie is similar to a TForm or TFrame in the 3D space. Hundreds of them is a lot. I think you're after something much small or lighter-weight? – David Oct 01 '14 at 17:34
  • @DavidM I'm just pushing performance to the limit. And from my own experience and based on other peoples experience, the FMX performance is not good at all. My customers deserve superb quality and performance and I won't settle with anything below that. – xaid Oct 01 '14 at 17:56
  • What about if you use 512 TImage3D-s? They are lightweight - much lighter than the heavy TLayer3D - and are meant just to hold a picture, ie a texture. Ie, using one of those will address your question since the texture will be mapped across the four-sided rectangle. If *those* are slow I will concede defeat :) (But make sure your 3D form is running with DX, ie you're using XE5/6/7.) – David Oct 02 '14 at 09:43
  • @DavidM Hello, sorry for the delayed answer. I have had no luck with TImage3D objects or TSolidLayer3D. Activating DirectX does not make any difference. The performance is very poor. Much poorer than it should be. Thanks for your help. – xaid Oct 06 '14 at 07:43

1 Answers1

1

assuming you are not implementing something crazy in your shaders, or that you are using fixed function pipeline functionality this should be fairly trivial.

Texture coordinates in OpenGL are always normalized, which means they fall with in the range of [0-1];

So basically as long as when you are drawing your objects you always set the coordinates of the texture to be maximum 1 and minimum 0 you should always have the texture filling your quad.

Could you possibly provide the code you are using to draw your 4 points? I might be able to help with that if I can see it.

Daniel
  • 589
  • 4
  • 19
  • I have no code available since I use GLScene and I basically add a TGLPlane object to the scene which consists of 4 points. I don't know how manipulate those 4 points as GLScene handles everything. So I cannot even try what you are suggesting. However I am investigating GLScene right now to see how to manipulate the 4 points of a TGLPlane. – xaid Sep 30 '14 at 14:41
  • Well as long as your texture coordinates from your plane are using the normalized coordinates you shouldn't have any problem. – Daniel Sep 30 '14 at 19:01