glTexImage2D failing with GL_INVALID_ENUM when creating texture using GL_ALPHA format

3,069 views
Skip to first unread message

mannewalis

unread,
Dec 22, 2011, 2:27:31 PM12/22/11
to android-ndk
Hi

I am porting some code to Android using the NDK which is working
pretty well so far. The issue I am having is that the texture I am
creating for a font is failing.

The call is this...

glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA,
GL_UNSIGNED_BYTE, data);

width = 128
height = 64

and it fails with glGetError() reporting 1280 which is GL_INVALID_ENUM
I believe

I have tried replacing the GL_ALPHA with GL_LUMINANCE as well as
making sure the width and height are the same (thinking the GPU might
require the pow2 being the same for both axis) but am having no luck.

Does anyone have any idea why this call might be failing?

Thanks
Justin

Ken Turkowski

unread,
Jan 3, 2012, 11:47:09 AM1/3/12
to andro...@googlegroups.com


I'm using the exact thing with no proiblem.

The errors in GL are sticky. Try calling glError() beforehand.

Have you tried GL_RGB?

I assume that you have already called glBindTexture()

You might try preceding everything with
glActiveTexture(GL_TEXTURE0);


Message has been deleted

Lohit

unread,
Jan 4, 2012, 8:31:15 AM1/4/12
to android-ndk
Hi mannewalis,
This can be solved in 2 ways,
1. The texture should be binded before you do any operation on
the texture. To be in safer side, the texture size should be in
power
of 2.
To generate the texture, use glGenTextures(int n, IntBuffer
textures)
To bind the texture, use glBindTexture(int target, int texture).
Eg:
// Our texture.
int[] textures = new int[1];
//Generate one texture pointer...
gl.glGenTextures(1, textures, 0);
//...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

The above texture creation and binding should be called only
once when the surface is created. Now u should be able to call your
glTexImage2D() any number of times in draw().

2. The second solution is as follows,
try using below code inside some function say
public void loadGLTexture(){
..
//your code that sets all texture parameters.
..
int textureWidthInPowerOf2 = 512;
int textureHeightInPowerOf2= 512;
/** Create a bitMap which has width and height in
power of 2. */
Bitmap b = Bitmap.createBitmap(textureWidthInPowerOf2,
textureHeightInPowerOf2, Bitmap.Config.RGB_565);
/** This function creates a texture of size
textureWidthInPowerOf2*textureHeightInPowerOf2. */
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, b, 0);
}
The above function should be called only once and good if it is called
in onSurfaceCreated(). The above code draws a bitMap with texture as
specified.The texture is now set.

And in

public void draw(){
..
// Your code that may or may not crop the image.
..
GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0,0,0, aBitmap);
}

Now, you can draw bitmap any number of times on the texture that was
created.

The solution 2 is demo to draw bitMaps, u can use the same logic to
draw anything.

Also, you get error code 1280 if the parameters passed to any openGL
function call is invalid or not appropriate.
Reply all
Reply to author
Forward
0 new messages