Results 1 to 7 of 7

Thread: problem: got an OpenGL error at the first line of OnCreate event.

  1. #1
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    problem: got an OpenGL error at the first line of OnCreate event.

    Hi!

    I made a procedure to trap the OpenGL errors.
    Code :
    procedure TForm1.finderr;
    {some code}
    private
      errorcode: GLenum;
    {some code}
    procedure TForm1.finderr;
    begin
      errorcode:= glGetError;
      if errorcode<>GL_NO_ERROR then
        MessageDlg('glerr:'+ gluErrorString(errorcode),
                   mtInformation, [mbOK], 0);
    end;
    then I call finderr routine at the first line of OnCreate event of the form. The whole project only have one form.
    An error message still pops up when I run the program. Message is "Invalid Operation".

    I don't know where is the error made, because I think this is the first point the the whole execution path.

    Can you gie me some idea?

    Thank you!

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    Re: problem: got an OpenGL error at the first line of OnCreate event.

    you cannot call glgeterror before you have an active context.. to call it is an invalid operation, so thats why you get that message

  3. #3
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    Re: problem: got an OpenGL error at the first line of OnCreate event.

    Thank you!

    I tried to insert "finderr;" at different positions(indicated in the code}, every time only one "finderr;" in the whole program. However, I still got the same error messages each time. What can I do now?

    Code :
    procedure TForm1.FormCreate(Sender: TObject);
    var
      pfd: TPixelFormatDescriptor;
      FormatIndex: integer;
    begin
      {finderr}
      fillchar(pfd, SizeOf(pfd),0);
      {finderr}
      with pfd do
      begin
        nSize := sizeOf(pfd);
        nVersion := 1;
        dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
        iPixelType := PFD_TYPE_RGBA;
        cColorBits := 24;
        cDepthBits := 32;
        iLayerType := PFD_MAIN_PLANE;
      end;
      {finderr}
      FormatIndex := ChoosePixelFormat(Canvas.Handle,@pfd);
      SetPixelFormat(Canvas.Handle,FormatIndex, @pfd);
      {finderr}
      GLContext := wglCreateContext(Canvas.Handle);
      {finderr}
      wglMakeCurrent(Canvas.Handle, GLContext);
      {finderr}
    {some code}
    end;

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    Re: problem: got an OpenGL error at the first line of OnCreate event.

    only the last err check is valid..

  5. #5
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    Re: problem: got an OpenGL error at the first line of OnCreate event.

    oh, thank you! I will check that procedure's documentation.

  6. #6
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    Re: problem: got an OpenGL error at the first line of OnCreate event.

    Hi! This time I didn't use "finderr" function to test that error, but indivitually test output of each commands, with the following code. It pops up "Error2", which means the command:
    GLContext := wglCreateContext(Form1.Canvas.Handle);
    has problem, what shall I do?

    Thank you!

    PS: I already tested SetPixelFormat and it returns true.

    Code :
    procedure TForm1.FormCreate(Sender: TObject);
    var
      pfd: TPixelFormatDescriptor;
      FormatIndex: integer;
    begin
      fillchar(pfd, SizeOf(pfd),0);
      with pfd do
      begin
        nSize := sizeOf(pfd);
        nVersion := 1;
        dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
        iPixelType := PFD_TYPE_RGBA;
        cColorBits := 24;
        cDepthBits := 32;
        iLayerType := PFD_MAIN_PLANE;
      end;{with}
      FormatIndex := ChoosePixelFormat(Form1.Canvas.Handle,@pfd);
      if (FormatIndex=0) then MessageDlg('Error1',mtInformation,[mbOK], 0);
      SetPixelFormat(Form1.Canvas.Handle,FormatIndex, @pfd);
      GLContext := wglCreateContext(Form1.Canvas.Handle);
      if (GLContext=0) then MessageDlg('Error2'mtInformation,[mbOK],0);

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    Re: problem: got an OpenGL error at the first line of OnCreate event.

    That should work in most opengl implementations, however, opengl actually wants the 'CS_OWNDC' flag to be set for thw window that should contain the opengl window.

    One easy way to get a window with that flag is to use my Draw control, its just a canvas with owndc set in it, since it doesnt like that the DC handle can be different each time if you do like that..
    how ever its unprobable that it should be an error when all is called in the same function.

    But if you want to try it :
    http://mazy.annat.nu/files/Delphi/Components/draw.pas

    Install that and just put it on the window and use Draw1.canvas.handle instead of the forms one and try if it could be that error.

Similar Threads

  1. Replies: 0
    Last Post: 04-10-2012, 04:40 PM
  2. Problem on Mouse Event
    By beams in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-21-2011, 03:16 PM
  3. Problem - Event Handling for an OpenGL window - and MFC/Win32 App
    By loopguru in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 11-04-2002, 11:56 AM
  4. Problem - Event Handling for an OpenGL window - and MFC/Win32 App
    By loopguru in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-30-2002, 09:51 PM
  5. OpenGL error in Quake3 message line
    By moosetrance in forum OpenGL: User Software
    Replies: 3
    Last Post: 02-04-2001, 03:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean