Thread: glFrustum

  1. #1
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96

    glFrustum

    Hey iv'e started learning OpenGL (again) and I ran into this...
    when i use glFrustum() the output I get is all distored but if i use gluPerspective() the program works perfect, it's my understanding is that both the functions do the same thing, but with differernt arguments, so why does one work and the other not??
    The program changes the viewport so it can be rotated around a wirecube always

    heres the code:
    Code:
    #include <GL/glut.h>
    #include <iostream>
    using namespace std;
    
    float a,b;
    
    
    /********** DISPLAY FUNCTION **********/
    void display(void)
    {
    glPushMatrix();
    
    gluLookAt(b, 0.0, a , 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    
    glutWireCube(25.f);// make a cube the size one quater of the viewing volume
    
    glutSwapBuffers();     //for double duffer
    
    glPopMatrix();
    }
    
    
    /********** CHANGESIZE FUNCTION **********/
    void ChangeSize(GLsizei w, GLsizei h) //changesize prototype
    {
    glViewport(0,0,w,h);
    
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    //glFrustum(-100.0 , 100.0 , -100.0, 100.0, 1.0, 100.0);// this defines the viewing area\volume
    gluPerspective(90.0, 1.0 ,1.0,100.0);
    
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();    
    
    	glutPostRedisplay();
    }
    
    
    
    /********** KEYS FUNCTION **********/
    
    
    void Keys(int key, int x, int y)
    	{
    	if(key == GLUT_KEY_UP)
    {a++;
    cout << "Z = " << a <<endl;
    }
    
    	if(key == GLUT_KEY_DOWN)
    {a--;
    cout << "Z = " << a <<endl;
    }
    
    	if(key == GLUT_KEY_LEFT)
    {b++;
    cout << "X = " << b <<endl;
    }
    
    	if(key == GLUT_KEY_RIGHT)
    {b--;
    cout << "X = " << b <<endl;
    }
    
    	glutPostRedisplay();	// Refresh the Window... APPARENTLLY
    	}
    
    
    /********** MAIN FUNCTION **********/
    
    int main(int argc, char *argv[])
    {
        a = -30.0;
        b = 0.0;
        
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); // SETS DISPLAY MODE
        glutInitWindowSize(300,300);
        glutCreateWindow("Mattys Test"); //Creates a window
        
        glutDisplayFunc(display);        //call back functions
        glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(Keys);    //KEYBOARD FUNCTIONS
    
    
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f); //CLEAR COLOUR ONLY NEEDS TO BE SET ONCE!
    
        glutMainLoop();
        
    return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Probably because if you do the math, the glFrustum call you have is equivalent to
    Code:
    gluPerspective(178.854, 1.0, 1.0, 100.0);
    If you really want a 90 degree field of view angle, then your near plane would have to start at 100. (Or alternatively, your other directions go from -1 to 1.)

  3. #3
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96
    whats the relationship between the two i'm not quite sure how to calculate one into the other(well im guessing near and far is the same but the fovy and aspect confuses me a little)

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Matty_Alan View Post
    whats the relationship between the two i'm not quite sure how to calculate one into the other(well im guessing near and far is the same but the fovy and aspect confuses me a little)
    Check here, it's explained a number of different ways.
    glFrustum and glPerspective difference? - GameDev.Net Discussion Forums

Popular pages Recent additions subscribe to a feed