PDA

View Full Version : GLDirectOpengl for 2D graphics



Ray
27-11-2010, 04:15 PM
I have very fast 2D graphics working very nicely using the GLDirectOpengl, with anti-aliasing. I am drawing 800 000 pixels, and am getting very high frame rates, over 50 FPS.

procedure TForm1.GLDirectOpenGL1Render(Sender: TObject;
var rci: TRenderContextInfo);
var
i,j, x, y : Integer;
glc : TGLCanvas;
r : TRect;
color : TColor;

begin
glc:=TGLCanvas.Create(glsceneviewer1.width,glscene viewer1.height);


{ for x:=0 to 1000 do
for y:=0 to 800 do
begin
glc.PenColor:=clyellow;
glc.PlotPixel(x,y);
end;}

glc.Free;
end;

I have a few questions:

1. How would one do 2d Graphics using OpenGL and not glsscene? I like glscene, but am looking for something with minimal overhead.

2. With the code above, and without using PlotPixel, is there any way to bitblt a bmp to the screen? Or do I need to create a polygon and put a texture onto it?

User137
28-11-2010, 11:44 AM
A whole picture like bmp drawn as texture with quad is definitely 10000 times faster than plotting it in pixels.

Andru
28-11-2010, 11:51 AM
How would one do 2d Graphics using OpenGL and not glsscene? I like glscene, but am looking for something with minimal overhead.
ZenGL (http://www.pascalgamedevelopment.com/showthread.php?6404-Description) :)

Or do I need to create a polygon and put a texture onto it?
Yes, this is the fastest way to draw image on the screen, but with any 2d engine you will not have to worry about this.

Ray
28-11-2010, 01:15 PM
Is there an example for doing the following with GLDirectOpengL:

1. Draw some lines. - Done
2. Draw some test. - Done
3. Draw a bitmap or dib on the GLDirectOpengl surface.

For the last one, I do not see any bitmap type functions in the unit for GLDirectOpengl. What would the code be to draw a simple bitmap? Or do I need to use all the 3D stuff.

Ray
28-11-2010, 01:55 PM
Ok, did it like this:

//put a glplane onto the viewing area (orientate it so that it looks 2d) and assign a bitmap to it. Is there a faster way?

procedure TForm1.SpeedButton2Click(Sender: TObject);
var
rbitmap : tbitmap;
begin
rbitmap:=tbitmap.Create;
rbitmap.SetSize(200,200);
// glplane1.Material.Texture.Image.AssignToBitmap(rbi tmap);
glplane1.Material.Texture.Image.Assign(rbitmap);

end;

Ray
28-11-2010, 03:22 PM
Okay I've been experimenting with this:

procedure TForm1.GLDirectOpenGL1Render(Sender: TObject;
var rci: TRenderContextInfo);
var
i,j, x, y : Integer;
color : TColor;
begin
glc:=TGLCanvas.Create(glsceneviewer1.width,glscene viewer1.height);

//method 1
with glc do
begin
for x:=0 to 499 do
for y:=0 to 499 do
begin
PenColor:=rgb(random(255),random(255),random(255)) ;
plotpixel(x,y);
end;
end;



glc.Free;

//method 2
for x:=0 to 499 do
for y:=0 to 499 do
begin
testdib.Pixels[x,y]:=rgb(random(255),random(255),random(255));
end;
glplane1.Material.Texture.Image.Assign(testdib);
end;

I am drawing 2 blocks using different methods. Method 1 is to use the glcanvas. Method 2 is to use a glplane, draw the pixels on the dib and then copy them to the glplane's material. Writing to the DIB itself is very very fast and doesn't slow things sown much at all. The problem is trying to get the dib onto the plane.

Method 1 by itself I get 50FPS.

Method 2 by itself I get 15 FPS

Method 2 without assigning the testdib to the plane's material, I get 60FPS.

So I conclude that Method 2 has a bottleneck of glplane1.Material.Texture.Image.Assign(testdib);

My questions are:

1. Is there any way to get the tdib into the glplane faster than using assign?

2. OR is there a completely different (and much faster) way of putting pixels on the screen than using the 2 methods above?