gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Problem with lights

#126262 - trabis - Sat Apr 21, 2007 11:49 am

Hello, i want a simple code with a 3d cube and changing color light but something is wrong. I`ve modified the lesson06 from nehe libnds examples. That?s the loop code:

Code:


   while (1)
   {
      // Reset the screen and setup the view
      glReset();
      gluPerspective(35, 256.0 / 192.0, 0.1, 100);
      glColor3f(1,1,1);
      
      glLight(0, RGB15(r,g,b) , 0,              floattov10(-1.0),       0);
      glLight(1, RGB15(r,g,b) , 0,              0,   floattov10(-1.0));
      glLight(2, RGB15(r,g,b) , 0,              0,   floattov10(1.0));

      glMatrixMode(GL_TEXTURE);
      glIdentity();
      
      glMatrixMode(GL_MODELVIEW);

      //need to set up some material properties since DS does not have them set by default
      glMaterialf(GL_AMBIENT, RGB15(16,16,16));
      glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
      glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
      glMaterialf(GL_EMISSION, RGB15(16,16,16));

      //ds uses a table for shinyness..this generates a half-ass one
      glMaterialShinyness();
      
      // Set the current matrix to be the model matrix
      glMatrixMode(GL_MODELVIEW);
      
      //Push our original Matrix onto the stack (save state)
      glPushMatrix();   

      //ds specific, several attributes can be set here   
      glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE  | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2);
      
      DrawGLScene();
      
      // Pop our Matrix from the stack (restore state)
      glPopMatrix(1);

      // flush to screen   
      glFlush();
      
      r=(r+1)%32;
      g=(g+1)%32;
      b=(b+1)%32;
   
   }


Why don`t I feel any difference? Can anyone help me?

Thanks

#126300 - 3D_geek - Sun Apr 22, 2007 12:57 am

trabis wrote:

Code:

      glLight(0, RGB15(r,g,b) , 0,              floattov10(-1.0),       0);
      glLight(1, RGB15(r,g,b) , 0,              0,   floattov10(-1.0));
      glLight(2, RGB15(r,g,b) , 0,              0,   floattov10(1.0));



One problem that's immediately obvious is that you are overflowing the coordinates you pass to your light sources. The coordinates must fit in 10 bits after floattov10 - and the number +1 doesn't. Try values like 0.9 instead of 1.0.

#126331 - trabis - Sun Apr 22, 2007 11:33 am

I`ve just try it but nothing changes. Thanks for your idea.

Any other solution?