Board index » delphi » OpenGL question

OpenGL question


2004-01-21 08:25:18 AM
delphi111
Hi!
I'm writing an OpenGL control (Descent of TCustomControl) to do draw fast 2D
graphics. The problem is, that the component won't Clear at creation. I have
to clear it from the program that is using it. What am I doing wrong???
Thanks,
Patrick
P.S. Does anyone know if it is a lot faster to use OpenGL, than to write to
a DIB in assembler?
constructor TOpenGLControl.Create(AOwner: TComponent);
var
pfd : TPixelFormatDescriptor;
iPixelFormat: Integer;
begin
inherited Create(AOwner);
FillChar(pfd, SizeOf(pfd),0);
with pfd do
begin
nSize := SizeOf(pfd);
nVersion := 1;
dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
iPixelType := PFD_TYPE_RGBA;
iLayerType := PFD_MAIN_PLANE;
cDepthBits := 32;
cColorBits := 24;
end;
iPixelFormat := ChoosePixelFormat(Canvas.Handle, @pfd);
SetPixelFormat(Canvas.Handle, iPixelFormat, @pfd);
hrc := wglCreateContext(Canvas.Handle);
Clear;
end;
procedure TOpenGLControl.Clear;
begin
wglMakeCurrent(Canvas.Handle, hrc);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
SwapBuffers(wglGetCurrentDC);
end;
 
 

Re:OpenGL question

Patrick Veenstra writes:
Quote
Hi!

I'm writing an OpenGL control (Descent of TCustomControl) to do draw
fast 2D graphics. The problem is, that the component won't Clear at
creation. I have to clear it from the program that is using it. What
am I doing wrong???

Thanks,
Patrick

P.S. Does anyone know if it is a lot faster to use OpenGL, than to
write to a DIB in assembler?

Speedwise and concerning 2D stuff : I would assume OpenGL
to use the Hardware accelerator if possible.
This means as soon as you use some geometry and/or rendering
operations in hardware you have won against ASM and bitblt.
I Would also assume a clearwindow to be faster in hardware.
Rene
--
Ing.Buro R.Tschaggelar www.ibrtses.com
Your newsgroups @ www.talkto.net
 

Re:OpenGL question

Thanks!!!
About 2D openGL graphics:
Does anyone know if someone already made a compent that lets you use a
OpenGL canvas, as a Delphi one, i.e. using absolute position (a canvas of
600x400 pixels, not -1 to 1 single floating point), to draw objects?
Regards,
Patrick
 

Re:OpenGL question

"Patrick Veenstra" <XXXX@XXXXX.COM>writes
Quote
Thanks!!!

About 2D openGL graphics:
Does anyone know if someone already made a compent that lets you use a
OpenGL canvas, as a Delphi one, i.e. using absolute position (a canvas of
600x400 pixels, not -1 to 1 single floating point), to draw objects?
Hmm... Have a look at "gluOrtho2D". In fact, you may simply want to have a
look at some OpenGL web sites... to learn the basics...
nehe.gamedev.net/
fly.cc.fer.hr/~unreal/theredbook/
Alan.
 

Re:OpenGL question

There is a GLCanvas class & unit in GLScene that does that.
(glscene.org), this particular class & unit can be
used independantly from the rest (only text output requires
extra stuff).
Eric