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 > Looking into the light

#108400 - Rajveer - Wed Nov 08, 2006 3:03 pm

Hi guys. I've added light to my game, but whenever I position the camera in a way that it looks towards the light everything goes darker (even the models I'm not using light on). Is this normal or have I screwed around with something? :S

#108443 - Payk - Wed Nov 08, 2006 9:18 pm

Maybe some code helps to understand...
code from cam, lights, and renderscenes...
But indeed a strange thing

#108454 - Rajveer - Wed Nov 08, 2006 11:56 pm

Ok, I'm still fairly new to coding in general and especially with the DS so dont laugh at any newb mistakes! ;)

FIRST
Code:
   while(1)
   {
      glReset();

      glMatrixMode(GL_TEXTURE);
      glIdentity();
      glPushMatrix();
      
      glMaterialf(GL_AMBIENT, RGB15(20,20,20));
      glMaterialf(GL_DIFFUSE, RGB15(31,31,31));
//      glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
//      glMaterialf(GL_EMISSION, RGB15(5,5,5));
      
//      glMaterialShinyness();
      
      glEnable(GL_ANTIALIAS);      
      DrawGLScene();
      
      glPopMatrix(1);
      swiWaitForVBlank();
      glFlush();
      
   }
   
   return 0;


SECOND
Code:
   if(currentCamera == 0)
   {
      camerapos[0] = player[1].transmatrix[12] - mulf32(20480,player[1].transmatrix[8]) + mulf32(12288,player[1].transmatrix[4]);
      camerapos[1] = player[1].transmatrix[13] - mulf32(20480,player[1].transmatrix[9]) + mulf32(12288,player[1].transmatrix[5]);
      camerapos[2] = player[1].transmatrix[14] - mulf32(20480,player[1].transmatrix[10]) + mulf32(12288,player[1].transmatrix[6]);

      cameralook[0] = player[1].transmatrix[12] + mulf32(5000,player[1].transmatrix[4]);
      cameralook[1] = player[1].transmatrix[13] + mulf32(5000,player[1].transmatrix[5]);
      cameralook[2] = player[1].transmatrix[14] + mulf32(5000,player[1].transmatrix[6]);

      cameraup[0] = player[1].transmatrix[4];
      cameraup[1] = player[1].transmatrix[5];
      cameraup[2] = player[1].transmatrix[6];
   }
   else if(currentCamera == 1)
   {
      camerapos[0] = player[0].transmatrix[12] - mulf32(20480,player[0].transmatrix[8]) + mulf32(12288,player[0].transmatrix[4]);
      camerapos[1] = player[0].transmatrix[13] - mulf32(20480,player[0].transmatrix[9]) + mulf32(12288,player[0].transmatrix[5]);
      camerapos[2] = player[0].transmatrix[14] - mulf32(20480,player[0].transmatrix[10]) + mulf32(12288,player[0].transmatrix[6]);

      cameralook[0] = player[0].transmatrix[12] + mulf32(5000,player[0].transmatrix[4]);
      cameralook[1] = player[0].transmatrix[13] + mulf32(5000,player[0].transmatrix[5]);
      cameralook[2] = player[0].transmatrix[14] + mulf32(5000,player[0].transmatrix[6]);

      cameraup[0] = player[0].transmatrix[4];
      cameraup[1] = player[0].transmatrix[5];
      cameraup[2] = player[0].transmatrix[6];
   }
   
/* SET THE SCENE AND THE CAMERA-----------------------------------------*/
//   glOrtho(-40,40,-30,30,0.1,10000);
   gluPerspective(38, 256.0 / 192.0, 0.1, 2000);
   glMatrixMode(GL_MODELVIEW);
   glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
   
   glLoadIdentity();
   gluLookAtf32(camerapos[0], camerapos[1], camerapos[2],cameralook[0],cameralook[1],cameralook[2],cameraup[0],cameraup[1],cameraup[2]);
   glLight(0, RGB15(31,31,31) , 0, floattov10(1), 0);

/* DRAW THE SKYBOX------------------------------------------------------*/
   glPushMatrix();
   
   glTranslate3f32(camerapos[0],camerapos[1],camerapos[2]);
   glScalef(90,90,90);
   DrawSkybox();
   glPopMatrix(1);
   
/* DRAW THE LEVEL------------------------------------------------------*/
   glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0);
   glPushMatrix();

   glScalef(LevelScale,LevelScale,LevelScale);
   DrawLevel1();
   glPopMatrix(1);
      
   glPushMatrix();
   
   glTranslate3f32(Waypoint1[player[1].currentWaypoint].x, Waypoint1[player[1].currentWaypoint].y, Waypoint1[player[1].currentWaypoint].z);
   DrawSkybox();
   glPopMatrix(1);

/* DRAW THE COMPUTER SHIP-----------------------------------------------*/
   glPushMatrix();

   glMultMatrix4x4((m4x4 *)&player[1].transmatrix[0]);
   glBindTexture(GL_TEXTURE_2D, shiptextures[0]);
   Draw3DS(0);
   glBindTexture(0, 0);
   glPopMatrix(1);

/* DRAW THE PLAYER SHIP------------------------------------------------------*/
   glPushMatrix();

   glMultMatrix4x4((m4x4 *)&player[0].transmatrix[0]);
   glRotatef32i(player[0].tilt,0,0,4096);
   glBindTexture(GL_TEXTURE_2D, shiptextures[0]);
   Draw3DS(0);
   glBindTexture(0, 0);
   glPopMatrix(1);


P.S. whats a renderscene?

#108461 - Payk - Thu Nov 09, 2006 2:14 am

First of all: i dont laugh....i used float all the time and hat about 10FPS before knowing about fixed point...pppl may laught about me some months ago...Thats why i told you that :D
The other thing is that i meaned with the renderscene part...there where u call the normal and vertex functions. Maybe its wrong name for that :D
Not sure....english isnt may mother language (as u maybe able to read ;) )
...
Hmh i dont find the bug ...sorry. But i can see that your arent a n00p at all.Your new to ds, well, but not new to opengl, right?
(its late...will watch that tomorow again)

#108509 - Rajveer - Thu Nov 09, 2006 6:49 pm

Lol so did I until I realised that the DS cant do float, then I learnt about fixed :-D

Damn I'm not sure whats wrong with the code, it's a really weird thing thats going on. Cheers for helping anyways Payk :)

P.S. I'm still a noob, the only other times I've coded are java/pascal in uni and visual basic at college, been teaching myself c and opengl over the summer and been programming on the ds as my first project. It's going well, I've learnt a hell of alot!