PDA

View Full Version : Slowly moving objects


McSebi
2006.07.02, 02:42 PM
I have some 2D objects in a 2D world using glOrtho. The objects use textured quads. The view port is expanded so the whole scene is magnified.
When I move them at a speed lower than 1 pixel per animation frame (for example 0.6) I get a "pumping" effect: The texture appears one pixel smaller some times.
I have also seen small vertical lines inside the textures appear darker when they get moved this way. Anyone has an idea whta can be wrong here?

If I move the objects by integer values there is no problem.

Fenris
2006.07.02, 04:08 PM
What happens is that OpenGL notices that all the pixels in the texture are between pixels, and filters them out. One thing you can do (and probably should) is to just switch all your glVertex2f calls to glVertex2i. This will allow you to keep floating-point precision in your logic, but render on integer positions. If you go this route, I'd recommend you to put:
glTranslatef (0.375, 0.375, 0);
just after your call to glLoadIdentity(). This will offset your entire scene by a small amount, which is a sort of magic number to achieve good filtering. Search the Red Book for 0.375 for an explanation. :)

McSebi
2006.07.03, 06:01 PM
Thanks. This is possible and fixes the pumping effect. However, it is then not possible to resize the whole scene to screen size because the slow moving objects now "step" from one magnified integer position to the next.

So it seems I need to use bigger objects to avoid magnification...