OpenGL Help??
BlitzMax Forums/BlitzMax Programming/OpenGL Help??
| ||
Ok, so I have the following code: Import brl.BlitzGL Import pub.OpenGL bglCreateContext 800,600,16,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER glShadeModel GL_SMOOTH glClearColor 0.0,0.0,0.0,0.0 val = 0 While Not KeyDown(KEY_ESCAPE) glMatrixMode GL_PROJECTION glLoadIdentity gluPerspective 45,800/600,0.1,100 glMatrixMode GL_MODELVIEW glLoadIdentity glClearDepth 0.0 glViewPort 0,0,800,600 glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glRotatef val,0,0,0 val = val + 1 glBegin GL_QUADS glVertex2f -1,1 glVertex2f 1,1 glVertex2f 1,-1 glVertex2f -1,-1 glEnd FlushMem bglSwapBuffers Wend End But it seems to produce a blank window. Further, when I previously tried it without the rotation, it did produce a quad but it was rectangular rather than square, suggesting that the aspect ratio was wrong. I've tried re-arranging all of the initialisation stuff several times and copying the order out of the OpenGL example included with blitzMax but it still refuses to show anything. Can anyone give me a clue what's going on? |
| ||
Rotate is axis based, i.e glRotateF Angle,PitchBit,YawBit,RollBit. glRotateF Roll,0,0,1 glRotateF Yaw,0,1,0 glRotateF Pitch,1,0,0, also for 2d stuff, you're better off using orothogonal projection, glViewport 0, 0, dWidth,dHeight glMatrixMode gl_projection glLoadIdentity() gluortho2d(0.0, dWidth, 0.0, dHeight ) glMatrixMode gl_modelview glLoadIdentity then you can specify verts in pixel space. |
| ||
Well, I tried changing those but still got nothing, so I pulled the rotate altogether, but it still just comes up blank: Import brl.BlitzGL Import pub.OpenGL bglCreateContext 800,600,16,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER glShadeModel GL_SMOOTH glClearColor 0.0,0.0,0.0,0.0 val = 0 While Not KeyDown(KEY_ESCAPE) glViewport 0, 0, 800,600 glMatrixMode gl_projection glLoadIdentity gluortho2d 0.0, 800, 0.0, 600 glMatrixMode gl_modelview glLoadIdentity glClearDepth 0.0 glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 'glRotatef val,1,0,0 glColor3f 1,1,1 glBegin GL_QUADS glVertex2f -1,100 glVertex2f 100,100 glVertex2f 100,-1 glVertex2f -1,-1 glEnd FlushMem bglSwapBuffers Wend End |
| ||
Copy/paste your code don't work. Try this : Import brl.BlitzGL Import pub.OpenGL val:Float=0.0 bglCreateContext (800, 600, 32, 0, BGL_BACKBUFFER | BGL_DEPTHBUFFER) bglSetSwapInterval(1) InitGl() While Not KeyHit( KEY_ESCAPE ) ' Clear The Screen And The Depth Buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ' Reset The Current Modelview Matrix glLoadIdentity() glColor3f 1.0,1.0,1.0 glRotatef val,1,0,0 glBegin GL_QUADS glVertex2f -1.0,100.0 glVertex2f 100.0,100.0 glVertex2f 100.0,-1.0 glVertex2f -1.0,-1.0 glEnd val:+0.1 FlushMem bglSwapBuffers Wend End Function InitGl() ' Enable Smooth Shading glShadeModel(GL_SMOOTH) ' Black Background glClearColor(0.0, 0.0, 0.0, 0.5) ' Depth Buffer Setup glClearDepth(1.0) ' Enables Depth Testing glEnable(GL_DEPTH_TEST) ' The Type Of Depth Testing To Do glDepthFunc(GL_LEQUAL) ' Really Nice Perspective Calculations glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) ' Set viewport glViewport(0,0,800,600) ' Select The Projection Matrix glMatrixMode(GL_PROJECTION) ' Reset The Projection Matrix glLoadIdentity() gluortho2d(0.0, 800, 0.0, 600) ' Select The Modelview Matrix glMatrixMode(GL_MODELVIEW) ' Reset The Modelview Matrix glLoadIdentity() End Function |
| ||
hyphz - Of all of these lines in your code:glViewport 0, 0, 800,600 glMatrixMode gl_projection glLoadIdentity gluortho2d 0.0, 800, 0.0, 600 glMatrixMode gl_modelview glLoadIdentity glClearDepth 0.0 glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) Only the second glLoadIdentity should be in the main loop. |