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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:46:15+00:00 2026-05-27T04:46:15+00:00

I am trying to develop space simulator. I am trying to use sun as

  • 0

I am trying to develop space simulator. I am trying to use sun as the light source. My problem is that the lighting dosent work as expected. Maybe i am using the wrong calculation for the normals. I am using a single “createsphere” function to create a sphere, and then use different coordinates and sizes to display them. The problem is that all the spheres on the screen show almost the same effect(i.e i’ve applied only one light source but it seems to have been implemented to all the spheres) .and also the light rotates along with them. I am not sure where the problem is …i am posting my code …

the code for sphere display

void DisplaySphere_sun (double R, GLuint texture)
{

 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

int b,m = 0;
glScalef (0.0125 * R, 0.0125 * R, 0.0125 * R);
glBindTexture (GL_TEXTURE_2D, texture);
glBegin (GL_TRIANGLE_STRIP);


for ( b = 0; b <VertexCount; b++)
{
    /*if((b%3)==0)
    {
        glNormal3f(normal[m].x,normal[m].y,normal[m].z);
        m++;
    }*/

    glTexCoord2f (VERTEX[b].U, VERTEX[b].V);
    /*glNormal3f(-VERTEX[b].X, -VERTEX[b].Y, -VERTEX[b].Z);*/
    glVertex3f (VERTEX[b].Y, VERTEX[b].X, -VERTEX[b].Z);
}

m = 0;

for ( b = 0; b <VertexCount; b++)
{
    /*if((b%3)==0)
    {
        glNormal3f(normal[m].x,normal[m].y,normal[m].z);
        m++;
    }*/

    glTexCoord2f (VERTEX[b].U, -VERTEX[b].V);
/*  glNormal3f(-VERTEX[b].X, -VERTEX[b].Y, -VERTEX[b].Z);*/
    glVertex3f (VERTEX[b].Y, VERTEX[b].X, VERTEX[b].Z);
}


glEnd();
//glRotatef(120,0,0,0);

}

the code for creating a sphere

void CreateSphere (double R, double X, double Y, double Z) {
int n,m;
double a;
double b;
n = 0;
m = 0;


for( b = 0; b <= 90 - space; b+=space){

for( a = 0; a <= 360 - space; a+=space)
{
    VERTEX[n].X = R * sin((a) / 180 * PI) * sin((b) / 180 * PI) - X;
    VERTEX[n].Y = R * cos((a) / 180 * PI) * sin((b) / 180 * PI) + Y;
    VERTEX[n].Z = R * cos((b) / 180 * PI) - Z;
    VERTEX[n].V = (2 * b) / 360;
    VERTEX[n].U = (a) / 360;

    n++;
    VERTEX[n].X = R * sin((a) / 180 * PI) * sin((b + space) / 180 * PI) - X;
    VERTEX[n].Y = R * cos((a) / 180 * PI) * sin((b + space) / 180 * PI) + Y;
    VERTEX[n].Z = R * cos((b + space) / 180 * PI) - Z;
    VERTEX[n].V = (2 * (b + space)) / 360;
    VERTEX[n].U = (a) / 360;

    n++;
    VERTEX[n].X = R * sin((a + space) / 180 * PI) * sin((b) / 180 * PI) - X;
    VERTEX[n].Y = R * cos((a + space) / 180 * PI) * sin((b) / 180 * PI) + Y;
    VERTEX[n].Z = R * cos((b) / 180 * PI) - Z;
    VERTEX[n].V = (2 * b) / 360;
    VERTEX[n].U = (a + space) / 360;
    n++;


    VERTEX[n].X = R * sin((a + space) / 180 * PI) * sin((b + space) /180 * PI) - X;
    VERTEX[n].Y = R * cos((a + space) / 180 * PI) * sin((b + space) /180 * PI) + Y;
    VERTEX[n].Z = R * cos((b + space) / 180 * PI) - Z;
    VERTEX[n].V = (2 * (b + space)) / 360;
    VERTEX[n].U = (a + space) / 360;
n++;
}

}
}

and code for lighting the sun

glPushMatrix();

 gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); //defines a viewing transformation.

 // Now translate to the sun 

  glTranslatef(0.0, -7.0, 3.0);

  /* For LIGHT0 */

 GLfloat lightZeroPosition[] = {0.0f, 0.0f, 0.0f, 1.0f};

 /*GLfloat lightvec[] = {0.5f, 0.2f, 0.0f, 1.0f};*/

 GLfloat lightZeroColor[] = {0.5f, 0.5f, 0.5f, 1.0f};


 GLfloat amb[] = {1, 1, 1, 1};

 GLfloat spec[] = {0.3, 0.3, 0.3, 1};

 glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);

 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

 glLightfv(GL_LIGHT0, GL_SPECULAR, spec);

  glEnable(GL_LIGHT0);

 glRotatef(angle,0,0,1);

 DisplaySphere(5,textures);

// function to display the sun

 glPopMatrix();
  • 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-27T04:46:15+00:00Added an answer on May 27, 2026 at 4:46 am

    I’m a bit puzzled, why you don’t draw the sun at the orign of the solar system? The sun is a star, and stars carry over 95% of their stellar systems mass, so the center of gravity of the whole thing is within the sun for most planets (only Jupiter has so much mass, that it shifts the center of gravity slightly outside the sun’s photosphere radius).

    As for your lighting problem, one normally doesn’t illuminate light sources. Just switch off lighting when drawing the sun. Then when drawing the planets place the light source within the sun. OpenGL is not a global renderer, i.e. after you’ve drawn something, it completely forgets about it, i.e. you won’t get any lighting interactions between the things you draw (means also, no shadows for free).

    This is how I’d draw a solar system (pseudocode):

    draw_solar_system():
        glPushMatrix()
    
        glDisable(GL_LIGHTING)
        draw_origin_sphere(sun_radius)
    
        glEnable(GL_LIGHTING)
        glLightfv(GL_LIGHT0, GL_POSITION, (0., 0., 0., 1.))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, (1., 1., 1., 1.))
        glLightfv(GL_LIGHT0, GL_AMBIENT, (0., 0., 0., 1.))
    
        for p in planets:
            glPushMatrix()
    
            glRotatef(p.orbital_inclination, p.axis_of_orbital_inclination)
            glRotatef(p.orbital_angle, 0., 1., 0.)
            glTranslatef(p.orbit_radius, 1., 0. 0.)
            glRotate(p.axial_of_inclination, p.axis_of_axis_inclination)
            glRotate(p.time_of_day, 0., 1., 0.)
    
            draw_origin_sphere(p.radius)
    
            glPopMatrix()
        glPopMatrix()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop an application that will use getImageData in javascript in Firefox
I'm trying to develop some SharePoint workflows for the company I work for, and
I'm trying to develop a firefox extension that inserts additional HTTP header fields into
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I am trying to develop a mobile app, that registered with a Java program
I'm trying to develop a very simple app that displays like a slideshow of
I'm trying to develop an app that uses opengl on android, and ideally make
I'm trying to develop a web app with Django that would let users to
Im trying to develop an application that should show a map using the Google
I am (trying) to develop a WPF (C#) app that just gets (or at

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.