Jump to content
  • Advertisement
Sign in to follow this  
Strider007

GLUT 100% CPU Issue

This topic is 4447 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey im hoping someone could hopefully help me out with an issue i have. Basically ive created a GLUT application and every time i compile and run it im hitting 100% cpu usage. Strange and confusing thing is that it works fine on any other PC and if i run any other GLUT application on my PC it just maxes out my CPU. Any Ideas?

Share this post


Link to post
Share on other sites
Advertisement
It's impossible to tell what your bottleneck is without seeing some code. I would recommend profiling it or posting some likely points of interest.

As a side note, run your code with your SwapBuffers() call commented out and see what your CPU runs at. It won't draw anything but it will tell you how much time the SwapBuffers() is eating up.

Share this post


Link to post
Share on other sites
If you can see your Windows message pump, it should say PeekMessage instead of GetMessage. I'm betting thats exactly what it is.

Share this post


Link to post
Share on other sites
Commented out glswapbuffers() and had no effect.

Heres my main.cpp file.




#include <windows.h>
#include <stdio.h>
#include <glut.h>
#include <gl\gl.h>
#include <math.h>
#include "Texture.h"
#include "Collision.h"
#pragma comment( lib, "Glu32.lib")
#pragma comment( lib, "glaux.lib")
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )

bool LoadTGA(Texture *, char *);
Texture texture[2];




int LoadGLTextures()
{
int Status=FALSE;

if (LoadTGA(&texture[0], "Media/Background.tga"))
(LoadTGA(&texture[1], "Media/Striker.tga"));
{
Status=TRUE;

for (int loop=0; loop<2; loop++)
{
glGenTextures(1, &texture[loop].texID); glBindTexture(GL_TEXTURE_2D, texture[loop].texID);
glTexImage2D(GL_TEXTURE_2D, 0, texture[loop].bpp / 8, texture[loop].width, texture[loop].height, 0, texture[loop].type, GL_UNSIGNED_BYTE, texture[loop].imageData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

if (texture[loop].imageData)
{
free(texture[loop].imageData);
}
}
}
return Status;
}

void renderScene() {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(-90,0.0,0.0,1.0);
glBindTexture(GL_TEXTURE_2D, texture[0].texID);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f,-1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(-1.0f,1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f,1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex2f(1.0f,-1.0f);
glEnd();

glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();

}

void InitOpenGL(void)
{
glOrtho(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
}



void vars(void)
{
float speed=0.0f;
speed += 0.05;
glutPostRedisplay();
}

void main(int argc, char **argv) {

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(768,576);
glutCreateWindow("Carrom Board");

LoadGLTextures();
InitOpenGL();

glutDisplayFunc(renderScene);
glutIdleFunc(vars);

glEnable(GL_DEPTH_TEST);
glutMainLoop();

}


Share this post


Link to post
Share on other sites
Quote:
Original post by dpadam450
If you can see your Windows message pump, it should say PeekMessage instead of GetMessage. I'm betting thats exactly what it is.


Not entirely sure what you mean.

Share this post


Link to post
Share on other sites
Quote:
Original post by dpadam450
If you can see your Windows message pump, it should say PeekMessage instead of GetMessage. I'm betting thats exactly what it is.


Completely irrelevant.

Quote:
Original post by Strider007
void renderScene() {
...
glutPostRedisplay();
}


This is why you have 100% CPU usage. As soon as your renderScene function completes, you have requested for it to be called again.

Share this post


Link to post
Share on other sites
Quote:
Original post by bakery2k1
Quote:
Original post by dpadam450
If you can see your Windows message pump, it should say PeekMessage instead of GetMessage. I'm betting thats exactly what it is.


Completely irrelevant.

Quote:
Original post by Strider007
void renderScene() {
...
glutPostRedisplay();
}


This is why you have 100% CPU usage. As soon as your renderScene function completes, you have requested for it to be called again.




Removing glutPostRedisplay(); has no effect either. The thing is the code works fine on other computers just not mine. Is there anything other than the code that could be affecting the performance?

Share this post


Link to post
Share on other sites
ignore the vars function ive deleted that, i stuck that in hoping that would solve the issue which i got from a thread but that had no effect.

Share this post


Link to post
Share on other sites
It will show the program using 100% unless you are throttling it using sleeping commands after you draw the screne..

After you draw the scene do this:


include: <windows.h>
include: <winbase.h>
...
...
...
Sleep(100); // sleep 100ms


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!