Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Mapping a sphere

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Location
    Milan
    Posts
    3

    Mapping a sphere

    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

    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    513

    Re: Mapping a sphere

    Please enclose code snippets with
    Code :
     
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •