Hi! I’m using Delphi5 to do OpenGL programming. The following code is from a book, it have been working, but doesn’t work now. Can you help to see how to fix it?
Thank you!
procedure TForm1.FormCreate(Sender: TObject);
var
pfd: TPixelFormatDescriptor;
FormatIndex: integer;
begin
ShowMessage(‘version=’+glGetString(GL_VERSION)+’;’
+#13+‘vendor=’+glGetString(GL_VENDOR)+’;’);
{error checking}
errorCode := glGetError;
if errorCode<>GL_NO_ERROR then
raise Exception.Create(‘Error in Paint’#13+
gluErrorString(errorCode));
end; {FormCreate}
The information given by watching variables:
FormatIndex=1
GLContext=0
errorCode=1282
also, the ShowMessage statement tells that both vendor and version returns empty string.
I remember this program worked in summer this year, but it doesn’t work during these couple month, is it possible to because of the update of Windows? I’m under Windows 2000
Don’t use the handle of the form’s canvas, use the form’s handle itself instead. I see a lot of people using the handle of a canvas for creating their contexts, but that’s wrong. So for example just do
ShowMessage(‘version=’+glGetString(GL_VERSION)+‘;’
+#13+‘vendor=’+glGetString(GL_VENDOR)+‘;’);
{error checking}
errorCode := glGetError;
if errorCode<>GL_NO_ERROR then
raise Exception.Create(‘Error in Paint’#13+
gluErrorString(errorCode));
running result:
FormatIndex becomes 0, other variables do not change.
Using a call to GetDC in every function isn’t good, since you’ll most likely get different DCs which all take up resource you can’t easily free later. And moreover, SetPixelFormat, wglCreateContext and wglMakeCurrent also need the DC instead of just the handle.
If the above approach isn’t working, then make sure that your pixelformat is really supported and also valid.
[This message has been edited by PanzerSchreck (edited 12-29-2003).]