[fpc-pascal] OpenGL ES bitmap drawing

Sven Barth pascaldragon at googlemail.com
Sun Nov 27 19:50:30 CET 2011


On 27.11.2011 17:26, Sven Barth wrote:
> On 26.11.2011 21:32, Felipe Monteiro de Carvalho wrote:
>> // Displacement trick for exact pixelization
>> glTranslatef(0.357, 0.357, 0);
>
> Untested guess: try to move your object in front of the virtual camera
> (which is located at (0, 0, 0) ). Thus set the Z value to something
> negative (e.g. -0.5 as you've set your far clipping plane to 1). [The Z
> axis is pointing from the infinity in front of you through the origin,
> thus the negative values]

Ok, I have now experimented myself with glOrtho (as I had to do a 
homework where we need to do a simple OpenGL project (boooring) I used 
the time to find a solution for you ^^). The problem is not the missing 
translation, but your setup of the orthographic projection matrix. The 
coordinates you define there are NOT your viewport coordinates. Thus the 
origin lies not at the upper left corner, but at the center! So if you 
adjust your call to the following it should work:

glOrthof(-engine^.width/2, engine^.width/2, engine^.height/2, 
-engine^.height/2, 0, 1);

Also it is sufficient to set the projection matrix only when a change in 
the size of the window happens (or when you really need to switch 
between rendering 3D and 2D content, e.g. when drawing a 2D GUI above a 
3D scene).

Regards,
Sven




More information about the fpc-pascal mailing list