Reputation: 13415
I'm trying to create a simple project using freeglut. Well all my previous projects were working before but new one shows nothing in window. I don't understand why.
There I initialize glut
int main(int argc, char* argv[])
{
cout<<"Initializing project...."<<endl;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_MULTISAMPLE);
glutInitContextVersion(3, 3);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
glutInitContextFlags(GLUT_COMPATIBILITY_PROFILE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 800);
glutCreateWindow("PROJECT");
glewExperimental = true;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
if (glewIsSupported("GL_VERSION_3_3"))
cout<<"SUCCESS: Opengl 3.3 supported"<<endl;
else {
cout<<"FAIL: Opengl 3.3 not supported"<<endl;
getchar();
return 1;
}
glViewport(0, 0, 800, 800);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 1.0, 0.5f ,150.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glutSetCursor(GLUT_CURSOR_NONE);
cout<<"INIT: functions binding....";
glutDisplayFunc(render);
glutIdleFunc(render);
cout<<"SUCCESS"<<endl;
cout<<"GLUT STARTS NOW!"<<endl;
glutMainLoop();
cout<<"GLUT WINDOW CLOSED!"<<endl;
cout<<"Cleaning...."<<endl;
cout<<"Press any ENTER to exit..."<<endl;
getchar();
return 0;
}
function render
looks like this
void render()
{
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_LINES);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.1, 0, 0);
glVertex3f(0.1, 0.5, 0);
glVertex3f(0.5, 0.5, 0);
glVertex3f(0.5, 0.0, 0);
glEnd();
glutSwapBuffers();
}
But it shows nothing. What is the problem?
Upvotes: 0
Views: 594
Reputation: 14781
The 3rd and 4th parameters of gluPerspective
means the zNear
and zFar
for clipping. As you're setting it to 0.5~150
, the z-value you pass to glVertex3f
shall be changed since in OpenGL we're looking into the negative direction of Z by default. You may try something like glVertex3f(0.1, 0.5, -10)
Also, on my platform I must also comment this line glutInitContextVersion(3, 3);
to make it working. That's an extension of freeglut
and I rarely use that in my experiences. Maybe you could also remove that line without affecting your final results.
Upvotes: 1