Advertisement

URGENT! lights with textures

Started by June 20, 2003 06:18 AM
4 comments, last by ludo 21 years, 8 months ago
Hello everybody I'm creating a solar system. All work except one thing : the light: I don't succeed to put a light in my solar system. I use gluQuadric to put a texture on my spheres and I don't understand why there aren't lights whereas I put it in my code... And it's urgent, it's the only one thing that doesn't work and I have to send my project on Monday Here a part of my code :

int LightPos[4] = {1,20,20,0};
int MatSpec [4] = {1,1,1,1};

....

void init(void){
  GLfloat couleurAP[]={0.5,0.5,0.5,1.0}; /* couleur de fond */

  // Paramètres d'eclairage /

  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,L0dif);
  glLightfv(GL_LIGHT0,GL_SPECULAR,L0dif);
  glLightfv(GL_LIGHT1,GL_DIFFUSE,L1dif);
  glLightfv(GL_LIGHT1,GL_SPECULAR,L1dif);
  glEnable(GL_LIGHTING);
*/

...
  glShadeModel (GL_SMOOTH);

  glEnable(GL_LIGHTING);
  glEnable(GL_DEPTH_TEST);

  glGenTextures(20,texName); 

  creation_texture("textures/terre.jpg",texture_terre);
 glTexImage2D(GL_TEXTURE_2D,0,3,
               LI,LH,0,GL_RGB,
               GL_UNSIGNED_BYTE,
               &texture_terre);
 
   creation_texture("textures/lune.jpg",texture_lune);
glTexImage2D(GL_TEXTURE_2D,0,3,
               LI,LH,0,GL_RGB,
               GL_UNSIGNED_BYTE,
               &texture_lune );
...
glEnable(GL_TEXTURE_2D);

}

//----------------------------------------------------

void display(void)
{

GLUquadricObj * qobj;
int i;
qobj = gluNewQuadric();


glMaterialiv(GL_FRONT_AND_BACK,GL_SPECULAR,MatSpec); 
glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,100); 


glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();


gluLookAt (0.0, hauteur, distance, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

glRotatef(xvu,yvu,1.0,0.0);


glLightiv(GL_LIGHT0,GL_POSITION,LightPos);
//


....

//-----Soleil--------------- 

glBindTexture(GL_TEXTURE_2D,texName[10]);

glPushMatrix();

gluQuadricDrawStyle(qobj,GLU_FILL); //soleil avec une equation quadrique

gluQuadricNormals(qobj,GLU_SMOOTH);
gluQuadricTexture(qobj,GL_TRUE);
gluSphere(qobj,1.0,20.0,20.0);
glPopMatrix();

glPopMatrix();


//--------Terre-------

glBindTexture(GL_TEXTURE_2D,texName[0]);

glPushMatrix();

glRotatef (year, 0.0, 1.0, 0.0);
glTranslatef (6.0, 0.0, 0.0);
glRotatef (-year, 0.0, 1.0, 0.0);
glRotatef (year*3, 0.3907, 0.92705, 0.0);

gluQuadricDrawStyle(qobj,GLU_FILL);
gluQuadricNormals(qobj,GLU_SMOOTH);
gluQuadricTexture(qobj,GL_TRUE);
gluSphere(qobj,0.2,10.0,8.0);

glPopMatrix();
....
glutPostRedisplay();

glutSwapBuffers();
}


/*-----------------------------------------------------------------------*/

void reshape (int w, int h)
{
  glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 400.0);
  glMatrixMode(GL_MODELVIEW);
  ;
}


/*----------------------------------------------------------------------*/

int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize (800, 800);
  glutInitWindowPosition (100, 100);
  glutCreateWindow ("Système solaire");
  init ();
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);

  glutMouseFunc(souris);
  glutMotionFunc(mouvSouris);

  glutMainLoop();
  return 0;
}

Thank you for your patience Ludo [edited by - ludo on June 20, 2003 9:39:10 AM]
Not 100% sure about this but I have had problems before getting textured objects to show light and I think it was because I had the colour of the object behind the texture as black.

I think OpenGL uses this when lighting objects even though the texture is on top.

Try setting the colour to white or grey or something before drawing the objects
Advertisement
So urgent in fact that you didn''t have time to read the FAQ to see how to use source code tags.


Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
Sorry siaspete, i modified that :d.

Thx rickp101, but it doesn''t work, i changed all the colours and it''s the same thing, so i continue to search but right now i have''nt ideas....
Hmm, try setting the last 0 in LightPos to 1. I''m presuming you want the light to be a positional light and not a directional light (although that could be wrong). I''m not utterly positive that will fix it either.
sorry if this doesnt help but you could try glEnable(GL_COLOR_MATERIAL)...

www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org

This topic is closed to new replies.

Advertisement