Skip to content

Commit

Permalink
Adjust lighting configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nsgomez committed Oct 28, 2024
1 parent 7a728b3 commit 7f78a9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 8 additions & 8 deletions scgl/GLStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ GLStateManager::GLStateManager() :
alphaFunc(7), // GL_ALWAYS
alphaRef(0.0f),
shadeModel(1), // GL_SMOOTH,
ambientLightEnabled(true),
diffuseLightEnabled(true),
ambientLightEnabled(false),
diffuseLightEnabled(false),
ambientLightParams{ 0.2f, 0.2f, 0.2f, 1.0f },
diffuseLightParams{ 0.0f, 0.0f, 0.0f, 1.0f },
isIdentityMatrix{ true, true, true },
Expand Down Expand Up @@ -271,13 +271,13 @@ void GLStateManager::AlphaMultiplier(float a) {
}

void GLStateManager::EnableVertexColors(bool ambient, bool diffuse) {
//if (ambientLightEnabled != ambient || diffuseLightEnabled != diffuse) {
ambientLightEnabled = ambient;
diffuseLightEnabled = diffuse;

if (ambientLightEnabled != ambient || diffuseLightEnabled != diffuse) {
uint8_t oldFlags = (ambientLightEnabled ? 1 : 0) | (diffuseLightEnabled ? 2 : 0);
uint8_t newFlags = (ambient ? 1 : 0) | (diffuse ? 2 : 0);

ambientLightEnabled = ambient;
diffuseLightEnabled = diffuse;

switch (newFlags) {
case 0:
glDisable(GL_COLOR_MATERIAL);
Expand All @@ -300,11 +300,11 @@ void GLStateManager::EnableVertexColors(bool ambient, bool diffuse) {
break;
}

glEnable(GL_COLOR_MATERIAL);
if (!oldFlags) {
glEnable(GL_COLOR_MATERIAL);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseLightParams);
}
//}
}
}

void GLStateManager::MatrixMode(GLenum mode) {
Expand Down
11 changes: 9 additions & 2 deletions scgl/cGDriver_Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,17 @@ namespace nSCGL
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

GLfloat ambientLightParams[] = { 1.0f, 0.0f, 0.0f, 1.0f };
GLfloat ambientLightParams[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLightParams);

GLfloat diffuseLightParams[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLightParams);
glLightfv(GL_LIGHT0, GL_SPECULAR, diffuseLightParams);

GLfloat ambientMaterialParams[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT, ambientLightParams);

GLfloat diffuseLightParams[] = { 0.0f, 0.0f, 0.0f, 0.0f };
GLfloat diffuseMaterialParams[] = { 0.0f, 0.0f, 0.0f, 0.0f };
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseLightParams);

SetViewport();
Expand Down

0 comments on commit 7f78a9b

Please sign in to comment.