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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:49:07+00:00 2026-05-26T00:49:07+00:00

New to OpenGL, trying to implement a sphere with shading and lighting. I am

  • 0

New to OpenGL, trying to implement a sphere with shading and lighting. I am aware that there is a sphere function I could call on, but trying to create my own. However, while I can get lighting and shading on other objects in the scene (such as glcubes, etc.), I am unable to get any shading or lighting on the sphere. Any suggestions would be greatly appreciated!

Bellow is my function to draw the sphere:

void cg_SolidSphere( GLint slices, GLint stacks )
{
    float x, y, z ;
    for( float lat = 0 ; lat < PI ; lat = lat + PI/stacks )
    {
        glBegin( GL_QUAD_STRIP ) ;
        for( float lon = 0 ; lon < 2*PI ; lon = lon + 2*PI/slices )
        {
            x = cosf( lat ) * sinf( lon ) ;
            y = sinf( lat ) * sinf( lon ) ;
            z = cosf( lon ) ;
            glVertex3f( x, y, z ) ;
            x = cosf( lat + PI/stacks ) * sinf( lon ) ;
            y = sinf( lat + PI/stacks ) * sinf( lon ) ;
            z = cosf( lon ) ;
            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-05-26T00:49:08+00:00Added an answer on May 26, 2026 at 12:49 am

    You need glNormal3f calls, too. In this case, the normal is the same as the vertex, so we can use the same points:

    x = cosf( lat ) * sinf( lon ) ;
    y = sinf( lat ) * sinf( lon ) ;
    z = cosf( lon ) ;
    glNormal3f( x, y, z ) ;
    glVertex3f( x, y, z ) ;
    x = cosf( lat + PI/stacks ) * sinf( lon ) ;
    y = sinf( lat + PI/stacks ) * sinf( lon ) ;
    z = cosf( lon ) ;
    glNormal3f( x, y, z ) ;
    glVertex3f( x, y, z ) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to OpenGL and was trying to create a simple maze that
I'm new to OpenGl ES. I'm trying to build a sphere not using any
I'm new to OpenCL and I'm trying to implement a simple function in OpenCL.
i am new to opengl es 2.0 on ios, i am trying to create
Rather new to trying to get OpenGL ES working on the iPhone, but I've
Okay so I'm kind of new with OpenGL, but I thought I should learn
I've been programming OpenGL for some time now but I'm quite new to OpenGL
I am trying to create a simple 3-D app for android that will have
I'm trying to implement a point cloud with OpenGL and CUDA, where the radii
I am trying to implement a game using opengl in qt4. So far I

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.