could someone explain to me how does the opengl interacts with 2d and 3d?
For example if i wan’t to make a bar in 2d on the top of the screen, and then a cube rotating, what do i have to do?
I know it has something to do with the glortho and glmatrixmode, but i really don’t understand…
Heh…good luck getting 2D to work in OpenGL without your framerate dropping to say 1 frame per 10 seconds
what? 2d is just 3d but without the depth. and, no, that’s not a silly thing to say.
(opengl 2D is drawing on a PLANE with z=0 in three dimensions. same thing…)
John’s right, 2D need not be a performance issue in OpenGL if you do it right. The only real problem is if you’re coming from DOS and are used to having direct access to the framebuffer. In which case, you need to get over it, because those days are gone.
Use this 2 functions:
glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0,1,1,0,1,-1);
After calling Enter2dMode() you have (0,0) at upper left corner of screen, and (1,1) at lower right corner. Now you can use glVertex2f() to specify 2d coords. After you’ve done your 2d work you can return to previous state with Exit2dMode().
thanks a lot
Humus is proposing a unit square reference frame for 2D work in OpenGL. This does have it’s merits, because it’s sometimes more logical/easier to think of placement as a proportion of the window.
An alternative is to map the projection matrix to the pixels, so you’d have left=top=0 and right=width and bottom=height of the screen. That way you can say glVertex(5,5) maps to the pixel 5,5 of the screen.
Both techniques, i would argue, have their place.