@@ -33,6 +33,7 @@ extern "C" {
3333 #include " Shock.h"
3434 #include " faketime.h"
3535 #include " render.h"
36+ #include " wares.h"
3637
3738 extern SDL_Renderer *renderer;
3839 extern SDL_Palette *sdlPalette;
@@ -54,6 +55,7 @@ struct Shader {
5455 GLuint shaderProgram;
5556 GLint uniView;
5657 GLint uniProj;
58+ GLint uniNightSight;
5759 GLint tcAttrib;
5860 GLint lightAttrib;
5961};
@@ -204,10 +206,12 @@ static int CreateShader(const char *vertexShaderFile, const char *fragmentShader
204206 glAttachShader (shaderProgram, vertShader);
205207 glAttachShader (shaderProgram, fragShader);
206208 glLinkProgram (shaderProgram);
209+ glUseProgram (shaderProgram);
207210
208211 outShader->shaderProgram = shaderProgram;
209212 outShader->uniView = glGetUniformLocation (shaderProgram, " view" );
210213 outShader->uniProj = glGetUniformLocation (shaderProgram, " proj" );
214+ outShader->uniNightSight = glGetUniformLocation (shaderProgram, " nightsight" );
211215 outShader->tcAttrib = glGetAttribLocation (shaderProgram, " texcoords" );
212216 outShader->lightAttrib = glGetAttribLocation (shaderProgram, " light" );
213217
@@ -393,6 +397,10 @@ static void updatePalette(SDL_Palette *palette, bool transparent) {
393397 }
394398}
395399
400+ static bool nightsight_active () {
401+ return WareActive (player_struct.hardwarez_status [HARDWARE_GOGGLE_INFRARED]);
402+ }
403+
396404void opengl_start_frame () {
397405 SDL_GL_MakeCurrent (window, context);
398406
@@ -426,6 +434,8 @@ void opengl_swap_and_restore() {
426434 GLint tcAttrib = textureShaderProgram.tcAttrib ;
427435 GLint lightAttrib = textureShaderProgram.lightAttrib ;
428436
437+ glUniform1i (textureShaderProgram.uniNightSight , nightsight_active ());
438+
429439 glUniformMatrix4fv (textureShaderProgram.uniView , 1 , false , IdentityMatrix);
430440 glUniformMatrix4fv (textureShaderProgram.uniProj , 1 , false , IdentityMatrix);
431441
@@ -450,6 +460,8 @@ void opengl_swap_and_restore() {
450460
451461 glFlush ();
452462
463+ glUniform1i (textureShaderProgram.uniNightSight , false );
464+
453465 // check OpenGL error
454466 GLenum err = glGetError ();
455467 if (err != GL_NO_ERROR)
@@ -642,19 +654,21 @@ static void set_texture(grs_bitmap *bm) {
642654static void draw_vertex (const g3s_point& vertex, GLint tcAttrib, GLint lightAttrib) {
643655
644656 // Default, per-vertex lighting
645- float light = vertex.i / 4096 .0f ;
657+ float light = 1 . 0f - ( vertex.i / 4096 .0f ) ;
646658
647- // Could be a CLUT color instead, use that for lighting
648- if (gr_get_fill_type () == FILL_CLUT) {
659+ if (nightsight_active ()) {
660+ light = 1 .0f ;
661+ } else if (gr_get_fill_type () == FILL_CLUT) {
662+ // Could be a CLUT color instead, use that for lighting
649663 // Ugly hack: We don't get the original light value, so we have to
650664 // recalculate it from the offset into the global lighting lookup
651665 // table.
652666 uchar* clut = (uchar*)gr_get_fill_parm ();
653- light = (clut - grd_screen->ltab ) / 4096 .0f ;
667+ light = 1 . 0f - (clut - grd_screen->ltab ) / 4096 .0f ;
654668 }
655669
656670 glVertexAttrib2f (tcAttrib, vertex.uv .u / 256.0 , vertex.uv .v / 256.0 );
657- glVertexAttrib1f (lightAttrib, 1 . 0f - light);
671+ glVertexAttrib1f (lightAttrib, light);
658672 glVertex3f (vertex.x / 65536 .0f , vertex.y / 65536 .0f , -vertex.z / 65536 .0f );
659673}
660674
@@ -729,7 +743,7 @@ int opengl_bitmap(grs_bitmap *bm, int n, grs_vertex **vpl, grs_tmap_info *ti) {
729743 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
730744
731745 float light = 1 .0f ;
732- if (ti->flags & TMF_CLUT) {
746+ if (( ti->flags & TMF_CLUT) && ! nightsight_active () ) {
733747 // Ugly hack: We don't get the original 'i' value, so we have to
734748 // recalculate it from the offset into the global lighting lookup
735749 // table.
0 commit comments