Hi y'all
I have some old DX code I need to convert to OpenGL. Unfortunately I'm not well aqauinted with OpenGL so I'm reading up on it (Red book, OpenGL Super Bible, and Astle's Beginning OpenGL Game Programming (we must supports the Rhino right [smile])).
Anyway, the following code should display a trianlge (it's adapted from Astle's book), but the triangle doesn't show.
The window is setup proberly because I can change the background colour just fine. Maybe it has something to do with the transformations?
Anyway this is the rendering code:
void opengl_render::render() {
// Clear the screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Move back 5 units and rotate about all 3 axes
glTranslatef(0.0, 0.0, -5.0f);
glRotatef(angle_, 1.0f, 0.0f, 0.0f);
glRotatef(angle_, 0.0f, 1.0f, 0.0f);
glRotatef(angle_, 0.0f, 0.0f, 1.0f);
// Lime greenish color
glColor3f(0.7f, 1.0f, 0.3f);
// Draw the triangle such that the rotation point is in the center
glBegin(GL_TRIANGLES);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
}
And this sets up the perspective projection (called in response to any WM_SIZE messages):
void opengl_render::setup_projection(int width, int height) {
// Avoid a divide by zero
if(height = 0) {
height = 1;
}
// Reset the viewport to new dimensions
glViewport(0, 0, width, height);
// Set projection matrix current matrix
glMatrixMode(GL_PROJECTION);
// Reset projection matrix
glLoadIdentity();
// Calculate aspect ratio of window
gluPerspective(52.0f, (GLfloat)width/(GLfloat) height, 1.0f, 1000.0f);
// Set modelview matrix
glMatrixMode(GL_MODELVIEW);
// Reset modelview matrix
glLoadIdentity();
window_width_ = width;
window_height_ = height;
}
So, what did I do wrong? I only see a black window (or whatever color I use for the glClearColor (this call is in another method not shown above)).