ref: a271c0d5cf1ae8781ae8d35179da9ea56359d7d5
parent: 89828b91c3a6ea35c63c9b43fc064d0954c2ce5c
author: David <gek@katherine>
date: Wed Feb 17 12:34:23 EST 2021
Bug fix in polygon stipple, bad variable assignment
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -240,6 +240,7 @@
glEnable(GL_POLYGON_STIPPLE);
+// glDisable(GL_POLYGON_STIPPLE);
glPolygonStipple(stipplepattern);
glTextSize(GL_TEXT_SIZE24x24);
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -355,7 +355,7 @@
double t = 0;
glViewport(0, 0, winSizeX, winSizeY);
// glEnable(GL_POLYGON_STIPPLE);
- // glPolygonStipple(stipplepattern);
+ glPolygonStipple(stipplepattern);
// initScene();
{
objraw omodel;
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -227,12 +227,9 @@
GLint *ctable;
PIXEL *current_texture;
/* opengl polygon stipple*/
- GLint dostipple;
+ GLuint dostipple;
#if TGL_FEATURE_POLYGON_STIPPLE == 1
- unsigned char stipplepattern[TGL_POLYGON_STIPPLE_BYTES];
-
- /* opengl blending */
-
+ GLubyte stipplepattern[TGL_POLYGON_STIPPLE_BYTES];
#endif
GLenum blendeq, sfactor, dfactor;
GLint enable_blend;
@@ -312,5 +309,6 @@
void gl_free(void *p);
void *gl_malloc(GLint size);
void *gl_zalloc(GLint size);
+void gl_memcpy(void* dest, void* src, GLuint size);
#endif /* _tgl_zbuffer_h_ */
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -10,6 +10,7 @@
//NOTE: Polygon Offset does nothing at the moment.
#define TGL_FEATURE_POLYGON_OFFSET 0
#define TGL_FEATURE_POLYGON_STIPPLE 0
+
#define TGL_FEATURE_BLEND 1
//A stipple pattern is 128 bytes in size.
#define TGL_POLYGON_STIPPLE_BYTES 128
--- a/src/memory.c
+++ b/src/memory.c
@@ -4,9 +4,13 @@
#include "zgl.h"
/* modify these functions so that they suit your needs */
-
+#include<string.h>
void gl_free(void* p) { free(p); }
void* gl_malloc(GLint size) { return malloc(size); }
void* gl_zalloc(GLint size) { return calloc(1, size); }
+
+void gl_memcpy(void* dest, void* src, GLuint size){
+ memcpy(dest,src,size);
+}
--- a/src/misc.c
+++ b/src/misc.c
@@ -2,15 +2,14 @@
#include "zgl.h"
void glPolygonStipple(void* a) {
-#if TGL_FEATURE_POLYGON_STIPPLE
- GLubyte* b = a;
+#if TGL_FEATURE_POLYGON_STIPPLE == 1
GLContext* c = gl_get_context();
ZBuffer* zb = c->zb;
- memcpy(zb->stipplepattern, a, TGL_POLYGON_STIPPLE_BYTES);
-// for (GLint i = 0; i < TGL_POLYGON_STIPPLE_BYTES; i++) {
-// zb->stipplepattern[i] = b[i];
-// }
+ gl_memcpy(zb->stipplepattern, a, TGL_POLYGON_STIPPLE_BYTES);
+ for (GLint i = 0; i < TGL_POLYGON_STIPPLE_BYTES; i++) {
+ zb->stipplepattern[i] = ((GLubyte*)a)[i];
+ }
#endif
}
--- a/src/zgl.h
+++ b/src/zgl.h
@@ -7,7 +7,6 @@
#include "zmath.h"
#include <assert.h>
#include <math.h>
-//#include <stdio.h>
#include <stdlib.h>
#ifndef M_PI
#define M_PI 3.14159265358979323
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -2,6 +2,9 @@
#include "msghandling.h"
#include <stdlib.h>
+//#include <stdio.h>
+//#warning STDIO INCLUDE!!!
+
#if TGL_FEATURE_RENDER_BITS == 32
#elif TGL_FEATURE_RENDER_BITS == 16
#else
@@ -8,22 +11,22 @@
#error "WRONG MODE!!!"
#endif
-#if TGL_FEATURE_POLYGON_STIPPLE
+#if TGL_FEATURE_POLYGON_STIPPLE == 1
-#define TGL_STIPPLEVARS GLubyte* zbstipplepattern = zb->stipplepattern; GLubyte zbdostipple = zbdostipple;
+#define TGL_STIPPLEVARS GLubyte* zbstipplepattern = zb->stipplepattern; GLubyte zbdostipple = zb->dostipple;
#define THE_X (((GLushort)(pp - pp1)))
#define XSTIP(_a) ((THE_X + _a) & TGL_POLYGON_STIPPLE_MASK_X)
#define YSTIP (the_y & TGL_POLYGON_STIPPLE_MASK_Y)
// NOTES Divide by 8 to get the byte Get the actual bit
#define STIPBIT(_a) (zbstipplepattern[(XSTIP(_a) | (YSTIP << TGL_POLYGON_STIPPLE_POW2_WIDTH)) >> 3] & (1 << (XSTIP(_a) & 7)))
-#define STIPTEST(_a) !(zbdostipple && !STIPBIT(_a))
+#define STIPTEST(_a) (!(zbdostipple && !STIPBIT(_a)))
#else
#define TGL_STIPPLEVARS /* a comment */
#define STIPTEST(_a) (1)
-//#define ZCMP(z,zpix,_a) ((z) >= (zpix))
+
#endif
#if TGL_FEATURE_NO_DRAW_COLOR == 1
@@ -32,8 +35,8 @@
#define NODRAWTEST(c) (1)
#endif
-#define ZCMP(z, zpix, _a, c) ( ((!zbdt) || (z) >= (zpix)) && STIPTEST(_a) && NODRAWTEST(c))
-#define ZCMPSIMP(z, zpix, _a, c) ( ((!zbdt) || (z) >= (zpix)) && STIPTEST(_a))
+#define ZCMP(z, zpix, _a, c) ( ((!zbdt) || (z >= zpix)) && STIPTEST(_a) && NODRAWTEST(c))
+#define ZCMPSIMP(z, zpix, _a, c) ( ((!zbdt) || (z >= zpix)) && STIPTEST(_a) )
void ZB_fillTriangleFlat(ZBuffer* zb, ZBufferPoint* p0, ZBufferPoint* p1, ZBufferPoint* p2) {
@@ -40,7 +43,7 @@
PIXEL color = RGB_TO_PIXEL(p2->r, p2->g, p2->b); GLubyte zbdw = zb->depth_write; GLubyte zbdt = zb->depth_test;
TGL_BLEND_VARS
TGL_STIPPLEVARS
-
+
#undef INTERP_Z
#undef INTERP_RGB
#undef INTERP_ST
@@ -49,8 +52,7 @@
#define INTERP_Z
//#define INTERP_RGB
-#define DRAW_INIT() \
- { }
+#define DRAW_INIT() { }
#define PUT_PIXEL(_a) \
{ \
@@ -57,7 +59,7 @@
zz = z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMPSIMP(zz, pz[_a], _a, color)) { \
TGL_BLEND_FUNC(color, (pp[_a])) /*pp[_a] = color;*/ \
- if(zbdw)pz[_a] = zz; \
+ if(zbdw)pz[_a] = zz; \
} \
z += dzdx; \
}
@@ -73,11 +75,10 @@
#undef INTERP_RGB
#undef INTERP_ST
#undef INTERP_STZ
-
+// {printf("\nzbdostipple = %d",zbdostipple);} //TODO: remove this after debugging is complete.
#define INTERP_Z
//#define INTERP_RGB
-#define DRAW_INIT() \
- { }
+#define DRAW_INIT() { }
#define PUT_PIXEL(_a) \
{ \
--- a/src/ztriangle.h
+++ b/src/ztriangle.h
@@ -359,6 +359,8 @@
pp1 = (PIXEL*)((GLbyte*)pp1 + zb->linesize);
#if TGL_FEATURE_POLYGON_STIPPLE == 1
the_y++;
+#else
+//#error POLYGONSTIPPLE_TESTING
#endif
pz1 += zb->xsize;
}