PDA

View Full Version : depth & gltranslate & wah?!



baconbeastnz
05-31-2008, 10:26 PM
Hi there, basically im trying to understood how this ends up drawing a trial which is approx: 200px wide. When the floating point numbers specified are only 1.

I can change the size of the triangle by altering the 3rd arg in glTranslatef, but I do no understand how it works, nor how the numbering works. E.G -6 = 200px, but -2 = approx 800px

so confused :p

glEnable(GL_DEPTH_TEST); Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glEnable ( GL_COLOR_MATERIAL glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glTranslatef(-1.5f,0.0f,-6.0f);

glBegin(GL_TRIANGLES); // Drawing Using Triangles


void reshape ( int w, int h ) // Create The Reshape Function (the viewport)
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix
glLoadIdentity ( ); // Reset The Projection Matrix
if ( h==0 ) // Calculate The Aspect Ratio Of The Window
gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
else
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
glLoadIdentity ( ); // Reset The Model View Matrix
}
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();

ZbuffeR
06-01-2008, 03:28 AM
You have a perspective transformation.
The third arg is the Z axis, the one that goes away from the camera through the screen. So you see the perspective distance shortening.

If you want to merely scale the triangle, use glScale on X and Y instead.