Game Development Reference
In-Depth Information
static void DrawIntoTextureRGB565 (unsigned short * pixels, int w, int h)
{
// clear screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// enable vetices & and texture coordinates
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mTextureID);
glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
pixels);
// Draw quad
glFrontFace(GL_CCW);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnable(GL_TEXTURE_2D);
glTexCoordPointer(2, GL_FLOAT, 0, coords);
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);
}
// Flip surface (Draw into texture)
void JNI_RGB565_Flip(unsigned short *pixels , int width, int height)
{
if ( ! pixels) {
return;
}
DrawIntoTextureRGB565 (pixels, width, height);
// Must swap GLES buffers here
jni_swap_buffers ();
}
To render into the texture using OpenGL, follow these steps.
1.
Clear the color and depth buffers using glClear(GL_COLOR_BUFFER_
BIT | GL_DEPTH_BUFFER_BIT) .
2.
Enable the client state: vertex array and texture coordinates array for
writing when glDrawElements is called.
3.
Select active texture unit with glActiveTexture where the initial value
is GL_TEXTURE0 .
4.
Bind a named texture to a texturing target. GL_TEXTURE_2D
(a 2D surface) is the default target to which the texture is bound.
mTextureID is the ID of a texture.
Search WWH ::




Custom Search