Whenever I launch my (opengl) game.. the cpu usage goes up to 100%.
Is this normal?
my game doesnt even do anything.. it just draws a tile map on the screen and that's it.
Here is the code that's causing high cpu usage.
bool DR::DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-11.0f, 9.0f,-35.0f);
char tile(' ');
int xpos(0);
int ypos(0);
int counter(0);
do
{
tile = map.CurrentMap()[counter];
if ( xpos > 21 ) { //goes to next line
xpos=0;
ypos++;
}
switch(tile)
{
case '0':
glColor3f(0.6f,0.3f,0.1f); //wall=dark brown
break;
case '1':
glColor3f(0.8f,0.3f,0.1f); //path=light brown
break;
case '2':
glColor3f(0.0f,0.0f,1.0f); //player=blue
break;
case '3':
glColor3f(1.0f,1.0f,0.0f); //gold=yellow
break;
case '4':
glColor3f(0.8f,0.3f,0.8f); //treasure box=orange
break;
case '5':
glColor3f(1.0f,0.6f,0.6f); //heart= pink
break;
case '6':
glColor3f(1.0f,0.0f,0.0f); //mine=red
break;
case '7':
glColor3f(0.0f,1.0f,0.0f); //store=teal
break;
case 'X':
glColor3f(0.0f,0.0f,0.0f); //game border
}
glBegin(GL_QUADS);
glVertex3f(float(xpos), float(-ypos), 0.0f);
glVertex3f(float(xpos), float(-ypos-1), 0.0f);
glVertex3f(float(xpos+1), float(-ypos-1), 0.0f);
glVertex3f(float(xpos+1), float(-ypos), 0.0f);
glEnd();
xpos++;
counter++;
} while(counter < map.CurrentMap().size());
return true;
}
map.CurrentMap() returns a vector that's size 400.
winmain:
int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done = false; // Bool Variable To Exit Loop
DR game; // Create our game
// Create OpenGL window
if (!CreateGLWindow("Dark Raider",600,600,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
while(!done) // loop until done == true
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // if received quit msg
{
done = true; // then set done = true
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !game.DrawScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=true; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}
}
// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
Any help would be appreciated.. Thanks.