@@ -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
};
@@ -203,10 +205,12 @@ static int CreateShader(const char *vertexShaderFile, const char *fragmentShader
203
205
glAttachShader (shaderProgram, vertShader);
204
206
glAttachShader (shaderProgram, fragShader);
205
207
glLinkProgram (shaderProgram);
208
+ glUseProgram (shaderProgram);
206
209
207
210
outShader->shaderProgram = shaderProgram;
208
211
outShader->uniView = glGetUniformLocation (shaderProgram, " view" );
209
212
outShader->uniProj = glGetUniformLocation (shaderProgram, " proj" );
213
+ outShader->uniNightSight = glGetUniformLocation (shaderProgram, " nightsight" );
210
214
outShader->tcAttrib = glGetAttribLocation (shaderProgram, " texcoords" );
211
215
outShader->lightAttrib = glGetAttribLocation (shaderProgram, " light" );
212
216
@@ -391,6 +395,10 @@ static void updatePalette(SDL_Palette *palette, bool transparent) {
391
395
}
392
396
}
393
397
398
+ static bool nightsight_active () {
399
+ return WareActive (player_struct.hardwarez_status [HARDWARE_GOGGLE_INFRARED]);
400
+ }
401
+
394
402
void opengl_start_frame () {
395
403
SDL_GL_MakeCurrent (window, context);
396
404
@@ -424,6 +432,8 @@ void opengl_swap_and_restore() {
424
432
GLint tcAttrib = textureShaderProgram.tcAttrib ;
425
433
GLint lightAttrib = textureShaderProgram.lightAttrib ;
426
434
435
+ glUniform1i (textureShaderProgram.uniNightSight , nightsight_active ());
436
+
427
437
glUniformMatrix4fv (textureShaderProgram.uniView , 1 , false , IdentityMatrix);
428
438
glUniformMatrix4fv (textureShaderProgram.uniProj , 1 , false , IdentityMatrix);
429
439
@@ -448,6 +458,8 @@ void opengl_swap_and_restore() {
448
458
449
459
glFlush ();
450
460
461
+ glUniform1i (textureShaderProgram.uniNightSight , false );
462
+
451
463
// check OpenGL error
452
464
GLenum err = glGetError ();
453
465
if (err != GL_NO_ERROR)
@@ -640,19 +652,21 @@ static void set_texture(grs_bitmap *bm) {
640
652
static void draw_vertex (const g3s_point& vertex, GLint tcAttrib, GLint lightAttrib) {
641
653
642
654
// Default, per-vertex lighting
643
- float light = vertex.i / 4096 .0f ;
655
+ float light = 1 . 0f - ( vertex.i / 4096 .0f ) ;
644
656
645
- // Could be a CLUT color instead, use that for lighting
646
- if (gr_get_fill_type () == FILL_CLUT) {
657
+ if (nightsight_active ()) {
658
+ light = 1 .0f ;
659
+ } else if (gr_get_fill_type () == FILL_CLUT) {
660
+ // Could be a CLUT color instead, use that for lighting
647
661
// Ugly hack: We don't get the original light value, so we have to
648
662
// recalculate it from the offset into the global lighting lookup
649
663
// table.
650
664
uchar* clut = (uchar*)gr_get_fill_parm ();
651
- light = (clut - grd_screen->ltab ) / 4096 .0f ;
665
+ light = 1 . 0f - (clut - grd_screen->ltab ) / 4096 .0f ;
652
666
}
653
667
654
668
glVertexAttrib2f (tcAttrib, vertex.uv .u / 256.0 , vertex.uv .v / 256.0 );
655
- glVertexAttrib1f (lightAttrib, 1 . 0f - light);
669
+ glVertexAttrib1f (lightAttrib, light);
656
670
glVertex3f (vertex.x / 65536 .0f , vertex.y / 65536 .0f , -vertex.z / 65536 .0f );
657
671
}
658
672
@@ -727,7 +741,7 @@ int opengl_bitmap(grs_bitmap *bm, int n, grs_vertex **vpl, grs_tmap_info *ti) {
727
741
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
728
742
729
743
float light = 1 .0f ;
730
- if (ti->flags & TMF_CLUT) {
744
+ if (( ti->flags & TMF_CLUT) && ! nightsight_active () ) {
731
745
// Ugly hack: We don't get the original 'i' value, so we have to
732
746
// recalculate it from the offset into the global lighting lookup
733
747
// table.
0 commit comments