ref: b0e4642366a76e49553afa9947715ba0cc0c07a6
parent: 54b3500444819d31761907321809e3f20dd77cef
author: David <gek@katherine>
date: Tue Feb 16 10:32:31 EST 2021
Bug fix: Unlit textured models
--- a/README.md
+++ b/README.md
@@ -75,6 +75,9 @@
* There is no stencil buffer.
+* Lit triangles will use the current material properties, even if they are textures. If the diffuse color is black, then your
+textured triangles will appear black.
+
* <Undocumented limitations that have not been tested>
@@ -123,10 +126,14 @@
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.
+
+Lit texturing is toggleable because it significantly bogs down the rendering of textured triangles even if there is no lighting.
```c
#define TGL_FEATURE_ARRAYS 1
#define TGL_FEATURE_DISPLAYLISTS 1
-#define TGL_FEATURE_POLYGON_OFFSET 1
+#define TGL_FEATURE_LIT_TEXTURES 1
+//NOTE: Polygon Offset does nothing at the moment.
+#define TGL_FEATURE_POLYGON_OFFSET 0
#define TGL_FEATURE_POLYGON_STIPPLE 0
```
--- a/SDL_Examples/model.c
+++ b/SDL_Examples/model.c
@@ -312,8 +312,6 @@
glInit(frameBuffer);
srand(time(NULL));
- // initGL(winSizeX,winSizeY);
- // initialize GL:
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_DEPTH_TEST);
@@ -325,14 +323,12 @@
// glLightfv( GL_LIGHT0, GL_AMBIENT, white);
// glLightfv( GL_LIGHT0, GL_SPECULAR, white);
glEnable(GL_CULL_FACE);
- //glEnable(GL_LIGHTING);
+
//glDisable( GL_LIGHTING );
glEnable(GL_LIGHT0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
- // glEnable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
- // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glClearColor(0, 0, 0, 0);
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -227,9 +227,12 @@
/* tex coords */
if (c->texture_2d_enabled) {
+#if TGL_FEATURE_LIT_TEXTURES == 1
+ if(!(c->lighting_enabled))
+ v->color = gl_V4_New(1, 1, 1, 0); //Fix by GEK for unlit textured models.
+#endif
if (c->apply_texture_matrix) {
gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord);
- //v->color = gl_V4_New(1, 1, 1, 0); //Fix by GEK for unlit textured models.
} else {
v->tex_coord = c->current_tex_coord;
}