Page 1 of 1

Wierd OpenGL Problems

Posted: Tue Jun 15, 2004 2:34 am
by Raine3D
Instead of starting in a window, the entire screen goes black as if its in fullscreen. Is it my code, or a bug? (Im using a userlib that allows me to pass floats into glDepth and glPerspective, forgot the name)

Code: Select all

;-----------------------
;-OpenGL Test-----
;-Raine3D-----------
;-----------------------

XIncludeFile "opengl.pbi"

Global hDC.l
Global hRC.l
Global hWnd.l
Global pFormat.l

pFD.PIXELFORMATDESCRIPTOR

#WINDOWSETTINGS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget

If (hWnd = OpenWindow(0, 0, 0, 320, 240, #WINDOWSETTINGS, "OpenGL Test")) = 0
  MessageRequester("Error", "Could not create window.", 0)
  End
EndIf

hDC = GetDC_(hWnd)
If hDC = 0
  MessageRequester("Error", "Could not create device context.", 0)
  End
EndIf

pFD\nSize = SizeOf(pFD)
pFD\nVersion = 1
pFD\dwFlags = #PFD_DRAW_TO_WINDOW | #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER
pFD\iPixelType = #PFD_TYPE_RGBA
pFD\cColorBits = 32
pFD\cRedBits = 0
pFD\cRedShift = 0
pFD\cGreenBits = 0
pFD\cGreenShift = 0
pFD\cBlueBits = 0
pFD\cBlueShift = 0
pFD\cAlphaBits = 0
pFD\cAlphaShift = 0
pFD\cAccumBits = 0
pFD\cAccumRedBits = 0
pFD\cAccumGreenBits = 0
pFD\cAccumBlueBits = 0
pFD\cAccumAlphaBits = 0
pFD\cDepthBits = 16
pFD\cStencilBits = 0
pFD\cAuxBuffers = 0
pFD\iLayerType = #PFD_MAIN_PLANE
pFD\bReserved = 0
pFD\dwLayerMask = 0
pFD\dwVisibleMask = 0
pFD\dwDamageMask = 0

pFormat = ChoosePixelFormat_(hDC, @pFD)
If pFormat = 0
  MessageRequester("Error", "Could not choose pixel format.", 0)
  ReleaseDC_(hWnd, hDC)
  End
EndIf

result = SetPixelFormat_(hDC, pFormat, @pFD)
If result = 0
  MessageRequester("Error", "Could not set pixel format.", 0)
  ReleaseDC_(hWnd, hDC)
  End
EndIf

hRC = wglCreateContext_(hDC)
If hRC = 0
  MessageRequester("Error", "Could not create rendering context.", 0)
  ReleaseDC_(hWnd, hDC)
  End 
EndIf

result = wglMakeCurrent_(hDC, hRC)
If result = 0
  MessageRequester("Error", "Could not activate rendering context.", 0)
  ReleaseDC_(hWnd, hDC)
  wglDeleteContext_(hRC)
  End
EndIf

glShadeModel_(#GL_SMOOTH)
glClearColor_(0.0, 0.0, 0.0, 0.5)
glClearDepth__(1.0)
glEnable_(#GL_DEPTH_TEST)
glDepthFunc_(#GL_LEQUAL)
glHint_(#GL_PERSPECTIVE_CORRECTION_HINT, #GL_NICEST)

UseWindow(0)
glViewport_(0, 0, WindowWidth(), WindowHeight())
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective__(45.0, WindowWidth() / WindowHeight(), 0.1, 100.0);
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()

glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_()
SwapBuffers_(hDC)
;wglSwapLayerBuffers_(hDC, #WGL_SWAP_MAIN_PLANE)

Repeat
  EventID = WaitWindowEvent()
    Select EventID
      Case #PB_Event_Repaint
         glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
         glLoadIdentity_()
         SwapBuffers_(hDC)
         ;wglSwapLayerBuffers_(hDC, #WGL_SWAP_MAIN_PLANE)
      Case #PB_Event_CloseWindow
        quit = 1
      Case #WM_SIZE
        UseWindow(0)
        glViewport_(0, 0, WindowWidth(), WindowHeight())
        glMatrixMode_(#GL_PROJECTION)
        glLoadIdentity_()
        gluPerspective__(45.0, WindowWidth() / WindowHeight(), 0.1, 100.0);
        glMatrixMode_(#GL_MODELVIEW)
        glLoadIdentity_()
    EndSelect
Until quit = 1

ReleaseDC_(hWnd, hDC)
wglDeleteContext_(hRC)
DestroyWindow_(hWnd)

End

Re: Wierd OpenGL Problems

Posted: Tue Jun 15, 2004 9:05 am
by traumatic
Raine3D wrote:Is it my code, or a bug? (Im using a userlib that allows me to pass floats into glDepth and glPerspective, forgot the name)
No, no bugs in the lib! :wink:

Seriously, I ran your code and it worked fine for me...

Posted: Tue Jun 15, 2004 7:21 pm
by Raine3D
Thats odd, it must be my computer then.. Well at least I know im programming correctly :wink:

Posted: Wed Jun 16, 2004 2:52 pm
by Raine3D
I found the problem:

Code: Select all

If (hWnd = OpenWindow(0, 0, 0, 320, 240, #WINDOWSETTINGS, "OpenGL Test")) = 0
  MessageRequester("Error", "Could not create window.", 0)
  End
EndIf 
When I changed it to this, it all worked fine:

Code: Select all

hWnd = OpenWindow(0, 0, 0, 320, 240, #WINDOWSETTINGS, "OpenGL Test")
If hWnd = 0
  MessageRequester("Error", "Could not create window.", 0)
  End
EndIf