views:

79

answers:

1

I'm using opengl es 2.0 on android 2.2. My problem here isn't with the canvas, or creating a fullscreen android view, that I already have figured out.

I'm wondering how you would set the coordinates of a GL_QUAD, or 2 GL_TRIANGLES to perfectly cover the entire screen, for use as a texturing surface for a 2D game, for example.

I currently have the gluPerspective set to:

float ratio = (float) width / height;
GLU.gluPerspective( gl, 45.0f, ratio, 1.0f, 100.0f );

inside onSurfaceChanged, so the width and height variables are the width and height of the screen, respectively.

next I have the coordinates of the quad as:

public static final float screenVerts[] = {
  -1f, -1f,
   1f, -1f,
   1f,  1f,
  -1f,  1f
};

however the displayed quadrilateral isn't in proportion to the screen, it's simply displayed as a square, with the coordinates apparently being relative to opengl's own geometry, not the screen's height / width.

how do I make the screenVerts variable, (2D points for the rect that I draw on) to be relative to the screen itself? I.e. 1.0f being 100% of the screen's height in the Y-coordinate of one of the points in the quad.

And I really do apologize for not phrasing this well, no offense will be taken if I need to explain myself again.

+1  A: 

Hi,

You should setup your projection matrix with gluOrtho2D instead. Another thing is that there is no GL_QUAD in OpenGL ES, you have to go for two triangles. And last - if you want to draw an axis-aligned texture, it'll be faster and easier with glDrawTexiOES, if the device supports OES_draw_texture extension (which is widely supported by Android devices).

ognian
ah, thank you. I know that opengl es only supports triangles, fan triangles and strip triangles, I was just trying to avoid confusion that the end product that i wanted was a rectangle.Thank you for being so helpful, it seems like people just don't write documentation like they used to. xD
N8-bit