blank screen

hi,

does anybody know the problem?
i always get one frame with the sphere, then a blank screen.

the code:


GLint displayList;

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100,100);
glutCreateWindow(“OpenGL”);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
displayList = glGenLists(1);
glColor4f(0.2f, 0.2f, 0.2f, 0.75f);

glNewList(displayList, GL_COMPILE);
glutSolidSphere(1,10,10);
glEndList();

glutPassiveMotionFunc(mouseMotion);
glutIgnoreKeyRepeat(false);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(pressSpecialKey);
glutSpecialUpFunc(releaseSpecialKey);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(changeSize);
glutMainLoop();
}

void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glCallList(displayList);

gluLookAt(0, 1, 10,
0, 0, 0,
0.0f, 1.0f, 0.0f);

glutSwapBuffers();
}

void changeSize(int scrWidth, int scrHeight)
{
screenWidth = scrWidth;
screenHeight = scrHeight;

if(scrHeight == 0)
scrHeight = 1;

ratio = 1.0f * scrWidth / scrHeight;

glViewport(0, 0, scrWidth, scrHeight);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45, ratio, 1, 1000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

You are doing your lookat AFTER you draw your data with a call list, this is the wrong order.

this doesn’t work also…


void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0, 1, 10, 
		 0, 0, 0,
		 0.0f, 1.0f, 0.0f);

glCallList(displayList);

glutSwapBuffers();

}

The sphere might be too dark, try something that isn’t dark charcoal, how about white for a test, you probably have gamma 1 from your video and won’t see a thing at .2 brightness. The color is not in the display list either (not mandatory but just a warning for the future). Your alpha of 0.75 will have no effect unless you blend, just another point of caution.

How about putting glViewport after glMatrixMode and glLoadIdentity.

first of all, thx for your answers!
now it works, here the solution:


void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glCallList(displayList);

// glMatrixMode(GL_MODELVIEW) not necessary !
// !!! VERY IMPORTANT !!!
glLoadIdentity();
gluLookAt(…);

glutSwapBuffers();
}

void changeSize(int scrWidth, int scrHeight)
{
if(scrHeight == 0)
scrHeight = 1;

ratio = 1.0f * scrWidth / scrHeight;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(0, 0, scrWidth, scrHeight);

gluPerspective(45, ratio, 1, 1000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// necessary??? but it works…
gluLookAt(…);
}


very simple :wink:

These codes work in my computer(win2000)

Originally posted by thisPointer:
[b]this doesn’t work also…


void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0, 1, 10,
0, 0, 0,
0.0f, 1.0f, 0.0f);

glCallList(displayList);

glutSwapBuffers();
}[/b]