Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlaying graphics on top of OpenGL render context

I am trying to overlay graphics on top of my OpenGL render scene.

I have managed to get it up and running but the drop in FPS is somewhat too much.

I am currently using GLScene in combination with Graphics32.

What I do is to render the GLScene Rendering Context to a bitmap, apply that bitmap to a TImageView32, and do some final UI touches inside the TImage32.

The code I am using to render to a bitmap is the following, which also reduces FPS is:

procedure RenderToBitmap;
  var b: TBitmap;
begin
  b:=TBitmap.Create;
  b:=GLSceneViewer.Buffer.CreateSnapShotBitmap; //TGLSceneViewer
  ImgVwr32.Bitmap.Assign(b); //TImageViewer32
  b.Free;
end;

I have tried some other code (see below), which gives me a realtime rendering, but I can not modify the "Bitmap" property of the ImageViewer32. In other words: The GLScene Rendering context is being rendered, but none of my own graphics is rendered. The code:

//The following line is put inside the FormCreate call
GLSceneViewer.Buffer.CreateRC(GetDC(ImgVwr32.Handle),false);

How can I properly overlay graphics on top of the rendering context, or copy the rendering context output, without losing FPS?

like image 563
xaid Avatar asked Feb 11 '23 20:02

xaid


1 Answers

Well, by avoiding the whole GPU→CPU→GPU copy roundtrips. Upload your overlay into a OpenGL texture and draw that over the whole scene using a large textured quad.

OpenGL is not a scene graph, it's just a somewhat more sophisticated drawing API. You can change the viewport and transformation parameters at any time without altering the pixels drawn so far. So it's easy to just switch into a screen space coordinate system and draw the overlay using that.

like image 142
datenwolf Avatar answered Feb 19 '23 23:02

datenwolf