PDA

View Full Version : Mapping a sphere



pedr0
12-27-2010, 03:39 AM
Hi at all, I have a terrible issues with texure sphere mapping.

This is my code:

(Once)
gl.glDisable(GL10.GL_DEPTH_TEST); //Disable Depth Testing
gl.glEnable(GL11.GL_TEXTURE_2D);
gl.glEnable(GL11.GL_CULL_FACE);
gl.glCullFace(GL11.GL_FRONT);
gl.glFrontFace(GL11.GL_CCW);
gl.glGenTextures(2, textures_ids);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_ids.get(0));
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, this.image, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL11.GL_FLOAT, 0, vertexBuffer);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY );
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0,textureBuffer);
(EachFrame)
gl10.glMatrixMode(GL10.GL_PROJECTION);
gl10.glLoadIdentity();
gl10.glFrustumf(-15.0f, 15.0f, -15.0f, 15.0f, 1.0f, 100.0f); //Mio
gl10.glMatrixMode(GL10.GL_MODELVIEW);
gl10.glLoadIdentity();
GLU.gluLookAt(gl10, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -10.0f, 0.0f, 1.0f,0.0f);

gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_ids.get(0));
gl10.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, totalVertexCount);



The vertex buffer contains a points for a sphere and the texture contains the normals for that, I meet an horrible result and I don't understand what's wrong...

This is the result img:

Fail (http://img198.imageshack.us/i/failfs.png/)

I am working with android OpenGL ES but I think error isn't correlated with my platform but is correlated with my use of OpenGL API, I am a newbye with this library.

Thanks so much in advance.

carsten neumann
12-27-2010, 02:49 PM
Please enclose code snippets with
for better readability.

Why do you cull front faces and disable depth testing? Anyway, it seems your texture is being used (at least it looks that way in the picture you uploaded), so my guess would be that there is something wrong with the texture coordinates.
You might want to use a checker board texture for debugging this as it may make it a bit easier to see if it gets mapped correctly.