OpenGL で球をレンダリングしようとしています。残念ながら、画面には常に背景しか表示されません。カメラの向きを変えてみましたが、うまくいきませんでした (間違っているかもしれませんが)。任意の洞察をいただければ幸いです。
画面を更新するために OpenGL が呼び出す関数は次のとおりです。
//The draw function - I have confirmed that this is called periodically.
void draw()
{
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, (globals.wireframe == true) ? GL_LINE : GL_FILL);
glViewport(0, 0, globals.window_size.x, globals.window_size.y);
mat4 prj = perspective(globals.fov, float(globals.window_size.x) / float(globals.window_size.y), globals.hither, globals.yon);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(value_ptr(prj));
glMatrixMode(GL_MODELVIEW);
mat4 context = mat4(1.0f);
globals.ship.draw(context); //the ship only draws a sphere for now
mat4 mv = lookAt(vec3(0.0f, 0.0f, -5.5f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
glLoadMatrixf(value_ptr(mv));
glutSwapBuffers();
}
そして船の定義:
GLuint Ship::sphere_handle; //static
bool Ship::is_initialized; //static
mat4 Ship::draw(mat4 context) const {
glLoadMatrixf(value_ptr(context));
glCallList(sphere_handle);
return context;
}
//called when program starts, after window created
bool Ship::initialize() {
if (sphere_handle == BAD_GL_VALUE)
{
GLUquadric *q = gluNewQuadric();
if (q != NULL)
{
if ((sphere_handle = glGenLists(1)) == 0)
{
cout << "Model::Initialize() - Failed to GenLists()" << endl;
return false;
}
glNewList(sphere_handle, GL_COMPILE);
gluSphere(q, 1.0, 10, 10);
glEndList();
gluDeleteQuadric(q);
is_initialized = true;
}
else
{
return false;
}
}
return true;
}