GLuint Hexagon::compile() {
if(hex!=0) {
glDeleteLists(hex,2);
}
hex=glGenLists(2);
if(hex!=0) {
glNewList(hex,GL_COMPILE);
glColor3f(red,green,blue);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(-0.25f,-0.433f,0.0f);
glVertex3f( 0.25f,-0.433f,0.0f);
glVertex3f( 0.25f,-0.433f,0.0f);
glVertex3f( 0.5f , 0.0f ,0.0f);
glVertex3f( 0.5f , 0.0f ,0.0f);
glVertex3f( 0.25f, 0.433f,0.0f);
glVertex3f( 0.25f, 0.433f,0.0f);
glVertex3f(-0.25f, 0.433f,0.0f);
glVertex3f(-0.25f, 0.433f,0.0f);
glVertex3f(-0.5f , 0.0f ,0.0f);
glVertex3f(-0.5f , 0.0f ,0.0f);
glVertex3f(-0.25f,-0.433f,0.0f);
glEnd();
glEndList();
glNewList(hex+1,GL_COMPILE);
glBegin(GL_LINE_LOOP);
glVertex3f(-0.25f,-0.433f,0.0f);
glVertex3f( 0.25f,-0.433f,0.0f);
glVertex3f( 0.5f , 0.0f ,0.0f);
glVertex3f( 0.25f, 0.433f,0.0f);
glVertex3f(-0.25f, 0.433f,0.0f);
glVertex3f(-0.5f , 0.0f ,0.0f);
glEnd();
glEndList();
}
return hex;
}
GLuint Board::compile() {
int i,j;
GLuint tempList;
if(board!=0) {
glDeleteLists(board,1);
}
board=glGenLists(1);
if(board!=0) {
glNewList(board,GL_COMPILE);
glTranslatef(0.0f,-0.433f,0.0f);
for(i=0;i<width;i++) {
if(i%2==1) {
glTranslatef(0.0f,-0.433f,0.0f);
}
else {
glTranslatef(0.0f,0.433f,0.0f);
}
for(j=0;j<height;j++) {
tempList=hex[i][j].compile();
glCallList(tempList);
glTranslatef(0.0f,-0.866f,0.0f);
}
glTranslatef(0.75f,(0.866f*(float)height),0.0f);
}
glEndList();
}
return board;
}
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
board.init(3,3);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// *** \/ \/ if I put it here it does not work ***
boardList=board.compile();
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
// *** \/ \/ if I put it here it does not work ***
//boardList=board.compile();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// *** \/ \/ if I put it here it works ***
//boardList=board.compile();
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-5.0f); // Move Left 1.5 Units And Into The Screen 6.0
glCallList(boardList);
return TRUE; // Keep Going
}
Make it work. Make it fast. "I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book