Hi… please help me, I’m trying to make a first person shooter. I’m having problems with the camera I think, it compiles and runs but the screen is completely black. I already moved many things but the result is the same. What is wrong with my camera?
void camera (void) {
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glRotatef(xrot,1.0,0.0,0.0); //rotate our camera on the (left and right) x-axis
glRotatef(yrot,0.0,1.0,0.0); //rotate our camera on the (up and down) y-axis
glTranslated(-xpos,-ypos,-zpos); //translate the screen to the position of our camera
}
void renderScene(void)
{
float xDistance = playerX-enemyX;
float yDistance = playerY-enemyY;
float zDistance = playerZ-enemyZ;
float hypotenuse = sqrt((xDistance * xDistance) + (yDistance * yDistance));
float timeFactor = 3.0;
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
camera();
// Posicionar la camara
gluLookAt(xpos, ypos, zpos,
xpos+lx, ypos, zpos+lz,
0.0f, y, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
enable();
angle++; //increase the angle
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Plano
glMatrixMode(GL_MODELVIEW);
glBindTexture(GL_TEXTURE_2D,1);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(100, 0, 100);
glTexCoord2f(1.0,0);
glVertex3f(-100, 0, 100);
glTexCoord2f(1.0,1.0);
glVertex3f( -100, 0, -100);
glTexCoord2f(1.0,0);
glVertex3f( 100, 0, -100);
glEnd();
glDisable(GL_TEXTURE_2D);
…
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("FPS");
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
glutKeyboardFunc (keyboard);
glutTimerFunc(33, myTimer, 0);
Init();
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 1;
}
These are the zones where the camera takes place (I think).