PDA

View Full Version : blank screen



thisPointer
11-16-2001, 05:09 AM
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();
}

dorbie
11-16-2001, 05:17 AM
You are doing your lookat AFTER you draw your data with a call list, this is the wrong order.

thisPointer
11-16-2001, 05:26 AM
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();
}

dorbie
11-16-2001, 08:51 AM
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.

Questions Burner
11-17-2001, 05:04 AM
How about putting glViewport after glMatrixMode and glLoadIdentity.

thisPointer
11-19-2001, 04:31 AM
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 ;-)

zero_t9
03-27-2005, 04:21 PM
These codes work in my computer(win2000)


Originally posted by thisPointer:
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();
}