Simplest OpenGL program ever -- not working...
BlitzMax Forums/OpenGL Module/Simplest OpenGL program ever -- not working...
| ||
I'm taking this code from GameDev.net so I don't understand why it's not working. What should be happening is that OpenGL is initialized for 2D (orthographical projection) and a simple line is drawn. However, in this case the screen is being cleared properly (according to glClearColor) but my line is not being drawn. Can somebody please, please help me? Here is the code: GLGraphics 320, 200 Enable2D() glClearColor(0.0, 0.0, 0.0, 0.0) While Not KeyHit(KEY_ESCAPE) glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glBegin(GL_LINE); glVertex2i(0, 0) ; glVertex2i(1, 1); glEnd(); Flip() Wend Function Enable2D() Local vPort : Int[4] glGetIntegerv(GL_VIEWPORT, vPort); glMatrixMode(GL_PROJECTION) ; glPushMatrix() ; glLoadIdentity() ; glOrtho(0, vPort[2], 0, vPort[3], -1, 1); glMatrixMode(GL_MODELVIEW) ; glPushMatrix() ; glLoadIdentity(); End Function Function Disable2D() glMatrixMode(GL_PROJECTION) ; glPopMatrix() ; glMatrixMode(GL_MODELVIEW) ; glPopMatrix(); End Function |
| ||
You're drawing a line that is 1 pixel across and 1 pixel up. Also, GL_LINE should be GL_LINES. Change: glBegin(GL_LINE); glVertex2i(0, 0) ; glVertex2i(1, 1); glEnd(); to glBegin(GL_LINES); glVertex2i(0, 0) ; glVertex2i(100, 100); glEnd(); and it should work. |
| ||
Oh, sorry... I was using (10, 10) to (100, 100) but then I thought maybe OpenGL was using 0..1 screen coordinates. Anyways, I think the problem was that I needed to use GL_LINES instead of GL_LINE. Crazy typos... Thanks for the help! |