Thread

Posted on Tue Jun 26 23:36:37 2007 by marvin
HELP!!! Simple glOrtho problem!
Hey, can anyone explain to me why this code doesn't generate a visible red line from the left bottom to the top right corner of my window? void initGL() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black background glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.f, 1.f, 0.f, 1.f, 0.f, 1.f); glMatrixMode(GL_MODELVIEW); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen and depth buffer glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(1.0f, 1.0f, 1.0f); glEnd(); glFlush(); } int main(int argc, char** argv) // Create main function for bringing it all together { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB); // Display mode glutInitWindowSize(500, 500); glutCreateWindow("Aufgabe ?"); initGL(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); // callback for key input // glutIdleFunc(display); // If continuous animation is required glutMainLoop(); // Initialize the main loop } As you can see, I have specified the viewable volume as a cube of length one, one corner at (0, 0, 0), the other one at (1, 1, 1). I'm drawing the diagonal line through these two corners, so what I should expect on the 2D window surface is a diagonal line across the window. Why isn't this happening? My window remains BLACK. Please help. This is such a simple thing, and I'm stuck at this already. Cheers Marvin
Direct Responses: 7113 | Write a response
Posted on Sat Feb 16 23:06:44 2008 by grafman in response to 5552
Re: HELP!!! Simple glOrtho problem!

Just noticed this message...

The issue is your glOrtho setting. Since your viewpoint is at 0/0/0, part of the line is behind you. Try using glOrtho(0.f, 1.f, 0.f, 1.f, -1.f, 0.f);

Note - this is a Perl forum, and your example is in C - a better to way to reach me is via my POGL site.

You can also find great tutorials at NeHe

Good luck!

Write a response