gluPerspective & gluOrtho2D

Howzit

I wrote a method that accepts a width and a height, which then goes and paints quads on the screen at the revelant places. I did this using gluOrtho2D and glTranslatef and it works perfectly.

Then I change to gluPerspective and I draw a small quad in the center of the screen also with glTranslatef.

When I press the arrow keys I increase/decrease the x or y values as needed to get the background to move around.

The problem comes in when I press the arrow keys. The small block in the middel of the screen dissappears.
The background is still there though.

What can I do?

There’s no need to use translatef on the background since you’re rendering in an ortho projection. All you need do ise set the ortho projection bounds to the dimensions of the screen/window. For example, with a resolution/window size of 800x600, the call might look like this:

gluOrtho2D(0,800,0,600);

Using the above, 0,0 will be in the lower left corner of the screen. Doing it this way:

gluOrtho2D(0,800,600,0);

puts (0,0) in the upper left corner. Then to render a quad you can use screen coordinates rather than world coordinates.