Jump to content
  • Advertisement
Sign in to follow this  
voldemort62442

Lighting trouble

This topic is 3723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to make a lit sphere with two wire spheres rotating around it however every time i turn off the lit sphere to color the two wire sphere the lit sphere suddenly turns to a solid color instead of keeping its lit up form. and the spheres around it seem to revolve around it oddly.
[source lang="cpp
#include<windows.h>
#include<GL/gl.h>
#include<GL/glut.h>

float idle=0.0;

void init(void)
{
	GLfloat light_position0[]= {0.0, 0.0, 0.0, 1.0};
	GLfloat mat_emissive[]= {1.0, 1.0, 1.0, 1.0};
    GLfloat mat_specular[]= {1.0, 1.0, 0.0, 1.0};
    GLfloat mat_shininess[]= {10.0};

	GLfloat white_light[]= {1.0, 1.0, 1.0, 1.0};
	GLfloat red_light[]= {1.0, 0.0, 0.0, 1.0};
	GLfloat orange_light[]={1.0,0.5, 0.0, 1.0};
	GLfloat yellow_light[]={1.0, 1.0, 0.0, 1.0};
	GLfloat green_light[]= {0.0, 1.0, 0.0, 1.0};
	GLfloat blue_light[]= {0.0, 0.0, 1.0, 0.0};
	GLfloat violet_light[]={0.5, 0.0, 1.0, 1.0};

	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);

	glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, yellow_light);
	glLightfv(GL_LIGHT0, GL_SPECULAR, yellow_light);
	glLightfv(GL_LIGHT0, GL_EMISSION, yellow_light);

	glShadeModel(GL_SMOOTH);
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHT0);
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
	glEnable(GL_LIGHT0);
	glutSolidSphere(1.5,1000,1000);
	glDisable(GL_LIGHTING);
	glutSolidCube(1.2);

        glColor3f(1.0, 0.0, 0.0);
        glTranslatef (1.6, 0.0, 0.0);
        glRotatef(idle, 0.0, 1.0, 0.0);
        glutWireSphere(0.1, 1000, 1000);

        glColor3f(0.0, 1.0, 0.0);
        glTranslatef (1.8, 0.0, 0.0);
        glRotatef(idle, 0.0, 1.0, 0.0);
        glutWireSphere(0.1, 1000, 1000);

    glPopMatrix();
    idle+=.5;
    glutSwapBuffers();
}

void reshape(int w, int h)
{
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
    glLoadIdentity ();
	gluPerspective(45.0, (GLfloat)w/(GLfloat)h, 0.1, 100.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
}

void keyboard (unsigned char key, int x, int y){
  switch (key) {
    case 27:
      exit (0);
      break;
    default:
      break;
  }
}

int main (int argc, char** argv)
{
    glutInit( &argc, argv );
    glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE );
  	glutCreateWindow ( "3D Programming 2" );
    glutFullScreen ();

    init();
    glutIdleFunc(display);
    glutDisplayFunc (display);
    glutReshapeFunc (reshape);
    glutKeyboardFunc (keyboard);
    glutMainLoop ();
}

Help would be appreciated [Edited by - voldemort62442 on September 24, 2008 11:38:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!