Hello,
I've just recently switched my game from using SDL's 2D rendering to OpenGL (for performance and easier scaling of sprites). The first big problem I've run into is how to do 'pixel-perfect' OpenGL. For example, my ship positions are stored as double-precision floats. I used to be able to draw the ships' health bars using code such as:
boxColor( TX( ship->m_Position.getPosX() ) - 31,
TY( ship->m_Position.getPosY() ) - 39,
TX( ship->m_Position.getPosX() ) - 31 + ( 62 * healthPercent ),
TY( ship->m_Position.getPosY() ) - 36, 0x00FF00C0 );
(messy, I know). But now, I've replaced the SDL_gfx functions with OpenGL equivalents, such as:
void glLine( double x1, double y1, double x2, double y2, Uint32 color )
{
setColor( color );
glBegin( GL_LINES );
glVertex2f( x1, y1 );
glVertex2f( x2, y2 );
glEnd();
}
void hlineColor( Uint32 x1, Uint32 x2, Uint32 y, Uint32 color )
{
// Wrapper for glLine()
setAA( false );
glLine( (int)x1, (int)y, (int)x2, (int)y, color );
}
And it has stopped working. I've tweaked the settings of the above boxColor() call, so that when the ships' positions are integral (i.e. 100.0, 100.0), it will work (note in this screenshot, I haven't gotten any image-rendering functions converted yet):
But, when the ships have fractional positions, it becomes off:
I have already applied a glTransformf( -0.5, -0.5, 0.0 );, which has prevented the lines from moving position every time the ships move... but the bars apparently still move around when the ships move (and not in a good way).
I would rather not tweak a thousand more variables in order to get my rendering to work right... if anyone has any ideas on how to fix this (or has programmed a 2D game in OpenGL before, or something), they would be greatly appreciated! Thanks in advance!