[fpc-pascal] OpenGL ES bitmap drawing

Reimar Grabowski reimgrab at web.de
Sun Nov 27 00:26:21 CET 2011


On Sat, 26 Nov 2011 16:30:31 +0100
Felipe Monteiro de Carvalho <felipemonteiro.carvalho at gmail.com> wrote:

> What is lit geometry? Google didn't help me here.
Geometry is anything you draw in OpenGL (in CG the term mesh is preferred) and lit just means that you use lighting and must therefor provide normals, take care of setting the lights, etc.
 
> I just want to draw a 2D image which fills the entire screen. I don't
> want any 3D at all. Only 1 texture which covers the entire screen.
Here is my OpenGL (note not ES) "textured fullscreen quad" code, ripped directly from my engine: 

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix;
  glLoadIdentity;
  glMatrixMode(GL_PROJECTION);
  glPushMatrix;
  glLoadIdentity;
  glDepthFunc(GL_LESS); <-- you don't need this if you disable the depth test before drawing
  glColor3fv(@BackgroundColor); <-- color can be set using the ordinary glColor3f/4f functions instead 
  glBindTexture(GL_TEXTURE_2D, BackgroundImage.id); <-- texture is already set up, but your set up code looked ok, so I don't post mine 
  glBegin(GL_QUADS); <-- this is not supported in ES as you have to use attribute arrays (like in your code)		
  glTexCoord2d(0, 1); glVertex3f(-1, -1, -1); <-- these values must be stuffed in your attribute arrays only that you have to adjust the texture coordinates to your needs (see below)
  glTexCoord2d(1, 1); glVertex3f(1, -1, -1);
  glTexCoord2d(1, 0); glVertex3f(1, 1, -1);
  glTexCoord2d(0, 0); glVertex3f(-1, 1, -1);
  glEnd;
  glPopMatrix;
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix;

Note: No call to glOrtho, just indentity matrices for projection and modelview. Lighting and blending is disabled when I call this function.

> The worse part here is that with the power of two limitation it seams
> that I will have a lot of problems, because with this limitation I
> can't match correctly the screen format. Usually the screens are 2x3
> in proporsions, but power of two allows only 1x2 from what I
> understand.
Nope, the only problem is that you need more texture memory for your image. Say your screen size is 640x480. Because of the pot limitation your texture must be 1024x512. Since you only want to render the 640x480 part of the texture to your quad you need to adjust your texture coordinates accordingly. Texture coordinates are in the range 0 to 1. But as you do not for example want the rightmost texel of the whole texure but the rightmost one of your smaller image you have to use 0.625 (1024/640) instead of 1. The same for the Y-coordinate.

Unfortunately we have left the realm of FPC programming and wandered of into the wonderful world of OpenGL. Perhaps a place dedicated to OpenGL development is better suited for this problem.
You may take a look at the NeHe OpenGL examples. They are available in many different languages (including delphi) and cover most of the basic stuff.

R.



More information about the fpc-pascal mailing list