1
votes

I'm having great difficulty getting basic textures to work in an OpenGL ES app on my Droid (2.1-update1). I trying to render a simple textured quad - four vertices, two faces, with normals and texture coords. When rendered, the texture is garbled and full of static, similar to TV noise.

Here's a pic showing the original texture map image, and then a screencap from my droid of the rendered textured quad : http://img686.imageshack.us/img686/6342/texturedquad.png

The basic colors are there, but obviously the texture isn't being read or applied correctly.

My texture load sequence is simple :

int[] textures = new int[1];
gl.glGenTextures(1, textures, 0);
Bitmap bmp = BitmapFactory.decodeResource(cx.getResources(), R.drawable.img);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);

I've tried setting various parameters for glTexParameterf at texture load time, but to no avail :

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

My render sequence is also very simple :

(setup)

gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glDisable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_FOG);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glDisable(GL10.GL_COLOR_MATERIAL);
gl.glShadeModel(GL10.GL_SMOOTH);

(render)

gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FIXED, 0, vertices);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_SHORT, 0, textureCoords);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
gl.glDrawElements(GL10.GL_TRIANGLES, numIndices, GL10.GL_UNSIGNED_SHORT, indices);

...

I've tried various texture image file formats, all sized ^2, placed under the drawable-nodpi folder. PNG, BMP, GIF, JPEG all give me the same result. I've also tried 8 and 16 bit color depths. I'm running this on top of GLSurfaceView with the default EGL config.

Can anyone shed some light on why my texture is coming through garbled?

Below is my index/vertex/normal/texcoord data. I've been over it a dozen times but perhaps I missed something.

Adding vertex (vIndex 1) Vector3F(77.0492, 0.0, 0)
Adding vertex (vIndex 2) Vector3F(478.1715, 0.0, 0)
Adding vertex (vIndex 3) Vector3F(478.1715, 227.0969, 0)
Adding vertex (vIndex 4) Vector3F(77.0492, 227.0969, 0)
Adding normal Vector3F(0.0, 0.0, 1.0)
Adding normal Vector3F(0.0, 0.0, 1.0)
Adding normal Vector3F(0.0, 0.0, 1.0)
Adding normal Vector3F(0.0, 0.0, 1.0)
Adding textureCoords Vector3F(0.0, 0.0)
Adding textureCoords Vector3F(1.0, 0.0)
Adding textureCoords Vector3F(1.0, 1.0)
Adding textureCoords Vector3F(0.0, 1.0)
Adding face indexes 1,2,3
Adding face indexes 3,4,1
1
Does it work in the emulator?genpfault

1 Answers

1
votes

Ok disregard my question, I found the issue.

It turns out my texture coordinates were stored as 32-bit unsigned ints, and I was passing GL_SHORT into the glTexCoordPointer call (I needed to be using GL_FIXED). This explains the random static texture mapping you can see in the rendered result.