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