I’m getting some suspicious results using glOrtho, is it ok to set it up so that 1.0 = 1 pixel?
And if I want to zoom out:
glOrtho(-128, 127, -128, 127, 4, 4000);
glScalef(1/256, 1/256, 1/256);
is there any reason these would be a problem? I’m storing shape data in 16bit integer arrays and this would be more convenient.
No, don’t do it! Your computer will explode and the resulting void in space will create a miniature black hole and destroy humanity!!
Just kidding. There’s not much “unsafe” to do with OpenGL. The worst you can do is crash your program or at worst the OS.
As for the differences of what you’re doing, yes there is a difference. One is altering only the projection matrix–assuming you’re in projection mode at the time you call glOrtho–while the other is affecting both the projection and modelview matrix… hmmm… actually you could call glScale on the projection matrix and achieve what I assume would be the same results, except for any arithmetic differences that arrive in the transformation. If you’re going to do that, though, just do the one glOrtho call to save on overhead. A note too, that the code you have right there will give you nothing but a black screen since the compiler will interpret 1/256 and integral division and will evaluate to zero, thus you will produce a very unuseful completely zero projection matrix.
As for getting 1.0 to equal one pixel… There’s some work to that. If it has to be pixel perfect, you should probably read the specs a little bit to see what they say about invariance and how to achieve pixel perfection. Otherwise maybe you’d like to look into using glBitmap–which might hurt your performance; you might help it if you have the GL_ARB_pixel_buffer_object extension.
In the end, the world doesn’t march to the beat of just one drum, because what might be good for you, may not be good for some. Uou take the good, you take the bad, you take it all, and there you have… my response.
Mapping 1.0 == 1 pixel has no real meaning in 3D since the depth is not a dimension in pixel buffers. It would make sense in voxel rendering, but this is absolutely not the goal of OpenGL.
Anyway, considering you need exact 2D mapping, simply take a look at the OpenGL FAQ :