NeHe 33 coupled with gluOrtho2D

Started by
1 comment, last by V-man 13 years, 1 month ago
Greetings,

While working with NeHe #33 tutorial, I tried setting glMatrixMode(GL_PROJECTION) with some standard resolutions, (0, 800, 0, 600), etc.
However, when I invoke this call in the init portion of the code, the rotating sprites disappear. I have no idea how what the coordinates correspond to, when rendering the GL_QUADS.

Would anyone be able to show me how to set this up whilst having the glMatrixMode set to GL_PROJECTION?
Advertisement
I do something like this:


void SetPerspective(float fov, float aspect, float znear, float zfar)
{
float top, bottom, left, right;

top = znear * tan(fov / 2 * DEG2RAD);
bottom = -top;
right = aspect * top;
left = -right;

glFrustum(left, right, bottom, top, znear, zfar);
}


void Draw_Perspective()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
SetPerspective(camera_fov, (float)(app_rect.right - app_rect.left)/(app_rect.bottom - app_rect.top), 1, 99999);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(camera_angles.x, 1, 0, 0);
glRotatef(camera_angles.y, 0, 1, 0);
glRotatef(camera_angles.z, 0, 0, 1);
glTranslatef(-camera_origin.x, -camera_origin.y, -camera_origin.z);
}

void Draw_Ortho()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, VID_WIDTH, VID_HEIGHT, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}




The glOrtho takes arguments (left-side, right-side, bottom, top, near, far) it looks like you had it backwards, but that's ok, the OpenGL guys got it backwards IMHO ;)

Oh and to minimize linkage I use glOrtho and glFrustum instead of any glu stuff so that I'm not linking more than is really necessary, but it's really no biggie.
gluOrtho2D sets znear to -1 and zfar to 1.0 so perhaps your geometry got clipped.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement