为什么 gluLookAt 不起作用?
它对场景没有任何影响,就好像它甚至没有被调用一样。
是不是因为我正在使用glMatrixMode(GL_MODELVIEW);
,如果我不包含它,我在屏幕上什么也得不到。
我正在使用 GLFW、GLEW 和 GLM。
// game.cpp:
Car* car;
void Game::init()
{
// LOADING SHADERS:
loadShaders();
// CREATING ENTITIES:
car = new Car();
//cube->position.x = -0;
car->position.z = -2;
entities.push_back(car);
// INITIAL GL PARAMETERS:
glEnable(GL_CULL_FACE); // BACK FACE CULLING
glEnable(GL_DEPTH_TEST); // DRAW NON-OBSCURED
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // FILL POLYGON MODE
glClearColor(0.3f, 0.5f, 0.9f, 0.0f); // BACKGROUND COLOR
glMatrixMode(GL_PROJECTION);
gluPerspective(CAMERA_FOVY, (GLdouble)WINDOW_WIDTH / (GLdouble)WINDOW_HEIGHT, CAMERA_ZNEAR, CAMERA_ZFAR);
}
void Game::update()
{
for (int i = 0; i != entities.size(); ++i)
{
entities[i]->update();
}
}
void Game::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 0, car->position.x, car->position.y, car->position.z, 0, -1, 0);
for (int i = 0; i != entities.size(); ++i)
{
glLoadIdentity();
glTranslatef(entities[i]->position.x, entities[i]->position.y, entities[i]->position.z);
glRotatef(entities[i]->rotation.x, 1.0f, 0.0f, 0.0f);
glRotatef(entities[i]->rotation.y, 0.0f, 1.0f, 0.0f);
glRotatef(entities[i]->rotation.z, 0.0f, 0.0f, 1.0f);
entities[i]->render();
}
}