Jump to content

  • Log In with Google      Sign In   
  • Create Account


NeHe 33 coupled with gluOrtho2D


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Bakuto   Members   -  Reputation: 131

Like
0Likes
Like

Posted 03 March 2011 - 10:46 PM

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?

Sponsor:

#2 radioteeth   Prime Members   -  Reputation: 709

Like
0Likes
Like

Posted 03 March 2011 - 11:22 PM

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.

#3 V-man   Members   -  Reputation: 797

Like
0Likes
Like

Posted 04 March 2011 - 07:58 AM

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);




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS