View Full Version : setting up an (actual) 2d projection

07-31-2010, 12:38 PM
Hello, I am a hobbyist programmer who uses CodeBlocks and MingW32 on Windows XP. I am wondering where I could go to find out how to set up a 2d OpenGL context. This works fine for me:

if (h <= 0)
h = 1;

glViewport(0, 0, (GLsizei)w, (GLsizei)h);


gluPerspective(60.0f, float(w) / float(h), 1.0f, 100.0f);

//gluOrtho2D() would go here instead of gluPerspective,


followed by:


gluLookAt(0.0, 0.0, 1.74,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);

However, I've read elsewhere that setting up a 2D context can increase speed, and I'm thinking about experimenting with some 2D animation to see how much faster it is than SDL_BlitSurface() type animation. So...what gives? As in, where do I go to see a 2D setup or how would I modify the code above? Also, can I keep using glVertex2f() functions for drawing in a 2D context or would I have to get into glVertex2d()? It doesn't seem like it, considering the "2" should be the operative point there. Thx in advance for any responses! -B

07-31-2010, 02:04 PM
OpenGL does not care the slightest bit whether you use gluPerspective or gluOrtho2D.

In the end, it will be the same, a 4x4 matrix multiplication.
In theory sending 2 float coordinates instead of 3 might be faster, but using immediate mode (glBegin etc) is totally useless for anything caring about performance.

07-31-2010, 02:16 PM
Using opengl would do hardware blitting opposed to sdl which would do software blitting. Use gluortho to set a 2d projection and don't use glulookat unless you want a isometric looking display.

08-17-2010, 02:51 PM
thx for the info

08-17-2010, 02:52 PM
thx for the info, I set up glOrtho or gluOrtho2D and now I've got 640x480 instead of 639x479.

10-22-2010, 07:53 PM
Thanks for that information about glBegin, etc.; I've found by experience recently with some online tutorial code, that OpenGL animation is only faster if you don't use that immediate mode, otherwise it's SLOWER compared to SDL_BlitSurface!