ref: c58a9a045fd18630b95033f1414a09eaf3544558
parent: 3da29a050385acdcf7e33fc30abbfc654d388f9a
author: David <gek@katherine>
date: Wed Feb 17 08:42:21 EST 2021
Demo update
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -28,7 +28,7 @@
#ifndef M_PI
#define M_PI 3.14159265
#endif
-
+int override_drawmodes = 0;
GLubyte stipplepattern[128] = {0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
@@ -66,7 +66,12 @@
glNormal3f(0.0, 0.0, 1.0);
/* draw front face */
- glBegin(GL_QUAD_STRIP);
+if(override_drawmodes == 1)
+ glBegin(GL_LINES);
+else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+else
+ {glBegin(GL_QUAD_STRIP);}
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
@@ -77,7 +82,12 @@
glEnd();
/* draw front sides of teeth */
- glBegin(GL_QUADS);
+ if(override_drawmodes == 1)
+ glBegin(GL_LINES);
+ else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+ else
+ glBegin(GL_QUADS);
da = 2.0 * M_PI / teeth / 4.0;
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
@@ -92,7 +102,12 @@
glNormal3f(0.0, 0.0, -1.0);
/* draw back face */
- glBegin(GL_QUAD_STRIP);
+ if(override_drawmodes == 1)
+ glBegin(GL_LINES);
+ else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+ else
+ glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
@@ -103,7 +118,12 @@
glEnd();
/* draw back sides of teeth */
- glBegin(GL_QUADS);
+ if(override_drawmodes == 1)
+ glBegin(GL_LINES);
+ else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+ else
+ glBegin(GL_QUADS);
da = 2.0 * M_PI / teeth / 4.0;
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
@@ -116,7 +136,12 @@
glEnd();
/* draw outward faces of teeth */
- glBegin(GL_QUAD_STRIP);
+ if(override_drawmodes == 1)
+ glBegin(GL_LINES);
+ else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+ else
+ glBegin(GL_QUAD_STRIP);
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
@@ -148,7 +173,12 @@
/* draw inside radius cylinder */
- glBegin(GL_QUAD_STRIP);
+ if(override_drawmodes == 1)
+ glBegin(GL_LINES);
+ else if (override_drawmodes == 2)
+ glBegin(GL_POINTS);
+ else
+ glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glNormal3f(-cos(angle), -sin(angle), 0.0);
@@ -263,6 +293,10 @@
blending = 1;
if (!strcmp(argv[i],"-nospecular"))
setenspec = 0;
+ if (!strcmp(argv[i],"-lines"))
+ override_drawmodes = 1;
+ if (!strcmp(argv[i],"-points"))
+ override_drawmodes = 2;
larg = argv[i];
}
}
--- a/include/GL/gl.h
+++ b/include/GL/gl.h
@@ -858,6 +858,9 @@
void glBlendFunc(GLint, GLint);
void glBlendEquation(GLenum mode);
void glDepthMask(GLint);
+
+/* Point Size */
+void glPointSize(GLfloat);
/* not implemented, just added to compile */
/*
inline void glPointSize(GLfloat) {}
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -219,6 +219,8 @@
/* depth */
GLint depth_test;
GLint depth_write;
+ /* point size*/
+ GLfloat pointsize;
GLint nb_colors;
unsigned char *dctable;
--- a/src/misc.c
+++ b/src/misc.c
@@ -7,9 +7,10 @@
GLContext* c = gl_get_context();
ZBuffer* zb = c->zb;
- for (GLint i = 0; i < TGL_POLYGON_STIPPLE_BYTES; i++) {
- zb->stipplepattern[i] = b[i];
- }
+ memcpy(zb->stipplepattern, a, TGL_POLYGON_STIPPLE_BYTES);
+// for (GLint i = 0; i < TGL_POLYGON_STIPPLE_BYTES; i++) {
+// zb->stipplepattern[i] = b[i];
+// }
#endif
}
@@ -59,6 +60,8 @@
c->zb->sfactor = p[1].i;
c->zb->dfactor = p[2].i;
}
+
+
void glBlendEquation(GLenum mode) {
GLParam p[2];
p[0].op = OP_BlendEquation;
@@ -66,6 +69,16 @@
gl_add_op(p);
}
void glopBlendEquation(GLContext* c, GLParam* p) { c->zb->blendeq = p[1].i; }
+
+void glopPointSize(GLContext* c, GLParam* p){
+ c->zb->pointsize = p[1].f;
+}
+void glPointSize(GLfloat f){
+ GLParam p[2]; p[0].op = OP_PointSize;
+ p[1].f = f;
+ gl_add_op(p);
+}
+
void glopEnableDisable(GLContext* c, GLParam* p) {
GLint code = p[1].i;
GLint v = p[2].i;
--- a/src/opinfo.h
+++ b/src/opinfo.h
@@ -71,8 +71,13 @@
/* blending */
ADD_OP(BlendEquation, 1, "%d")
ADD_OP(BlendFunc, 2, "%d %d")
+
+/* point size */
+ADD_OP(PointSize, 1, "%f")
+
/* Gek's Added Functions */
ADD_OP(PlotPixel, 2, "%d %d")
ADD_OP(TextSize, 1, "%d")
+
#undef ADD_OP
--- a/src/zline.c
+++ b/src/zline.c
@@ -3,7 +3,7 @@
#define ZCMP(z, zpix) (!(zbdt) || z >= (zpix))
-/* TODO: Implement blending for lines.*/
+/* TODO: Implement point size */
void ZB_plot(ZBuffer* zb, ZBufferPoint* p) {
GLushort* pz;