I have a camera class and a Vector3 class(obvious what they mean), the Vector3 class constructor takes three float arguments each has a default value of zero, so calling Vector3()
is equivalent to Vector3(0,0,0)
.
The camera class constructor also takes three arguments each is a Vector3, the positing , the viewpoint and the up vector.
here's my code, going to explain problem later :
#include "camera.h"
Vector3 StartPoint(1000,1000,1000);
Camera camera(Vector3(1000,1000,1100),Vector3(StartPoint),Vector3(0,1));
void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
camera.LookAt();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
camera.LookAt();
//draw some things
glutSwapBuffers();
}
void idle(void)
{
glutPostRedisplay();
}
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(300,200);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Tischfussball");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMainLoop();
return EXIT_SUCCESS;
}
I have a camera class which works great with the code above, but when removing glLoadIdentity
line from display function the screen appears just blank !
I searched and found something about idle function so I moved glLoadIdentity with camera.LookAt to idle function and didn't work.
I don't want to put code that I don't understand and I want to remove that line because I don't see any necessity in my logic, I mean glLoadIdentity just restores the matrix to the identity matrix(depending on last MatrixMode, it restores the MODELVIEW matrix here), it's not necessary at all to call it at each display(it's waste of performance I think).
I'm really confused, how does this work ?!!
EDIT
camera.LookAt() is equivalent to gluLookAt(camera.position.x,camera.position.y,camera.position.z,camera.view.x,camera.view.y,camera.view.z,camera.up.x,camera.up.y,camera.up.z)
there is no call to glTranslate* or glRotate* in the //draw some things
part.
And the only calls to change camera variables are called on key event, I see the blank screen just after the window appears(no key pressed yet), I press some keys with no use.