PDA

View Full Version : Newbie Q: App Hanging



jbich
04-12-2005, 09:49 AM
Hey all.

Thanks in advance for any help you could supply me.
I'm very new to GL and glut, I've done some minor work with directx and decided to check out this path instead.

Anyway, I've got a very simple example that shows my problem: I have tried running a few tutorial programs and I've read through the glut spec and the beginning of the GL spec, every example works the same way.

When I use glutIdleFunc to render a scene on every pass, it locks up my linux box. Really, it seems like it's just doing to much stuff and becomes unusable, making a cold boot necessary :(

I did notice however, that when the example below is run not in a window, but full screen, that it runs fine.

Is there any reason for this?
It is obvious that the animation runs slower in fullscreen than in windowed mode, but as I'm new, I can't find any simple answer to the problem. Perhaps it's my hardware?

here's the example program (trimmed down):
[ try running it in a window... ]
-------------------------------
#include <GL/glut.h> // Header File For The GLUT Library
#include <GL/gl.h> // Header File For The OpenGL32 Library
#include <GL/glu.h> // Header File For The GLu32 Library
#include <unistd.h> // Header File For sleeping.

#define ESCAPE 27

int window;
float rtri = 0.0f;
float rquad = 0.0f;

void InitGL(int Width, int Height){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
}

void ReSizeGLScene(int Width, int Height){
if (Height==0)
Height=1;

glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
}

void DrawGLScene(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(-1.5f,0.0f,-6.0f);

glRotatef(rtri,0.0f,1.0f,0.0f);
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glLoadIdentity();
glTranslatef(1.5f,0.0f,-6.0f);
glRotatef(rquad,1.0f,0.0f,0.0f);
glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
rtri+=15.0f;
rquad-=15.0f;
glutSwapBuffers();
}

void keyPressed(unsigned char key, int x, int y) {
usleep(100);
if (key == ESCAPE) {
glutDestroyWindow(window);
exit(0);
}
}

int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutInitWindowPosition(0, 0);
window = glutCreateWindow("window");
glutDisplayFunc(&DrawGLScene);
glutFullScreen();
glutIdleFunc(&DrawGLScene);
glutReshapeFunc(&ReSizeGLScene);
glutKeyboardFunc(&keyPressed);
InitGL(640, 480);
glutMainLoop();
return 1;
}

-------------------------------

Raiden
04-12-2005, 09:57 AM
" glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH); "

try removing the GLUT_ALPHA.

did that to me too and without the alpha it works nice.

jbich
04-12-2005, 10:34 AM
Thanks for the reply Raiden!

I tried removing the alpha. This worked -sorta- ... The app, although animating at an incredibly fast speed in a small window, did keep running. Problem now is when I went to close the window, it hung the machine ...

lol. I have no luck ;)

That sounds like a window manager event issue, which I will try to debug, of course, any further insight would be fantastic.

Again thanks for the help.

j