OpenGL - 2D Query

Morning, all :)

I'm planning on making a simple 2D game. The game will be using OpenGL 3.2 for the rendering. After some research, I found that glVertex3i( ) was deprecated, and is only available in compatibility mode, which is optional for some GPUs. Instead, I now have to use shaders and floating-point precision.

The problem is, if I draw my game's 2D tiles, I fear that the tiles will be misaligned due to floating-point precision loss over time. Is there any way of specifying exact pixel co-ordinates instead of floats?

Also, after some reading, I've noticed that may OpenGL tutorials use -1.0 to 1.0 co-ordinates. Why?

Regards,
The problem is, if I draw my game's 2D tiles, I fear that the tiles will be misaligned due to floating-point precision loss over time. Is there any way of specifying exact pixel co-ordinates instead of floats?


You should use exact pixel co-ordinates for your tile locations. The conversion to float should happen only at the very last stage, when drawing them on the screen, and you shouldn't keep hold of those float values because you don't care about them; you care about the actual, exact position of your tiles, which you are keeping track of yourself. OpenGL works for you; not the other way around.
Last edited on
You should definitely be using shaders, yes.

I doubt there are going to be any misalignment issues. I get the impression you think your sprites/tiles have to be in the coordinate space -1.0 to 1.0 and that might be what's worrying you.

The -1.0 to 1.0 space that the tutorials are operating in sounds like normalized device space to me. This would be your coordinates once you've performed your world, view and projection transformations.

You should be able to create sprite meshes wherever, really. As long your MVP transformations are set up correctly they'll eventually find their way to normalized device coordinates.
Thank you for the replies.

Moschops, how do I specify screen co-ordinates, then? I've been reading around, yet again, and came across the glVertexAttribFormat( ) function, where I can specify GL_INT for the type parameter. From what I understand, this tells OpenGL that the vertex co-ordinates are in pixels. Am I right? However, I want my game to function on my laptop, but that runs OpenGL 3.2, and glVertexAttribFormat( ) isn't supported until 4.3. Alternatives?

iHutch105, yes, I think I was referring to NDS after further inspection. Thanks for the hint on transformation and projections; I'm bearing that in mind.

Regards,
Topic archived. No new replies allowed.