shithub: tinygl

Download patch

ref: a2f16757fd2ba90a2717cfc1a1f8dedc7efab964
parent: c61f11f50db4b0fce0b6a63cddb15eb26efc5eee
author: David <gek@katherine>
date: Sun Feb 14 13:52:18 EST 2021

Bug fix: Normalized Position for lights at infinity

--- a/README.md
+++ b/README.md
@@ -112,7 +112,9 @@
 
 * Little endian was assumed in a thousand places in the code
 
-* 
+* Non-normalized position was used for lights at infinity.
+
+* Insert unknown bugs here.
 
 
   
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -219,7 +219,8 @@
 
 
 void initScene() {
-    static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 };
+    //static GLfloat pos[4] = {0.408248290463863, 0.408248290463863, 0.816496580927726, 0.0 }; //Light at infinity.
+    static GLfloat pos[4] = {5, 5, 10, 0.0 }; //Light at infinity.
     
     static GLfloat red[4] = {1.0, 0.0, 0.0, 0.0 };
     static GLfloat green[4] = {0.0, 1.0, 0.0, 0.0 };
@@ -263,7 +264,7 @@
     //glColor3fv(blue);
     gear( 1.3, 2.0, 0.5, 10, 0.7 ); //The small gear above with the large hole.
     glEndList();
-    glEnable( GL_NORMALIZE );
+    //glEnable( GL_NORMALIZE );
 }
 
 int main(int argc, char **argv) {
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -390,6 +390,7 @@
 	//tex = 
 	}
 	glDisable(GL_LIGHTING);
+	//glEnable( GL_NORMALIZE );
     // variables for timing:
     unsigned int frames=0;
     unsigned int tNow=SDL_GetTicks();
--- a/src/clip.c
+++ b/src/clip.c
@@ -23,33 +23,19 @@
   v->zp.z= (int) ( v->pc.Z * winv * c->viewport.scale.Z 
                    + c->viewport.trans.Z );
   /* color */
-  if (c->lighting_enabled) {
+  //if (c->lighting_enabled) {
   	
       v->zp.r=(unsigned int)(v->color.v[0] * 65535) & 65535;
       v->zp.g=(unsigned int)(v->color.v[1] * 65535) & 65535;
       v->zp.b=(unsigned int)(v->color.v[2] * 65535) & 65535;
-  } else {
-      /* no need to convert to integer if no lighting : take current color */
-      /* OLD CODE
-      v->zp_r = c->longcurrent_color[0]; //MARKED, NOT USED
-      v->zp.g = c->longcurrent_color[1]; //MARKED, NOT USED
-      v->zp.b = c->longcurrent_color[2]; //MARKED, NOT USED
 
-      */
-      /*
-      v->zp_r=(int)(v->color.v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) 
-                          + ZB_POINT_RED_MIN);
-      v->zp.g=(int)(v->color.v[1] * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) 
-                    + ZB_POINT_GREEN_MIN);
-      v->zp.b=(int)(v->color.v[2] * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) 
-                    + ZB_POINT_BLUE_MIN);
-      */
+  //} else {
       //printf("\nRECEIVED COLOR %f, %f, %f, %f", v->color.v[0], v->color.v[1], v->color.v[2], v->color.v[3]);
-      v->zp.r=(unsigned int)(v->color.v[0] * 65535) & 65535;
-      v->zp.g=(unsigned int)(v->color.v[1] * 65535) & 65535;
-      v->zp.b=(unsigned int)(v->color.v[2] * 65535) & 65535;
+    //  v->zp.r=(unsigned int)(v->color.v[0] * 65535) & 65535;
+    //  v->zp.g=(unsigned int)(v->color.v[1] * 65535) & 65535;
+    //  v->zp.b=(unsigned int)(v->color.v[2] * 65535) & 65535;
       //printf("\nCOLORS ARE %d, %d, %d", v->zp.r,v->zp.g,v->zp.b);
-  }
+ // }
   
   /* texture */
 
--- a/src/init.c
+++ b/src/init.c
@@ -107,9 +107,9 @@
   c->current_color.Z=1.0;
   c->current_color.W=0.0;
   //Shouldn't ever be used.
-  c->longcurrent_color[0] = 65280;
-  c->longcurrent_color[1] = 65280;
-  c->longcurrent_color[2] = 65280;
+  //c->longcurrent_color[0] = 65280;
+  //c->longcurrent_color[1] = 65280;
+  //c->longcurrent_color[2] = 65280;
 
   c->current_normal.X=1.0;
   c->current_normal.Y=0.0;
--- a/src/light.c
+++ b/src/light.c
@@ -116,7 +116,6 @@
         l->norm_position.X=pos.X;
         l->norm_position.Y=pos.Y;
         l->norm_position.Z=pos.Z;
-        
         gl_V3_Norm(&l->norm_position);
       }
     }
@@ -238,9 +237,10 @@
 
     if (l->position.v[3] == 0) {
       /* light at infinity */
-      d.X=l->position.v[0];
-      d.Y=l->position.v[1];
-      d.Z=l->position.v[2];
+      //Fixed by Gek, it used to use the unnormalized position?
+      d.X=l->norm_position.v[0];
+      d.Y=l->norm_position.v[1];
+      d.Z=l->norm_position.v[2];
       att=1;
     } else {
       /* distance attenuation */
@@ -280,6 +280,8 @@
             att=att*pow(dot_spot,l->spot_exponent);
           }
         }
+		//GEK SAYS TO REMOVE THIS
+        //printf("\nThis should not be being called.");
       }
 
       /* specular light */
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -34,20 +34,20 @@
     c->current_color.Y = p[2].f;
     c->current_color.Z = p[3].f;
     c->current_color.W = p[4].f;
-    c->longcurrent_color[0] = p[5].ui; //MARKED
-    c->longcurrent_color[1] = p[6].ui; //MARKED
-    c->longcurrent_color[2] = p[7].ui; //MARKED
+    //c->longcurrent_color[0] = p[5].ui; //MARKED
+    //c->longcurrent_color[1] = p[6].ui; //MARKED
+    //c->longcurrent_color[2] = p[7].ui; //MARKED
 
     if (c->color_material_enabled) {
-	GLParam q[7];
-	q[0].op = OP_Material;
-	q[1].i = c->current_color_material_mode;
-	q[2].i = c->current_color_material_type;
-	q[3].f = p[1].f;
-	q[4].f = p[2].f;
-	q[5].f = p[3].f;
-	q[6].f = p[4].f;
-	glopMaterial(c, q);
+		GLParam q[7];
+		q[0].op = OP_Material;
+		q[1].i = c->current_color_material_mode;
+		q[2].i = c->current_color_material_type;
+		q[3].f = p[1].f;
+		q[4].f = p[2].f;
+		q[5].f = p[3].f;
+		q[6].f = p[4].f;
+		glopMaterial(c, q);
     }
 }
 
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -232,7 +232,7 @@
 
   /* current vertex state */
   V4 current_color;
-  unsigned int longcurrent_color[3]; /* precomputed integer color */
+  //unsigned int longcurrent_color[3]; /* precomputed integer color */
   V4 current_normal;
   V4 current_tex_coord;
   int current_edge_flag;