views:

830

answers:

2

I am trying to learn OpenGL on the iPhone using the "Super Bible" but am having trouble porting from OpenGLto OpenGL ES. My understanding is that the glRectf() function is not available in the latter. What is the substitute approach? Any relevant conceptual information would be appreciated as well.

+2  A: 

Rather than doing a rect, you just do two triangles.

This is really irrelevant though since GL-ES on the iPhone does not support immediate mode. You need to define all your vertices in an array and use one of the vertex array rendering functions to draw them rather than using the immediate mode functions.

Eric Petroelje
+3  A: 

The substitute approach is to draw a triangle strip:

GLfloat texture[] =
{
 0, 0,
 0, 1,
 1, 0,
 1, 1
};

GLfloat model[] =
{
 0, 0, // lower left
 0, h, // upper left
 w, 0, // lower right
 w, h  // upper right
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(2, GL_FLOAT, 0, model);
glTexCoordPointer(2, GL_FLOAT, 0, texture);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

This draws a textured rectangle with width w and height h.

zoul
+1 - Just what I would have said, were I not too lazy right now to write up the code :)
Eric Petroelje