Super-simple OpenGL setup...no triangle visible?
BlitzMax Forums/OpenGL Module/Super-simple OpenGL setup...no triangle visible?
| ||
| I can't figure out why there is no triangle visible here. I believe I did everything I need to set it up properly. I need to set up the whole OpenGL environment myself, so I can access all the features I want. Any help pointing out an error in this code would be appreciated: This BlitzPlus code works: This BlitzMax code does not work: |
| ||
| If I use a PollEvent() instead of a WaitEvent() in the BlitzMax source the triangle shows up, though it is badly distorted. I don't think the pixel format is getting set up correctly. |
| ||
| I replaced the bank with a PIXELFORMATDESCRIPTOR structure. The screen still flashes badly, looking like the pixelformat is not getting set correctly. |
| ||
Okay, I had to get rid of the OR statements in the dwflags parameter. Here it is, a super-simple OpenGL setup on a BlitzMax window. That's pretty nice that it is so simple, even when you are creating a context from scratch:'Create Window
win:tgadget=CreateWindow("OpenGL Window",200,200,640,480,Null,3)
'Setup pixel format
hwnd=QueryGadget(win,QUERY_HWND_CLIENT)
hdc=GetDC(hwnd)
Local lpPixelFormat:PIXELFORMATDESCRIPTOR
lpPixelFormat.nSize=40
lpPixelFormat.nVersion=1
lpPixelFormat.dwFlags=PFD_SUPPORT_OPENGL+PFD_DOUBLEBUFFER+PFD_DRAW_TO_WINDOW
lpPixelFormat.iPixelType=PFD_TYPE_RGBA
lpPixelFormat.cColorBits=16
lpPixelFormat.cRedBits=8
lpPixelFormat.cGreenBits=8
lpPixelFormat.cBlueBits=8
lpPixelFormat.cAccumBits=16
lpPixelFormat.cDepthBits=16
lpPixelFormat.cStencilBits=8
lpPixelFormat.dwLayerMask=PFD_MAIN_PLANE
lPixelFormat=ChoosePixelFormat(hDC,lpPixelFormat)
If Not lPixelFormat RuntimeError "ChoosePixelFormat() failed"
result=SetPixelFormat(hDC,lPixelFormat,lpPixelFormat)
If Not result RuntimeError "SetPixelFormat() failed"
lpPixelFormat=Null
'Create OpenGL Context
hrc=wglCreateContext(hdc)
If Not hrc Notify "Failed to create context."
wglMakeCurrent hdc,hrc
'Program Loop
Repeat
'Setup Viewport
w=ClientWidth(win)
h=ClientHeight(win)
glViewport 0.0,0.0,w,h
glClearColor 0.0,0.0,1.0,0.0
glClear GL_DEPTH_BUFFER_BIT+GL_COLOR_BUFFER_BIT
glMatrixMode GL_PROJECTION
glLoadIdentity()
glPushMatrix()
gluPerspective 45.0,Float(w)/Float(h),1.0,100.0
'Draw Triangle
glBegin GL_TRIANGLES
glVertex3f 0.0,0.0,-10.0
glVertex3f 1.0,1.0,-10.0
glVertex3f 1.0,0.0,-10.0
glEnd
glpopmatrix()
'Flip buffer
SwapBuffers hdc
'Check for WindowClose Event
If WaitEvent()=EVENT_WINDOWCLOSE End
Forever |
| ||
In BMax 'AND' and 'OR' are logical operators, their binary counterparts being '&' and '|'...lpPixelFormat.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW ...ETC... |