Basically I revised my experiment programs to use a class, and rather than use a specific system api I’m using GLUT. The thing is when I converted all the rendering and such to an object I must have missed something and now my scene doesn’t show anything. It captures the keyboard properly so I know it’s in the proper loop, but other than that it’s just a black screen. Here’s my main source, and the class header and source
//main.cpp
#define GLUT_NO_LIB_PRAGMA
#define GLUT_NO_WARNING_DISABLE
#include <GL/glut.h>
#include "cgfxopengl.h"
//=========================================================================
int width = 800, height = 600;
CGfxOpenGL* glRender;
//=========================================================================
void renderScene(void)
{
glRender->prepare();
glRender->render();
glutSwapBuffers();
}
void idle(void)
{
glutPostRedisplay();
}
void preserveRatio(int width, int height)
{
glRender->setupProjection(width, height);
}
void specialKeys(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_F1:
glRender->toggleFlashLight();
break;
default:
break;
}
}
void normalKeys(unsigned char key, int x, int y)
{
if (key == 27)
glutLeaveMainLoop();
}
//main
int main(int argc, char **argv)
{
//Initializes and Creates Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(0,0);
glutInitWindowSize(width , height);
glutCreateWindow("My GLUT Window");
//displayfunctions
glutDisplayFunc(renderScene);
glutIdleFunc(idle);
glutReshapeFunc(preserveRatio);
//keyboard function
glutSpecialFunc(specialKeys);
glutKeyboardFunc(normalKeys);
//rendering object
glRender = new CGfxOpenGL;
glRender->intialize();
glutMainLoop();
return 0;
}
And here’s the definitions for the class that I’m using in there
#include "cgfxopengl.h"
#include "shapes.h"
//=========================================================================
GLfloat lightAngle;
GLfloat flashLightPos[] = {0.0, 0.0, 0.0, 1.0};
GLfloat flashLightDir[] = {0.0, 0.0, -1.0};
GLfloat flashLightCol[] = {0.2, 0.2, 0.2, 1.0};
GLfloat bigLightPos[] = {0.0, 1.0, 1.0, 0.0};
GLfloat bigLightCol[] = {0.3, 0.3, 0.3, 1.0};
//albient color for the scene, bluish Green
GLfloat globalAmbience[] = {0.0, 0.2, 0.3, 1.0};
//=========================================================================
CGfxOpenGL::CGfxOpenGL()
{
flashLightOn = GL_TRUE;
}
CGfxOpenGL::~CGfxOpenGL()
{
}
bool CGfxOpenGL::intialize()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbience);
//set up the flashLight
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, flashLightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, flashLightCol);
glLightfv(GL_LIGHT0, GL_DIFFUSE, flashLightCol);
glLightfv(GL_LIGHT0, GL_SPECULAR, flashLightCol);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, flashLightDir);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 15.0);
glEnable(GL_COLOR_MATERIAL);
//set up the large light
return true;
}
void CGfxOpenGL::setupProjection(int width, int height)
{
//prevent division by 0
if(height = 0)
height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)width/(GLfloat)height, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
windowWidth = width;
windowHeight = height;
}
void CGfxOpenGL::render()
{
glPushMatrix();
GLfloat coneColor[] = {0.6, 0.7, 1.0, 1.0};
GLfloat coneSpecular[] = { 1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, coneColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, coneSpecular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 15.0);
glTranslatef(0, 0, 10);
DrawCone(2, 2, 15);
glPopMatrix();
}
bool CGfxOpenGL::shutDown()
{
return true;
}
void CGfxOpenGL::prepare()
{
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if(flashLightOn == true)
glEnable(GL_LIGHT0);
else
glDisable(GL_LIGHT0);
}