The frame only draws once and if i remove the comment the glutPostRedisplay the screen is rendered white.
#include <gl\GLut.h>
int DLFloorBlock(0);
int DLCharacter(0);
int DLBackground(0);
GLfloat CharPos[3] = {3, 3, 0};
//GLfloat CharXPos();
//GLfloat CharYPos();
void DisplayList()
{
// Floor Block
DLFloorBlock = glGenLists(1);
glNewList(DLFloorBlock, GL_COMPILE);
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex2f( 0, 2);
glVertex2f( 0, 0);
glVertex2f( 3, 0);
glVertex2f( 3, 2);
glEnd();
glEndList();
// Character
DLCharacter = glGenLists(2);
glNewList(DLCharacter, GL_COMPILE);
glBegin(GL_QUADS);
glColor3i(1, 0, 1);
glVertex2f(4, 5);
glVertex2f(0, 5);
glVertex2f(0, 0);
glVertex2f(4, 0);
glEnd();
glEndList();
// Background
DLBackground = glGenLists(3);
glNewList(DLBackground, GL_COMPILE);
glBegin(GL_QUADS);
glColor3f(0, 1, 0);
glVertex3f(0, 0, -1);
glVertex3f(100, 0, -1);
glVertex3f(100, 100, -1);
glVertex3f(0, 100, -1);
glEnd();
glEndList();
}
void DrawCharacter()
{
glPushMatrix();
glTranslatef(3, 3, 0);
glCallList(DLCharacter);
glPopMatrix();
}
void DrawStage()
{
glPushMatrix();
// ***************************************START FLOOR***
glTranslatef(0, 1, 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
glTranslatef(3,0 , 0);
glCallList(DLFloorBlock);
//*********************************END FLOOR***
glPopMatrix();
}
void render()
{
glClearColor(1, 1, 1, 1);
glClearDepth(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glOrtho(0, 50, 0, 50, -1, 1);
glPushMatrix();
glCallList(DLBackground);
DrawStage();
DrawCharacter();
glPopMatrix();
glutSwapBuffers();
cout << "Frame done";
}
void Movement(int key, int x, int y)
{
if(key = GLUT_KEY_RIGHT)
CharPos[0] += 1;
if(key = GLUT_KEY_LEFT)
CharPos[0] -= 1;
cout << "Move done";
}
void LevelOneMain()
{
DisplayList();
glutDisplayFunc(render);
glutSpecialFunc(Movement);
glutPostRedisplay();
glutMainLoop();
}
// Create the window
void WindowInitGL(float Width, float Height, int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowPosition(0, 0);
glutInitWindowSize(Width, Height);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("Box Test");
}
void DrawFrame()
{
glClearColor(1,1,1,1);
glClearDepth(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glOrtho(0, 100, 0, 100, -1, 1);
glCallList(DLFloorBlock);
glFlush();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
WindowInitGL(800, 600, argc, argv);
LevelOneMain();
}