nehe tutorials

BlitzMax Forums/OpenGL Module/nehe tutorials

Gavin Beard(Posted 2006) [#1]
hey all,

i'm working thru nehe tutorials and am at basic level and alreay having issues :D

i've written this code:

SetGraphicsDriver GLGraphicsDriver()
GLGraphics 640,480

Repeat

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(-1.5,0.0,-6.0);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f(-1.0,-1.0, 0.0);
glVertex3f( 1.0,-1.0, 0.0);
glEnd();


Flip()
Until KeyDown(key_escape)

but as far as i can see is valid, and should draw a white triangle as per the nehe tut. however i get a black scr. if i take out the gltranslatef() it draws a triangle that fills the who;e screen but thats not the desired effect, it should be smaller

any ideas?


ImaginaryHuman(Posted 2006) [#2]
When you use GLGraphics() it does not set up any of the OpenGL state. You have to set up your own viewport, initialize your matrices, etc. If you want things to be set up already use Graphics() with the GLGraphicsDriver(). You can't really know what is going to be drawn if you don't specify the viewport at least. My guess is the viewport defaults to a 1x1 pixel view, so you're seeing the middle pixel of the triangle across the whole screen, or maybe that's totally way off the mark.

see:

glViewport()
glOrtho()


Gavin Beard(Posted 2006) [#3]
ok

i looked at glviewport and changed code to :

SetGraphicsDriver GLGraphicsDriver()
GLGraphics 640,480

Repeat
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(-1.5,0.0,-6.0);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f(-1.0,-1.0, 0.0);
glVertex3f( 1.0,-1.0, 0.0);
glEnd();


Flip()
Until KeyDown(key_escape)


still smae problem :S


Drago(Posted 2006) [#4]
You arn't setting Opengl up properly.
Refer to the following code.
SetGraphicsDriver GLGraphicsDriver()
GLGraphics 640,480
' Moved these up here. 
' Only needs to be done once :)
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

' Ok, you also need to setupthe Screens perspective.
' ie the Field of view, and the Aspect ratio.
' gluPerspective(FOV,Ratio,NearPlane,farPlane);
gluPerspective(45.0,640/480,0.1,100.0);

' you also need to set the current matrix to the modelviewmatrix.
' this matrix is what lets you move the current world offset from 0,0,0
glMatrixMode(GL_MODELVIEW);					' Select The Modelview Matrix
glLoadIdentity();						' Reset The Modelview Matrix

Repeat

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(-1.5,0.0,-6.0);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f(-1.0,-1.0, 0.0);
glVertex3f( 1.0,-1.0, 0.0);
glEnd();


Flip()
Until KeyDown(key_escape)


Any questions ask.

Laters, Drago