ref: c99b80721b808a9475068a8eafde9b7c3cac679e
parent: 3b22d132306702d254538f0cd23907c1d6c666b4
author: David <gek@katherine>
date: Mon Feb 15 13:54:01 EST 2021
Feature and bug fix update
--- a/README.md
+++ b/README.md
@@ -106,11 +106,13 @@
See `include/zfeatures.h`
Standard OpenGL features that you can disable for extra performance or smaller binary size.
+
+Note that Polygon Stipple is OFF by default, to improve performance.
```c
#define TGL_FEATURE_ARRAYS 1
#define TGL_FEATURE_DISPLAYLISTS 1
#define TGL_FEATURE_POLYGON_OFFSET 1
-#define TGL_FEATURE_POLYGON_STIPPLE 1
+#define TGL_FEATURE_POLYGON_STIPPLE 0
```
Change the dimensions of a polygon stipple pattern, and how it's interpreted.
--- a/SDL_Examples/Makefile
+++ b/SDL_Examples/Makefile
@@ -1,5 +1,5 @@
CC= gcc
-CFLAGS = -g -Wall -O3
+CFLAGS = -g -Wall -O3 -w
GL_LIBS= -L../
GL_INCLUDES= -I../include/
ALL_T= gears texture model helloworld
@@ -9,6 +9,8 @@
rm -f $(ALL_T) *.exe
texture:
gcc texture.c $(LIB) -o texture $(GL_INCLUDES) $(GL_LIBS) $(CFLAGS) -lSDL -lSDL_mixer -lmad -logg -lmikmod -logg -lm
+#triangle:
+# gcc triangle.c $(LIB) -o triangle $(GL_INCLUDES) $(GL_LIBS) $(CFLAGS) -lSDL -lGLU -lSDL_mixer -lmad -logg -lmikmod -logg -lm
helloworld:
gcc helloworld.c $(LIB) -o helloworld $(GL_INCLUDES) $(GL_LIBS) $(CFLAGS) -lSDL -lSDL_mixer -lmad -logg -lmikmod -logg -lm
--- a/SDL_Examples/gears.c
+++ b/SDL_Examples/gears.c
@@ -5,6 +5,8 @@
* ported to libSDL/TinyGL by Gerald Franz (gfz@o2online.de)
*/
+//#define PLAY_MUSIC
+
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
@@ -288,7 +290,9 @@
fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
return 1;
}
+#ifdef PLAY_MUSIC
ainit(0);
+#endif
SDL_Surface* screen = NULL;
if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
fprintf(stderr,"ERROR: Video mode set failed.\n");
@@ -306,8 +310,10 @@
printf("\nASHIFT IS %u",screen->format->Ashift);
fflush(stdout);
track* myTrack = NULL;
+#ifdef PLAY_MUSIC
myTrack = lmus("WWGW.mp3");
mplay(myTrack, -1, 1000);
+#endif
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_SetCaption(argv[0],0);
@@ -399,11 +405,11 @@
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
draw();
- glDrawText((unsigned char*)"RED text", 0, 0, 0x000000FF);
+// glDrawText((unsigned char*)"RED text", 0, 0, 0x000000FF);
- glDrawText((unsigned char*)"GREEN text", 0, 24,0x0000FF00);
+// glDrawText((unsigned char*)"GREEN text", 0, 24,0x0000FF00);
- glDrawText((unsigned char*)"BLUE text", 0, 48, 0x00FF0000);
+// glDrawText((unsigned char*)"BLUE text", 0, 48, 0x00FF0000);
// swap buffers:
if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
fprintf(stderr, "SDL ERROR: Can't lock screen: %s\n", SDL_GetError());
@@ -453,9 +459,11 @@
ZB_close(frameBuffer);
if(SDL_WasInit(SDL_INIT_VIDEO))
SDL_QuitSubSystem(SDL_INIT_VIDEO);
+#ifdef PLAY_MUSIC
mhalt();
Mix_FreeMusic(myTrack);
acleanup();
+#endif
SDL_Quit();
return 0;
}
--- a/SDL_Examples/helloworld.c
+++ b/SDL_Examples/helloworld.c
@@ -5,13 +5,14 @@
*
* ported to libSDL/TinyGL by Gerald Franz (gfz@o2online.de)
*/
+//#define PLAY_MUSIC
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-
#include "../include/GL/gl.h"
+//#include <GL/glu.h>
#define CHAD_API_IMPL
#include "include/api_audio.h"
#define STB_IMAGE_IMPLEMENTATION
@@ -25,8 +26,9 @@
GLuint tex = 0;
double time_passed = 0.0;
+int winSizeX=640;
+int winSizeY=480;
-
void draw() {
//glEnable(GL_TEXTURE_2D);
//glBindTexture(GL_TEXTURE_2D,tex);
@@ -51,6 +53,34 @@
}
+void draw2(){
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ int x = 0;
+ // Select and setup the projection matrix
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ //gluPerspective( 65.0f, (GLfloat)winSizeX/(GLfloat)winSizeY, 1.0f, 100.0f );
+ GLfloat h = (GLfloat) winSizeY / (GLfloat) winSizeX;
+ glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
+ // Select and setup the modelview matrix
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+ glRotatef(-90, 1,0,0);
+ glTranslatef(0,0,-1.0f);
+
+ // Draw a rotating colorful triangle
+ glTranslatef( 0.0f, 14.0f, 0.0f );
+ glRotatef( 0.3f*(GLfloat)x + (GLfloat)time_passed*100.0f, 0.0f, 0.0f, 1.0f );
+ glBegin( GL_TRIANGLES );
+ glColor4f( 1.0f, 0.0f, 0.0f, 0.0f );
+ glVertex3f( -5.0f, 0.0f, -4.0f );
+ glColor4f( 0.0f, 1.0f, 0.0f, 0.0f );
+ glVertex3f( 5.0f, 0.0f, -4.0f );
+ glColor4f( 0.0f, 0.0f, 0.0f, 0.0f );
+ glVertex3f( 0.0f, 0.0f, 6.0f );
+ glEnd();
+}
+
void initScene() {
//glLightfv( GL_LIGHT0, GL_AMBIENT, white);
@@ -80,8 +110,7 @@
int main(int argc, char **argv) {
// initialize SDL video:
- int winSizeX=640;
- int winSizeY=480;
+
unsigned int fps =0;
if(argc > 2){
char* larg = argv[1];
@@ -99,7 +128,9 @@
fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
return 1;
}
+#ifdef PLAY_MUSIC
ainit(0);
+#endif
SDL_Surface* screen = NULL;
if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
fprintf(stderr,"ERROR: Video mode set failed.\n");
@@ -117,8 +148,10 @@
printf("\nASHIFT IS %u",screen->format->Ashift);
fflush(stdout);
track* myTrack = NULL;
+#ifdef PLAY_MUSIC
myTrack = lmus("WWGW.mp3");
mplay(myTrack, -1, 1000);
+#endif
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_SetCaption(argv[0],0);
@@ -197,7 +230,7 @@
// draw scene:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- draw();
+ draw2();
glDrawText((unsigned char*)"Hello World!\nFrom TinyGL", 0, 0, 0x00FFFFFF);
// swap buffers:
if ( SDL_MUSTLOCK(screen) && (SDL_LockSurface(screen)<0) ) {
@@ -245,9 +278,11 @@
ZB_close(frameBuffer);
if(SDL_WasInit(SDL_INIT_VIDEO))
SDL_QuitSubSystem(SDL_INIT_VIDEO);
+#ifdef PLAY_MUSIC
mhalt();
Mix_FreeMusic(myTrack);
acleanup();
+#endif
SDL_Quit();
return 0;
}
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -4,6 +4,7 @@
*
* ported to libSDL/TinyGL by Gerald Franz (gfz@o2online.de)
*/
+//#define PLAY_MUSIC
#include <math.h>
#include <stdlib.h>
@@ -278,7 +279,9 @@
fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
return 1;
}
+#ifdef PLAY_MUSIC
ainit(0);
+#endif
SDL_Surface* screen = NULL;
if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
fprintf(stderr,"ERROR: Video mode set failed.\n");
@@ -295,9 +298,11 @@
printf("\nBSHIFT IS %u",screen->format->Bshift);
printf("\nASHIFT IS %u",screen->format->Ashift);
fflush(stdout);
+#ifdef PLAY_MUSIC
+ myTrack = lmus("WWGW.mp3");
+ mplay(myTrack, -1, 1000);
+#endif
- myTrack = lmus("WWGW.mp3");
- mplay(myTrack, -1, 1000);
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_SetCaption(argv[0],0);
@@ -553,9 +558,11 @@
if(SDL_WasInit(SDL_INIT_VIDEO))
SDL_QuitSubSystem(SDL_INIT_VIDEO);
+#ifdef PLAY_MUSIC
mhalt();
Mix_FreeMusic(myTrack);
acleanup();
+#endif
SDL_Quit();
return 0;
}
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -4,6 +4,7 @@
*
* ported to libSDL/TinyGL by Gerald Franz (gfz@o2online.de)
*/
+//#define PLAY_MUSIC
#include <math.h>
#include <stdlib.h>
@@ -130,7 +131,9 @@
fprintf(stderr,"ERROR: cannot initialize SDL video.\n");
return 1;
}
+#ifdef PLAY_MUSIC
ainit(0);
+#endif
SDL_Surface* screen = NULL;
if((screen=SDL_SetVideoMode( winSizeX, winSizeY, TGL_FEATURE_RENDER_BITS, SDL_SWSURFACE)) == 0 ) {
fprintf(stderr,"ERROR: Video mode set failed.\n");
@@ -148,8 +151,10 @@
printf("\nASHIFT IS %u",screen->format->Ashift);
fflush(stdout);
track* myTrack = NULL;
+#ifdef PLAY_MUSIC
myTrack = lmus("WWGW.mp3");
mplay(myTrack, -1, 1000);
+#endif
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_SetCaption(argv[0],0);
@@ -276,9 +281,11 @@
ZB_close(frameBuffer);
if(SDL_WasInit(SDL_INIT_VIDEO))
SDL_QuitSubSystem(SDL_INIT_VIDEO);
+#ifdef PLAY_MUSIC
mhalt();
Mix_FreeMusic(myTrack);
acleanup();
+#endif
SDL_Quit();
return 0;
}
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -7,7 +7,7 @@
#define TGL_FEATURE_ARRAYS 1
#define TGL_FEATURE_DISPLAYLISTS 1
#define TGL_FEATURE_POLYGON_OFFSET 1
-#define TGL_FEATURE_POLYGON_STIPPLE 1
+#define TGL_FEATURE_POLYGON_STIPPLE 0
//A stipple pattern is 128 bytes in size.
#define TGL_POLYGON_STIPPLE_BYTES 128
//A stipple pattern is 2^5 (32) bits wide.
@@ -54,13 +54,8 @@
#define TGL_FEATURE_16_BITS 0
#define TGL_FEATURE_32_BITS 1
-//MAINTAINER'S NOTE: Only TGL_FEATURE_RENDER_BITS 32 is maintained.
-//TODO: Include support for 16 bit.
-//All others are experimental.
-//24 bit is broken.
//#define TGL_FEATURE_RENDER_BITS 15
//#define TGL_FEATURE_RENDER_BITS 16
-//#define TGL_FEATURE_RENDER_BITS 24 //BROKEN!
#if TGL_FEATURE_32_BITS == 1
#define TGL_FEATURE_RENDER_BITS 32
--- a/src/light.c
+++ b/src/light.c
@@ -332,6 +332,6 @@
v->color.v[0]=clampf(R,0,1);
v->color.v[1]=clampf(G,0,1);
v->color.v[2]=clampf(B,0,1);
- v->color.v[3]=clampf(A,0,1);
+ v->color.v[3]=A;
}
--- a/src/zbuffer.c
+++ b/src/zbuffer.c
@@ -139,16 +139,16 @@
PIXEL *q;
GLint y;
#if !TGL_FEATURE_NO_COPY_COLOR
- GLint n;
+ //GLint n;
#endif
q = zb->pbuf;
p1 = buf;
#if !TGL_FEATURE_NO_COPY_COLOR
- n = zb->xsize * PSZB;
+ //n = zb->xsize * PSZB;
#endif
for (y = 0; y < zb->ysize; y++) {
- #if TGL_FEATURE_NO_COPY_COLOR
+ #if TGL_FEATURE_NO_COPY_COLOR == 1
for(GLint i = 0; i < zb->xsize; i++)
{
if((*(q+i) & TGL_COLOR_MASK) != TGL_NO_COPY_COLOR)
@@ -155,7 +155,7 @@
*(((PIXEL*)p1) + i) = *(q+i);
}
#else
- memcpy(p1, q, n);
+ memcpy(p1, q, linesize);
#endif
p1 += linesize; //TODO make this a predictable behavior.
q = (PIXEL *) ((GLbyte *) q + zb->linesize);