Results 1 to 4 of 4

Thread: Possible bug on Opengl template ?

  1. #1

    Possible bug on Opengl template ?

    I already posted a thread on sulaco website forum without reply ...

    If you're using a c++ style template for delphi, there's a little bug (in my opinion) in the windowed mode.. (the one i use although, there is a large number of template on the web)

    the viewport is not properly set because the height of the title bar is included.

    as an example, if you use glreadpixels you can notice there's a black area in the window titlebar's place.

    In the following code the parameters Width and Height are no longer used.(so they can be deleted)
    It works for both windowed and fullscreen mode.

    Code:
    procedure glResizeWnd(Width, Height : Integer);
    var
     ClientRect : TRect;
     ScreenHeight, ScreenWidth : integer
    begin
      GetClientRect(h_wnd,ClientRect);
      ScreenHeight := ClientRect.bottom - ClientRect.Top;
      ScreenWidth := ClientRect.Right - ClientRect.Left;
    
      if (ScreenHeight = 0) then                // prevent divide by zero exception
        ScreenHeight := 1;
    
      glViewport(0, 0, ScreenWidth, ScreenHeight);    // Set the viewport for the OpenGL window
      glMatrixMode(GL_PROJECTION);        // Change Matrix Mode to Projection
      glLoadIdentity();                   // Reset View
      gluPerspective(45.0, ScreenWidth/ScreenHeight, 1.0, 100.0);  // Do the perspective calculations. Last value = max clipping depth
      glMatrixMode(GL_MODELVIEW);         // Return to the modelview matrix
      glLoadIdentity();                   // Reset View
    end;
    what do you think ?

  2. #2

    Possible bug on Opengl template ?

    No. existing code for resizing window is proper, since glResizeWnd is called with proper parameters from the message loop. the real problem is, that the viewport is definetly not set right when the window is created(it does not take title bar into account).
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    Possible bug on Opengl template ?

    So the best way to prevent this problem would be to call another procedure than glresizewnd in the glcreatewnd function ?

  4. #4

    Possible bug on Opengl template ?

    Quote Originally Posted by Lowercase
    So the best way to prevent this problem would be to call another procedure than glresizewnd in the glcreatewnd function ?
    no. but your GetClientRect solution is not proper either, since the dimensions will match those retrieved from the message queve and fix something that is not broken.

    my solution:

    find call to CreateWindowExA and make it use: Width - 1

    after calling showwindow, setfocus and setforeground window, etc.. add this:

    // fix the window and window projection, this will also call GLResizeWnd
    MoveWindow(h_wnd,
    (GetSystemMetrics(SM_CXSCREEN) div 2) - (Width div 2),
    (GetSystemMetrics(SM_CYSCREEN) div 2) - (Height div 2),
    Width, Height, True);
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •