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 7862247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:03:27+00:00 2026-06-02T23:03:27+00:00

I am drawing a 3d sphere using GL_QUAD_STRIP primitive and it works except I

  • 0

I am drawing a 3d sphere using GL_QUAD_STRIP primitive and it works except I don’t know how to set up the texture coordinates.

I have a certain number of division that divide my sphere into equal number of latitudes and longitudes. Hence, the sphere’s vertices are approximated using the divisions as follows

   float x, y, z, dTheta=180/divisions, dLon=360/divisions, degToRad=3.14/180 ;

    for(float lat =0 ; lat <=180 ; lat+=dTheta)
    {
        glBegin( GL_QUAD_STRIP ) ;
        for(float lon = 0 ; lon <=360; lon+=dLon)
        {  

            x = r*cosf(lat * degToRad) * sinf(lon * degToRad) ;
            y = r*sinf(lat * degToRad) * sinf(lon * degToRad) ;
            z = r*cosf(lon * degToRad) ;

            glNormal3f( x, y, z) ;
            glVertex3f( x, y, z ) ;

            x = r*cosf((lat + dTheta) * degToRad) * sinf(lon * degToRad) ;
            y = r*sinf((lat + dTheta) * degToRad) * sinf(lon * degToRad) ;
            z = r*cosf( lon * degToRad ) ;

            glNormal3f( x, y, z ) ;
            glVertex3f( x, y, z ) ;
        }
        glEnd() ;

    }
  • 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-06-02T23:03:28+00:00Added an answer on June 2, 2026 at 11:03 pm

    Okay the problem was that I was only drawing 2 vertices and GL_QUAD_STRIP requires 4. The following code now has both vertices set up properly and texture working

       double x, y, z, dTheta=180/divisions, dLon=360/divisions, degToRad=3.141592665885/180 ;
    
        for(double lat =0; lat <=180; lat+=dTheta)
        {
    
            glBegin( GL_QUAD_STRIP ) ;
            for(double lon =0 ; lon <=360 ; lon+=dLon)
            {  
    
    
                //Vertex 1
                x = r*cos(lon * degToRad) * sin(lat * degToRad) ;
                y = r*sin(lon * degToRad) * sin(lat * degToRad) ;
                z = r*cos(lat * degToRad) ;
                glNormal3d( x, y, z) ;
                glTexCoord2d(lon/360-0.25, lat/180);
                glVertex3d( x, y, z ) ;
    
    
                //Vetex 2
                x = r*cos(lon * degToRad) * sin( (lat + dTheta)* degToRad) ;
                y = r*sin(lon * degToRad) * sin((lat + dTheta) * degToRad) ;
                z = r*cos( (lat + dTheta) * degToRad ) ;
                glNormal3d( x, y, z ) ;
                glTexCoord2d(lon/360-0.25, (lat + dTheta-1)/(180)); 
                glVertex3d( x, y, z ) ;
    
    
                //Vertex 3
                x = r*cos((lon + dLon) * degToRad) * sin((lat) * degToRad) ;
                y = r*sin((lon + dLon) * degToRad) * sin((lat) * degToRad) ;
                z = r*cos((lat) * degToRad ) ;
                glNormal3d( x, y, z ) ;
               glTexCoord2d((lon + dLon)/(360)-0.25 ,(lat)/180);
                 glVertex3d( x, y, z ) ;
    
    
                //Vertex 4
                x = r*cos((lon + dLon) * degToRad) * sin((lat + dTheta)* degToRad) ;
                y = r*sin((lon + dLon)* degToRad) * sin((lat + dTheta)* degToRad) ;
                z = r*cos((lat + dTheta)* degToRad ) ;
                glNormal3d( x, y, z ) ;
                glTexCoord2d((lon + dLon)/360-0.25, (lat + dTheta)/(180));
                 glVertex3d( x, y, z ) ;
    
    
            }
            glEnd() ;
    
        }
    

    Hope people who get stuck may find this useful.

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

Sidebar

Related Questions

I'm drawing rectangles on the screen using the basic NSBezierPath method. I have an
I am drawing a sphere using quads. I plot an extra vertex, just to
I'm having some trouble drawing out a sphere. std::vector<GLfloat> ballVerts; for(int i = 0;
Drawing bifurcation diagram for 1D system is clear but if I have 2D system
I'm drawing as scrollable graph using a custom extension of CALayer with a bunch
I am drawing line using bezier curve and i need to convert that bezier
When drawing a vertex skinned model, what is the maximum number of bones per
I am doing a Drawing App. I have saved the color fill image as
I'm drawing an image to a canvas (using the cityTexture method in http://haldean.github.com/citycanvas/city.js )
When drawing an editable Polygon on a map using Google's V3 API, is there

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.