shithub: tinygl

Download patch

ref: 78cda0b8ca678b6db1c89beee06069d784c63f29
parent: 005a5734a28e9bd767a55d7c919b0639e80807ab
author: David <gek@katherine>
date: Fri Feb 12 16:57:18 EST 2021

A

--- a/README.md
+++ b/README.md
@@ -1,6 +1,16 @@
 # TinyGL- New and Improved
+
+Without Polygon Stipple:
+
 ![GIF Video of demo](capture.gif)
+
+With Polygon Stipple:
+
 ![GIF Video of demo](capture2.gif)
+
+Texturing Test: 
+
+![Screenshot of Texture test](texture_test.png)
 
 TinyGL 0.6 (c) 1997-2021 Fabrice Bellard, C-Chads, Gek (see License, it's free software)
 
binary files a/capture2.gif b/capture2.gif differ
--- a/src/SDL_Examples/gears.c
+++ b/src/SDL_Examples/gears.c
@@ -21,6 +21,45 @@
 #endif
 
 
+
+GLubyte stipplepattern[128] = {
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA,
+	0xAA,0xAA,0xAA,0xAA,
+	~0xAA,~0xAA,~0xAA,~0xAA
+};
+
 /*
  * Draw a gear wheel.  You'll probably want to call this function when
  * building a display list since we do a lot of trig here.
@@ -197,6 +236,11 @@
     glEnable( GL_LIGHT0 );
     glEnable( GL_DEPTH_TEST );
     glShadeModel( GL_SMOOTH );
+
+    glEnable(GL_POLYGON_STIPPLE);
+    glPolygonStipple(stipplepattern);
+
+    
 	glTextSize(GL_TEXT_SIZE24x24);
     /* make the gears */
     gear1 = glGenLists(1);
--- a/src/api.c
+++ b/src/api.c
@@ -639,6 +639,7 @@
   p[0].op = OP_PolygonOffset;
   p[1].f = factor;
   p[2].f = units;
+  gl_add_op(p);
 }
 
 /* Special Functions */
--- a/src/arrays.c
+++ b/src/arrays.c
@@ -183,6 +183,7 @@
   p[0].op = OP_NormalPointer;
   p[1].i = stride;
   p[2].p = (void*)pointer;
+  gl_add_op(p);
 }
 
 void
@@ -203,4 +204,5 @@
   p[1].i = size;
   p[2].i = stride;
   p[3].p = (void*)pointer;
+  gl_add_op(p);
 }
--- a/src/light.c
+++ b/src/light.c
@@ -298,7 +298,7 @@
 	        s.Y=d.Y;
 	        s.Z=d.Z+1.0;
 	      }
-	      dot_spec=n.X*s.X+n.Y*s.Y+n.Z*s.Z;
+	      dot_spec=n.X*s.X + n.Y*s.Y + n.Z*s.Z;
 	      if (twoside && dot_spec < 0) dot_spec = -dot_spec;
 	      if (dot_spec>0) {
 	        GLSpecBuf *specbuf;
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -7,8 +7,8 @@
 #if TGL_FEATURE_RENDER_BITS == 32
 
 
-#define THE_X (((unsigned short)(pp-pp1)))
 
+
 #else
 
 #error "USE 32 BIT MODE!!!"
@@ -16,15 +16,24 @@
 #endif
 
 
+
+#if TGL_FEATURE_POLYGON_STIPPLE
+
+#define THE_X (((unsigned short)(pp-pp1)))
 #define XSTIP(_a) ((THE_X+_a)& 31)
 #define YSTIP (the_y & 31)
 #define STIPBIT(_a) (zb->stipplepattern[(XSTIP(_a) + (YSTIP<<5))>>3] & (1<<(XSTIP(_a) & 7)))
 #define STIPTEST(_a) !(zb->dostipple && !STIPBIT(_a))
-#if TGL_FEATURE_POLYGON_STIPPLE
 #define ZCMP(z,zpix,_a) ((z) >= (zpix) && STIPTEST(_a))
+
 #else
+
 #define ZCMP(z,zpix,_a) ((z) >= (zpix))
+
 #endif
+
+
+
 void ZB_fillTriangleFlat(ZBuffer *zb,
 			 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
 {
--- a/src/ztriangle.h
+++ b/src/ztriangle.h
@@ -10,8 +10,9 @@
   int part,update_left,update_right;
 
   int nb_lines,dx1,dy1,tmp,dx2,dy2;
+#if TGL_FEATURE_POLYGON_STIPPLE
   unsigned short the_y;
-
+#endif
   int error,derror;
   int x1,dxdy_min,dxdy_max;
 /* warning: x2 is multiplied by 2^16 */
@@ -134,7 +135,9 @@
   /* screen coordinates */
 
   pp1 = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p0->y); 
+  #if TGL_FEATURE_POLYGON_STIPPLE
   the_y = p0->y;
+  #endif
   pz1 = zb->zbuf + p0->y * zb->xsize;
 
   DRAW_INIT();
@@ -300,7 +303,8 @@
               pp=(PIXEL *)((char *)pp + PSZB);
               n-=1;
           }
-      }//the_y++;
+      }
+      //the_y++;
 #else
       DRAW_LINE();//the_y++;
 #endif
@@ -351,7 +355,9 @@
 
       /* screen coordinates */
       pp1=(PIXEL *)((char *)pp1 + zb->linesize);
+#if TGL_FEATURE_POLYGON_STIPPLE
       the_y++;
+#endif
       pz1+=zb->xsize;
     }
   }
binary files /dev/null b/texture_test.png differ