fragglet / sdl-sopwith

Classic bi-plane shoot-'em up
https://fragglet.github.io/sdl-sopwith
GNU General Public License v2.0
66 stars 13 forks source link

Add new feature: selectable video palettes #31

Closed techknight closed 7 months ago

techknight commented 7 months ago

Summary

This new feature adds a selectable video palette to the options menu. Pressing 2 on the menu cycles through the available color palettes. The player's choice is saved and reloaded between sessions.

Addresses issue #29.

Implementation

  1. Added new struct VideoPalette to hold the name and color values of each palette:
    {"CGA 1", // CGA black, cyan, magenta, white (Sopwith's default color scheme)
        {{0, 0, 0}, {0, 255, 255}, {255, 0, 255}, {255, 255, 255}}},
    {"CGA 2", // CGA black, red, green, yellow
        {{0, 0, 0}, {0, 255, 0}, {255, 0, 0}, {255, 255, 0}}},
    {"CGA Amber", // Shades of amber from a monochrome CGA display
        {{0, 0, 0}, {242, 125, 0}, {255, 170, 16}, {255, 226, 52}}},
    {"CGA Green", // Shades of green from a monochrome CGA display
        {{0, 0, 0}, {8, 202, 48}, {12, 238, 56}, {49, 253, 90}}},
    {"CGA Grey", // Shades of grey from a monochrome CGA display
        {{0, 0, 0}, {182, 186, 182}, {222, 222, 210}, {255, 255, 255}}},
    {"LCD 1", // Toshiba laptop with STN panel
        {{213, 226, 138}, {150, 160, 150}, {120, 120, 160}, {0, 20, 200}}},
    {"LCD 2", // Toshiba laptop with STN panel, reversed
        {{0, 20, 200}, {120, 120, 160}, {150, 160, 150}, {213, 226, 138}}},
  2. Options now support a new CONF_INT type, of which conf_video_palette is the first.
  3. Three new functions:
    1. Vid_SetVideoPalette() sets the video palette to a specified entry from the list of palettes
    2. Vid_GetVideoPaletteName() returns the name of a given video palette, for use on the options menu
    3. Vid_GetNumVideoPalettes() counts how many video palettes have been defined

When the options menu is active, there are points at which it must know whether it's dealing with a CONF_BOOL, CONF_INT, or CONF_KEY. In the case of CONF_INT, since the video palettes have names, there is a further check based on the name of the current option being considered.

Testing

I focused on making sure that the game defaults to the original video palette, if sopwith.cfg :

Entering the options menu with an invalid setting causes no unwanted behavior.

Video Palettes

Below are the first wave of new video palettes for SDL Sopwith.

To determine some of their color values, I used 86box to emulate PC hardware with a CGA video card installed, hooked up to a variety of displays. I took screenshots and used Photoshop to get the numbers.

In issue #29, @fragglet suggested:

  • Let's make sure there's enough contrast to see things properly - the amber scheme in your screenshot makes it look like the two darker shades are hard to distinguish

The amber palette is now taken from 86box (and looks great!), but it's worth mentioning that both the grey and green palettes are somewhat hard to distinguish, even though they're "accurate".

I think it's fair to adjust the colors for fun and useability, but I as I was working I kept thinking about accuracy and how nice it would be to have a full CRT shader with scanlines. 😅

CGA 1

CGA-1-Title CGA-1-Options

CGA 2

CGA-2-Title CGA-2-Options

CGA Amber

CGA-Amber-Title CGA-Amber-Options

CGA Green

CGA-Green-Title CGA-Green-Options

CGA Grey

CGA-Grey-Title CGA-Grey-Options

LCD 1

LCD-1-Title LCD-1-Options

LCD 2

LCD-2-Title LCD-2-Options

fragglet commented 7 months ago

Excellent work, thank you!