Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6591091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:22:52+00:00 2026-05-25T17:22:52+00:00

I want to draw an earth globe on android. At this point I need

  • 0

I want to draw an earth globe on android. At this point I need help with the UV texture coordinates. I’m using this earth texture (kibotu.net/earth.jpg). Currently it looks like this front side (kibotu.net/earthsphere.png), but 90° rotated it looks like this (kibotu.net/earthsphere2.png).

Since OpenGL ES doesn’t support Quadrics and it has not a native GLUT library I find it rather difficult. So maybe someone came across the same Problem and can help me.

My first approach was to use Blender and export it as OBJ File and load it into my application. However there are 2 side effects: totally weird looking normals (kibotu.net/sphere.png) and most importantly no texture coordinates.

(I’ve used these Blender Export Options [kibotu.net/blenderobjoptions.png])

My second attempt was to use the freeglut library to do the job. Now I’ve got a nice looking sphere (kibotu.net/sphere5.png). However there are no texture coordinates either. Since it’s last version was released on 27 November 2009 I very much doubt that there will be an update any time soon.

So after that I’ve tried to apply the wiki approach to calculate sphere uvs. However it looked like this kibotu.net/sphere2.png. I was searching every single stackoverflow thread after this problem and came across this uv approach. However there is no final solution. I’ve applied it to the freeglut code.

static private FloatBuffer sphereVertex;
static private FloatBuffer sphereNormal;
static private FloatBuffer sphereTexture;
static float sphere_parms[]=new float[3];
private static void plotSpherePoints(float radius, int stacks, int slices)
{
    sphereVertex = OpenGLUtils.allocateFloatBuffer( 4* 6 * stacks * (slices+1) );
    sphereNormal = OpenGLUtils.allocateFloatBuffer( 4* 6 * stacks * (slices+1) );
    sphereTexture = OpenGLUtils.allocateFloatBuffer( 4* 4 * stacks * (slices+1) );

    int i, j; 
    float slicestep, stackstep;

    stackstep = ((float)Math.PI) / stacks;
    slicestep = 2.0f * ((float)Math.PI) / slices;

    int counter = 0;

    for (i = 0; i < stacks; ++i) {
        float a = i * stackstep;
        float b = a + stackstep;

        float s0 =  (float)Math.sin(a);
        float s1 =  (float)Math.sin(b);

        float c0 =  (float)Math.cos(a);
        float c1 =  (float)Math.cos(b);

        float nv,u,v,dx,dy,dz;
        for (j = 0; j <= slices; ++j)       
        {
            float c = j * slicestep;
            float x = (float)Math.cos(c);
            float y = (float)Math.sin(c);

            nv=x * s0;
            sphereNormal.put(nv);
            sphereVertex.put( dx = nv * radius);

            nv=y * s0;
            sphereNormal.put(nv);
            sphereVertex.put( dy = nv * radius);

            nv=c0;

            sphereNormal.put(nv);
            sphereVertex.put( dz = nv * radius);
            // uv 1
            if (dz < 0)
                u = (float) (1 + dx/Math.sqrt(dx*dx+dy*dy+dz*dz)  / 4);
            else
                u = (float) (1 - (1 + dx/Math.sqrt(dx*dx+dy*dy+dz*dz) ) / 4);

            v = (float) (0.5 + ( -dy/Math.sqrt(dx*dx+dy*dy+dz*dz) ) /2);

            // u = (float) (dx / Math.sqrt(dx*dx + dy*dy +dz*dz));
            // v = (float) (dy / Math.sqrt(dx*dx + dy*dy +dz*dz));
            sphereTexture.put(u);
            sphereTexture.put(v);

            nv=x * s1;

            sphereNormal.put(nv);
            sphereVertex.put( dx = nv * radius);

            nv=y * s1;

            sphereNormal.put(nv);
            sphereVertex.put( dy = nv * radius);

            nv=c1;

            sphereNormal.put(nv);
            sphereVertex.put( dz = nv * radius);

            // uv 2
            if (dz < 0)
                u = (float) (1 + dx/Math.sqrt(dx*dx+dy*dy+dz*dz)  / 4);
            else
                u = (float) (1 - (1 + dx/Math.sqrt(dx*dx+dy*dy+dz*dz) ) / 4);

            v = (float) (0.5 + ( -dy/Math.sqrt(dx*dx+dy*dy+dz*dz) ) /2);

            sphereTexture.put(u);
            sphereTexture.put(v);
        }
    }
    sphereNormal.position(0);
    sphereVertex.position(0);
    sphereTexture.position(0);
}

And the drawing algorithm:

public static class SolidSphere{
    public static void draw(GL10 gl,float radius, int slices, int stacks) 
    {
        int i, triangles;

        if (sphereVertex!=null) 
        {
            if (sphere_parms[0] != radius || sphere_parms[1] != slices || sphere_parms[2] != stacks) 
            {
                sphereVertex=null;
                sphereNormal=null;
                sphereTexture = null;

                gl.glVertexPointer(3, GL10.GL_FLOAT, 0, OpenGLUtils.allocateFloatBuffer(0));
                gl.glNormalPointer(GL10.GL_FLOAT, 0, OpenGLUtils.allocateFloatBuffer(0));
                gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, OpenGLUtils.allocateFloatBuffer(0));
            }
        }

        if (sphereVertex==null) 
        {
            sphere_parms[0] = radius; 
            sphere_parms[1] = (float)slices; 
            sphere_parms[2] = (float)stacks;

            plotSpherePoints(radius, stacks, slices);
        }

        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, sphereVertex);
        gl.glNormalPointer(GL10.GL_FLOAT, 0, sphereNormal);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, sphereTexture);

        gl.glEnableClientState (GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState (GL10.GL_NORMAL_ARRAY);
        gl.glEnableClientState (GL10.GL_TEXTURE_COORD_ARRAY);

        triangles = (slices + 1) * 2;
        for(i = 0; i < stacks; i++)
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i * triangles, triangles);

        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    }
}

Can anyone help me figuring this out please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:22:53+00:00Added an answer on May 25, 2026 at 5:22 pm

    You should be able to take any triangle mesh for a (unit) sphere and apply a mapping from vertex (X,Y,Z) to (UV).

    I’m too lazy / busy (delete whichever you wish) to go through your code, but you might find the answer in chapter 6 of Watt & Watt’s “Advanced Animation and Rendering Techniques”. It gives some simple approaches to generating suitable UV coords for spheres.

    IIRC, to avoid too much distortion at the poles, their mapping uses sine to squeeze/stretch the latitude mapping.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw a simple graph like this in android. Can it be
I want to draw several cubes using glutSolidCube in some points in space. The
I want to draw a stock chart using Google Chart Tools. My self-written webservice
I want to Draw a hyper Link in C# using stringbuilder when i create
I want to draw lat log in every 1 Km interval using service. I
I want to draw this type of circle in my application. I am able
I want to draw a line using CSS 3 and place it under an
i am using TabControl in my windows form application (c#) and i want draw
I want to draw a sine wave on a image using openCV. I developed
I want draw a line between to specify point in java 3d. how can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.