Page 3 of 3

Re: Perspective

Posted: Wed Jan 18, 2012 1:31 pm
by Benjamin100
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
Yes, I know, WHY?

Re: Perspective

Posted: Wed Jan 18, 2012 2:02 pm
by qpHalcy0n
Watch your attitude, kid.

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

Re: Perspective

Posted: Thu Jan 19, 2012 1:08 am
by Benjamin100
Sorry.

OK, I'll look over some of that.

Re: Perspective

Posted: Sat Feb 11, 2012 5:34 pm
by Benjamin100
After taking a break I came back to it and now it seems to be working.

Thank you,

-Benjamin