I'm really new to OpenGL and can't seem to figure out how to put the "camera" inside the cube I've created so that I can move in an FPS-like style. I tried to use gluLookAt and gluPerspective but I'm clearly missing some steps. What should I do before gluLookAt? Here's the code written so far:
int rotate_Y; //used to rotate the cube about the Y-axis
int rotate_X; //used to rotate the cube about the X-axis
//the display function draws the scene and redraws it
void display(){
//clear the screen and the z-buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); //resets the transformations
glRotatef(rotate_X, 1.0, 0.0, 0.0);
glRotatef(rotate_Y, 0.0, 1.0, 0.0);
//Front Face of the cube - vertex definition
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
//Back Face of the cube - vertex definition
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glEnd();
//Right Face of the cube - vertex definition
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
//Left Face of the cube - vertex definition
glBegin(GL_POLYGON);
glColor3f(0.7, 0.7, 0.0);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
//Upper Face of the cube - vertex definition
glBegin(GL_POLYGON);
glColor3f(0.7, 0.7, 0.3);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glEnd();
//Bottom Face of the cube - vertex definition
glBegin(GL_POLYGON);
glColor3f(0.2, 0.2, 0.8);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
glFlush();
glutSwapBuffers(); //send image to the screen
}
int main(int argc, char*argv[]){
//initialize GLUT
glutInit(&argc, argv);
//request double buffering, RGB colors window and a z-buffer
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
//create a window
glutInitWindowSize(600, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Space");
//enable depth
glEnable(GL_DEPTH_TEST);
//callback functions
glutDisplayFunc(display); //display - redraws the scene
glutSpecialFunc(specialKeys); //special - allows interaction with specialkeys
//pass control to GLUT for events
glutMainLoop();
return 0; //this line is never reached
}
Feel free to ask more about what I'm trying to achieve if I wasn't clear enough. Thanks for your help.