Yes, I know, WHY?Pornomag wrote:OK I honestly just tried to get your code working (which I did), it does work with 0 degrees field of view, it just doesn't shrink the triangle for some reason
Perspective
Moderator: Coders of Rage
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Perspective
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Perspective
Watch your attitude, kid.
This code works. Your problem is that you were pushing the model/view matrix stack down and not loading a matrix into it. When you call glTranslate, there is garbage there and glTranslate implicitly invokes glMultMatrix. This multiplies the translation matrix with the garbage on the top of the stack. You need to load something into the top of the stack after you push. You need to focus much more heavily on transformations and basic data structures. Absolutely none of this code should work with a 0 degree FOV (All geometry will be clipped).
Code: Select all
void initialize_it(void) //sets up graphic stuff.
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,200);
glutInitWindowPosition(100,50);
glutCreateWindow("Moving Square");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, ScreenWidthInPixels / ScreenHeightInPixels, 0.1f, 100.0f);
// glEnable(GL_DEPTH_TEST); // Don't need depth testing
// glDepthFunc(GL_LEQUAL);
// Perspective is a "camera" idea, since you have a global camera in this demo we can just set the perspective once //
// There is no "view" transform in your case. However, you have a model transform. It does not make sense to //
// apply model transforms in initialization routines, these are applied per frame //
// glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();
}
Code: Select all
void rect_display(void)
{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
// Make the model/view matrix the current one. All matrix ops happen to the top matrix on the model/view matrix stack //
// Load an identity matrix into the top matrix of this stack //
// glTranslatef multiplies the current matrix (identity) with a translation matrix //
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0,translationAmount);
translationAmount-=0.0001;
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 1.0); //front.
glVertex3f(0.3, 0.8, 0.2);
glVertex3f(0.3, 0.2, 0.2);
glVertex3f(0.8, 0.8, 0.2);
glEnd();
// glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
This code works. Your problem is that you were pushing the model/view matrix stack down and not loading a matrix into it. When you call glTranslate, there is garbage there and glTranslate implicitly invokes glMultMatrix. This multiplies the translation matrix with the garbage on the top of the stack. You need to load something into the top of the stack after you push. You need to focus much more heavily on transformations and basic data structures. Absolutely none of this code should work with a 0 degree FOV (All geometry will be clipped).
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Perspective
Sorry.
OK, I'll look over some of that.
OK, I'll look over some of that.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Perspective
After taking a break I came back to it and now it seems to be working.
Thank you,
-Benjamin
Thank you,
-Benjamin