@@ -33,6 +33,7 @@ extern "C" {
33
33
#include " Shock.h"
34
34
#include " faketime.h"
35
35
#include " render.h"
36
+ #include " wares.h"
36
37
37
38
extern SDL_Renderer *renderer;
38
39
extern SDL_Palette *sdlPalette;
@@ -54,6 +55,7 @@ struct Shader {
54
55
GLuint shaderProgram;
55
56
GLint uniView;
56
57
GLint uniProj;
58
+ GLint uniNightSight;
57
59
GLint tcAttrib;
58
60
GLint lightAttrib;
59
61
};
@@ -204,10 +206,12 @@ static int CreateShader(const char *vertexShaderFile, const char *fragmentShader
204
206
glAttachShader (shaderProgram, vertShader);
205
207
glAttachShader (shaderProgram, fragShader);
206
208
glLinkProgram (shaderProgram);
209
+ glUseProgram (shaderProgram);
207
210
208
211
outShader->shaderProgram = shaderProgram;
209
212
outShader->uniView = glGetUniformLocation (shaderProgram, " view" );
210
213
outShader->uniProj = glGetUniformLocation (shaderProgram, " proj" );
214
+ outShader->uniNightSight = glGetUniformLocation (shaderProgram, " nightsight" );
211
215
outShader->tcAttrib = glGetAttribLocation (shaderProgram, " texcoords" );
212
216
outShader->lightAttrib = glGetAttribLocation (shaderProgram, " light" );
213
217
@@ -393,6 +397,10 @@ static void updatePalette(SDL_Palette *palette, bool transparent) {
393
397
}
394
398
}
395
399
400
+ static bool nightsight_active () {
401
+ return WareActive (player_struct.hardwarez_status [HARDWARE_GOGGLE_INFRARED]);
402
+ }
403
+
396
404
void opengl_start_frame () {
397
405
SDL_GL_MakeCurrent (window, context);
398
406
@@ -426,6 +434,8 @@ void opengl_swap_and_restore() {
426
434
GLint tcAttrib = textureShaderProgram.tcAttrib ;
427
435
GLint lightAttrib = textureShaderProgram.lightAttrib ;
428
436
437
+ glUniform1i (textureShaderProgram.uniNightSight , nightsight_active ());
438
+
429
439
glUniformMatrix4fv (textureShaderProgram.uniView , 1 , false , IdentityMatrix);
430
440
glUniformMatrix4fv (textureShaderProgram.uniProj , 1 , false , IdentityMatrix);
431
441
@@ -450,6 +460,8 @@ void opengl_swap_and_restore() {
450
460
451
461
glFlush ();
452
462
463
+ glUniform1i (textureShaderProgram.uniNightSight , false );
464
+
453
465
// check OpenGL error
454
466
GLenum err = glGetError ();
455
467
if (err != GL_NO_ERROR)
@@ -642,19 +654,21 @@ static void set_texture(grs_bitmap *bm) {
642
654
static void draw_vertex (const g3s_point& vertex, GLint tcAttrib, GLint lightAttrib) {
643
655
644
656
// Default, per-vertex lighting
645
- float light = vertex.i / 4096 .0f ;
657
+ float light = 1 . 0f - ( vertex.i / 4096 .0f ) ;
646
658
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
649
663
// Ugly hack: We don't get the original light value, so we have to
650
664
// recalculate it from the offset into the global lighting lookup
651
665
// table.
652
666
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 ;
654
668
}
655
669
656
670
glVertexAttrib2f (tcAttrib, vertex.uv .u / 256.0 , vertex.uv .v / 256.0 );
657
- glVertexAttrib1f (lightAttrib, 1 . 0f - light);
671
+ glVertexAttrib1f (lightAttrib, light);
658
672
glVertex3f (vertex.x / 65536 .0f , vertex.y / 65536 .0f , -vertex.z / 65536 .0f );
659
673
}
660
674
@@ -729,7 +743,7 @@ int opengl_bitmap(grs_bitmap *bm, int n, grs_vertex **vpl, grs_tmap_info *ti) {
729
743
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
730
744
731
745
float light = 1 .0f ;
732
- if (ti->flags & TMF_CLUT) {
746
+ if (( ti->flags & TMF_CLUT) && ! nightsight_active () ) {
733
747
// Ugly hack: We don't get the original 'i' value, so we have to
734
748
// recalculate it from the offset into the global lighting lookup
735
749
// table.
0 commit comments