Skip to content

Commit

Permalink
gfx: add wireframe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Jun 14, 2024
1 parent 012fd9b commit 28dd411
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
- `/hp`
- `/hp [num]`
- `/heal`
- `/wireframe`
- added unobtainable secrets stat support in the gameflow (#1379)
- added an option to enable wireframe mode
- fixed config tool and installer missing icons (#1358, regression from 4.0)
- fixed looking forward too far causing an upside down camera frame (#1338)
- fixed the enemy bear behavior in demo mode (#1370, regression since 2.16)
Expand Down
4 changes: 4 additions & 0 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Currently supported commands:
`/braid off`
Grants the power to switch Lara's iconic braid on and off.

- `/wireframe on`
`/wireframe off`
Enables or disables the wireframe mode. Enter the debugging realm!

- `/endlevel`
Ends the current level. Ideal for speedruns.

Expand Down
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@
"OSD_SPEED_SET": "Speed set to %d",
"OSD_BRAID_ON": "Braid enabled",
"OSD_BRAID_OFF": "Braid disabled",
"OSD_WIREFRAME_ON": "Wireframe enabled",
"OSD_WIREFRAME_OFF": "Wireframe disabled",
"OSD_VSYNC_ON": "VSync enabled",
"OSD_VSYNC_OFF": "VSync disabled",
"OSD_CHEATS_ON": "Cheats enabled",
Expand Down
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
"OSD_SPEED_SET": "Speed set to %d",
"OSD_BRAID_ON": "Braid enabled",
"OSD_BRAID_OFF": "Braid disabled",
"OSD_WIREFRAME_ON": "Wireframe enabled",
"OSD_WIREFRAME_OFF": "Wireframe disabled",
"OSD_VSYNC_ON": "VSync enabled",
"OSD_VSYNC_OFF": "VSync disabled",
"OSD_CHEATS_ON": "Cheats enabled",
Expand Down
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@
"OSD_SPEED_SET": "Speed set to %d",
"OSD_BRAID_ON": "Braid enabled",
"OSD_BRAID_OFF": "Braid disabled",
"OSD_WIREFRAME_ON": "Wireframe enabled",
"OSD_WIREFRAME_OFF": "Wireframe disabled",
"OSD_VSYNC_ON": "VSync enabled",
"OSD_VSYNC_OFF": "VSync disabled",
"OSD_CHEATS_ON": "Cheats enabled",
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ typedef struct {
bool enable_perspective_filter;
GFX_TEXTURE_FILTER texture_filter;
GFX_TEXTURE_FILTER fbo_filter;
bool enable_wireframe;
bool enable_vsync;
bool enable_fps_counter;
float anisotropy_filter;
Expand Down
1 change: 1 addition & 0 deletions src/config_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const CONFIG_OPTION g_ConfigOptionMap[] = {
{ .name = "fps", .type = COT_INT32, .target = &g_Config.rendering.fps, .default_value = &(int32_t){30}, 0},
{ .name = "texture_filter", .type = COT_INT32, .target = &g_Config.rendering.texture_filter, .default_value = &(int32_t){GFX_TF_BILINEAR}, 0},
{ .name = "fbo_filter", .type = COT_INT32, .target = &g_Config.rendering.fbo_filter, .default_value = &(int32_t){GFX_TF_NN}, 0},
{ .name = "enable_wireframe", .type = COT_BOOL, .target = &g_Config.rendering.enable_wireframe, .default_value = &(bool){false}, 0},
{ .name = "enable_perspective_filter", .type = COT_BOOL, .target = &g_Config.rendering.enable_perspective_filter, .default_value = &(bool){true}, 0},
{ .name = "enable_vsync", .type = COT_BOOL, .target = &g_Config.rendering.enable_vsync, .default_value = &(bool){true}, 0},
{ .name = "music_volume", .type = COT_INT32, .target = &g_Config.music_volume, .default_value = &(int32_t){8}, 0},
Expand Down
21 changes: 21 additions & 0 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static COMMAND_RESULT Console_Cmd_Fly(const char *const args);
static COMMAND_RESULT Console_Cmd_Speed(const char *const args);
static COMMAND_RESULT Console_Cmd_VSync(const char *const args);
static COMMAND_RESULT Console_Cmd_Braid(const char *const args);
static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args);
static COMMAND_RESULT Console_Cmd_Cheats(const char *const args);
static COMMAND_RESULT Console_Cmd_GiveItem(const char *args);
static COMMAND_RESULT Console_Cmd_FlipMap(const char *args);
Expand Down Expand Up @@ -314,6 +315,25 @@ static COMMAND_RESULT Console_Cmd_Braid(const char *const args)
return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args)
{
if (String_Equivalent(args, "off")) {
g_Config.rendering.enable_wireframe = false;
Config_Write();
Console_Log(GS(OSD_WIREFRAME_OFF));
return CR_SUCCESS;
}

if (String_Equivalent(args, "on")) {
g_Config.rendering.enable_wireframe = true;
Config_Write();
Console_Log(GS(OSD_WIREFRAME_ON));
return CR_SUCCESS;
}

return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_Cheats(const char *const args)
{
if (String_Equivalent(args, "off")) {
Expand Down Expand Up @@ -650,6 +670,7 @@ CONSOLE_COMMAND g_ConsoleCommands[] = {
{ .prefix = "speed", .proc = Console_Cmd_Speed },
{ .prefix = "vsync", .proc = Console_Cmd_VSync },
{ .prefix = "braid", .proc = Console_Cmd_Braid },
{ .prefix = "wireframe", .proc = Console_Cmd_Wireframe },
{ .prefix = "cheats", .proc = Console_Cmd_Cheats },
{ .prefix = "give", .proc = Console_Cmd_GiveItem },
{ .prefix = "gimme", .proc = Console_Cmd_GiveItem },
Expand Down
2 changes: 2 additions & 0 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ GS_DEFINE(OSD_SPEED_GET, "Current speed: %d")
GS_DEFINE(OSD_SPEED_SET, "Speed set to %d")
GS_DEFINE(OSD_BRAID_ON, "Braid enabled")
GS_DEFINE(OSD_BRAID_OFF, "Braid disabled")
GS_DEFINE(OSD_WIREFRAME_ON, "Wireframe enabled")
GS_DEFINE(OSD_WIREFRAME_OFF, "Wireframe disabled")
GS_DEFINE(OSD_VSYNC_ON, "VSync enabled")
GS_DEFINE(OSD_VSYNC_OFF, "VSync disabled")
GS_DEFINE(OSD_CHEATS_ON, "Cheats enabled")
Expand Down
13 changes: 4 additions & 9 deletions src/gfx/3d/3d_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ void GFX_3D_Renderer_Init(GFX_3D_Renderer *renderer)
LOG_INFO("");
assert(renderer);

// TODO: make me configurable
renderer->wireframe = false;
renderer->selected_texture_num = GFX_NO_TEXTURE;
for (int i = 0; i < GFX_MAX_TEXTURES; i++) {
renderer->textures[i] = NULL;
Expand Down Expand Up @@ -80,6 +78,7 @@ void GFX_3D_Renderer_Init(GFX_3D_Renderer *renderer)

GFX_3D_VertexStream_Init(&renderer->vertex_stream);

glLineWidth(2.5);
GFX_GL_CheckError();
}

Expand All @@ -98,9 +97,9 @@ void GFX_3D_Renderer_RenderBegin(GFX_3D_Renderer *renderer)
assert(renderer);
glEnable(GL_BLEND);

if (renderer->wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
glPolygonMode(
GL_FRONT_AND_BACK,
g_Config.rendering.enable_wireframe ? GL_LINE : GL_FILL);
GFX_GL_CheckError();

GFX_GL_Program_Bind(&renderer->program);
Expand Down Expand Up @@ -138,10 +137,6 @@ void GFX_3D_Renderer_RenderEnd(GFX_3D_Renderer *renderer)
assert(renderer);
GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream);

if (renderer->wireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}

GFX_GL_CheckError();
}

Expand Down
1 change: 0 additions & 1 deletion src/gfx/3d/3d_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <stdint.h>

typedef struct GFX_3D_Renderer {
bool wireframe;
GFX_GL_Program program;
GFX_GL_Sampler sampler;
GFX_3D_VertexStream vertex_stream;
Expand Down
1 change: 1 addition & 0 deletions src/gfx/fbo/fbo_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void GFX_FBO_Renderer_Render(GFX_FBO_Renderer *renderer)
{
assert(renderer);

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
GFX_GL_CheckError();

Expand Down

0 comments on commit 28dd411

Please sign in to comment.