// Note this is already in 2d ortho mode
glPushMatrix();
int x = 500;
int y = 30;
glTranslatef((float)x,(float)y,0.0f);
glBegin(GL_POINTS);
glVertex2i(0,0);
glEnd();
glPopMatrix();
For some reason, (float)x is getting converted to 499.0f, and in turn, causes the pixel to be drawn at (499,30) instead of (500,30).
However, if you change x to something like 300 or so, it gets converted properly, and the pixel gets drawn at (300,30).
What can I do to fix this? Is there a better way to get pixel perfect positioning in 2d?
Thanks for any help you might provide in advance.
2d pixel-perfect positioning
Not too happy right now, after rummaging through my code looking for an error I expected to have caused by my own fault, I come across a conversion inaccuracy:
If your card supports either OpenGL1.4 or the GL_ARB_window_pos extension, you can use the glWindowPos command which is pixel-exact but that''s limited for raster position (eg Bitmaps).
Otherwise there is an hint at the OpenGL.org FAQ : How do I draw 2D controls over my 3D rendering?
Otherwise there is an hint at the OpenGL.org FAQ : How do I draw 2D controls over my 3D rendering?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement