Code:
//==========================================
// BACKGROUND PLANE
static const GLbyte bgverts[8] =
{
0, 0,
1, 0,
0, 1,
1, 1
};
static const GLubyte bgtex[8] =
{
0, 1,
1, 1,
0, 0,
1, 0
};
void DrawBGPoly()
{
glPushMatrix();
// Enable vertex arrays.
glEnableClientState( GL_VERTEX_ARRAY );
// Set array pointers.
glVertexPointer( 2, GL_BYTE, 0, bgverts );
// Enable texture arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
// Set texture coords
glTexCoordPointer( 2, GL_BYTE, 0, bgtex );
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
void PerspectiveMode()
{
// Load our projection matrix
glMatrixMode( GL_PROJECTION );
glEnable( GL_DEPTH_TEST );
glEnable( GL_CULL_FACE );
// Get rid of ortho mode which was lst pushed in the projection matrix mode
glPopMatrix();
// Go back to model view matrix
glMatrixMode( GL_MODELVIEW );
}
void OrthoMode(TInt aLeft, TInt aRight, TInt aBottom, TInt aTop )
{
// Switch to our projection matrix so that we can change it to ortho mode, not perspective.
glMatrixMode(GL_PROJECTION);
// Push on a new matrix so that we can just pop it off to go back to perspective mode
glPushMatrix();
glDisable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE );
// Reset the current matrix to our identify matrix
glLoadIdentity();
// Pass in our 2D ortho screen coordinates (left, right, bottom, top, near, far).
glOrthof( aLeft, aRight, aBottom, aTop, -1, 1 );
// Switch to model view so that we can render the texture
glMatrixMode(GL_MODELVIEW);
// Initialize the current model view matrix with the identity matrix
glLoadIdentity();
}
void RenderTexturedBG(TUint8* aCamFrameData)
{
// Textures are initialized in OpenGL ES API by this function.
glGenTextures( 1, iTexturesID );
/* Bind the background texture to iTexturesID[0],
set the texture environment. */
glBindTexture( GL_TEXTURE_2D, iTexturesID[0] );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 256, 128,
0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)aCamFrameData );
glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Before drawing the background texture, we need to switch to ortho (2D) mode.
// Passing 1 instead of the implicit size of screen will make OpeGL use the full size of screen (1:1)
OrthoMode(0, 1, 0, 1);
DrawBGPoly();
PerspectiveMode();
glDeleteTextures(1, iTexturesID);
}