views:

604

answers:

2

I'm trying to render a 640x480 RGB565 image using OpenGL ES on Android using GLSurfaceView and Native C code.

Initially I had a 0x0501 error with glTexImage2D, which I was able to resolve by changing the image dimensions.

But now, in the "drawFrame" call, when I do glDrawTexiOES to resnder the texture, I'm getting the following error on the Logs:

drawtex.c:89: DrawTexture: No textures enabled

I'm already doing glEnable(GL_TEXTURE_2D), is there anything else I should do?

Is there a complete example showing GLSurfaceView with native code using textures?

Thanks in advance!

A: 

Did you generate a texture id and bind a texture first?

glGenTexture()/glBindTexture()

ddcruver
A: 

The following will get the texture all set up and ready to use on GL_TEXTURE0:

When loading the texture:

// in your native onSurfaceCreated function:

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
// setup texture parameters if you want:
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // etc.
glTexImage2D(GL_TEXTURE_2D, ... );

see here for how to fill out the TexImage2D parameters.

I've unfortunately not been able to get the glDrawTex_OES functions to work properly, but the texture does work if you render it onto a quad:

// in your native onRender function:

glBindTexture(GL_TEXTURE_2D, sGlTexture.texID);
// quad drawing:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, quadVerts[i]);
glTexCoordPointer(2, GL_FLOAT, 0, quadTexCoords[i]);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Clayton Hughes