Skip to content

Commit

Permalink
Fix material properties not being applied on frame start
Browse files Browse the repository at this point in the history
This was causing one of the clouds in the city to have its shadow drawn as an
opaque black splotch on every frame.
  • Loading branch information
nsgomez committed Jul 23, 2024
1 parent 8990572 commit 058e738
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions scgl/GLStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void GLStateManager::InterleavedArrays(GLenum format, GLsizei stride, void const
// These extensions did not exist when SimCity 4 was released, so their workaround was to
// use the CPU to swap the order of color components. That's slow - let's never do that.
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, stride, reinterpret_cast<uint8_t const*>(pointer) + colorOffset);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseLightParams);
}

shareable.interleavedPointer = pointer;
Expand Down Expand Up @@ -250,21 +251,23 @@ void GLStateManager::ShadeModel(GLenum mode) {
}

void GLStateManager::ColorMultiplier(float r, float g, float b) {
//if (ambientLightParams[0] != r || ambientLightParams[1] != g || ambientLightParams[2] != b) {
if (ambientLightParams[0] != r || ambientLightParams[1] != g || ambientLightParams[2] != b) {
ambientLightParams[0] = r;
ambientLightParams[1] = g;
ambientLightParams[2] = b;

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLightParams);
//}
}
}

void GLStateManager::AlphaMultiplier(float a) {
//if (diffuseLightParams[3] != a) {
if (diffuseLightParams[3] != a) {
diffuseLightParams[3] = a;

glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseLightParams);
//}
if (ambientLightEnabled || diffuseLightEnabled) {
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseLightParams);
}
}
}

void GLStateManager::EnableVertexColors(bool ambient, bool diffuse) {
Expand Down Expand Up @@ -298,6 +301,9 @@ void GLStateManager::EnableVertexColors(bool ambient, bool diffuse) {
}

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

Expand Down

0 comments on commit 058e738

Please sign in to comment.