Border colors working on PC.

This commit is contained in:
Scott Duensing 2022-09-16 17:20:04 -05:00
parent 92894cd6d2
commit 43e0fe4b6e
2 changed files with 49 additions and 16 deletions

View file

@ -36,6 +36,8 @@
#define AUDIO_FREQUENCY 44100
#define AUDIO_CHANNELS 2
#define BORDER_WIDTH 20
typedef struct {
uint8_t *data;
@ -57,6 +59,25 @@ typedef struct {
} jlPlatformModT;
static jbyte _jlBorderRGBs[16][3] = {
{ 0x00, 0x00, 0x00 }, // Black
{ 0xdd, 0x00, 0x33 }, // Deep Red
{ 0x00, 0x00, 0x99 }, // Deep Blue
{ 0xdd, 0x22, 0xdd }, // Purple
{ 0x00, 0x77, 0x22 }, // Dark Green
{ 0x55, 0x55, 0x55 }, // Dark Gray
{ 0x22, 0x22, 0xff }, // Medium Blue
{ 0x66, 0xaa, 0xff }, // Light Blue
{ 0x88, 0x55, 0x00 }, // Brown
{ 0xff, 0x66, 0x00 }, // Orange
{ 0xaa, 0xaa, 0xaa }, // Light Gray
{ 0xff, 0x99, 0x88 }, // Pink
{ 0x11, 0xdd, 0x00 }, // Green
{ 0xff, 0xff, 0x00 }, // Yellow
{ 0x44, 0xff, 0x99 }, // Acquamarine
{ 0xff, 0xff, 0xff } // White
};
static SDL_Window *_jlWindow = NULL;
static SDL_Renderer *_jlRenderer = NULL;
static SDL_Texture *_jlTexture = NULL; // Video card representation in ARGB
@ -76,6 +97,7 @@ static jlPlatformModT *_jlModCurrent = NULL;
static jbyte _jlModVolume = 255;
static jlSoundPlayingT *_jlSoundList = NULL;
static jbyte _jlSoundsPlaying = 0;
static jint16 _jlWindowZoom = 2;
static Uint32 _jlUtilTimer(Uint32 interval, void *param);
@ -241,17 +263,17 @@ static void _jlAudioCallback(void *userdata, Uint8 *buffer, int bytes) {
void jlDisplayPresent(void) {
int i = 0;
int j = 0;
int pitch = 0;
void *pixelData = NULL;
Uint32 *pixels = NULL;
int i = 0;
int j = 0;
int pitch = 0;
void *pixelData = NULL;
Uint32 *pixels = NULL;
SDL_Rect r;
jlUtilIdle();
// Render 4 bit copy to proper pixel format.
// This extra step preserves palette effects.
//***TODO*** Fake border colors on PC
jlUtilIdle();
SDL_LockTexture(_jlTexture, NULL, &pixelData, &pitch);
pixels = (Uint32 *)pixelData;
@ -273,7 +295,16 @@ void jlDisplayPresent(void) {
}
SDL_UnlockTexture(_jlTexture);
SDL_RenderCopy(_jlRenderer, _jlTexture, NULL, NULL);
// Border.
SDL_SetRenderDrawColor(_jlRenderer, _jlBorderRGBs[_jlBorderColor][0], _jlBorderRGBs[_jlBorderColor][1], _jlBorderRGBs[_jlBorderColor][2], 255);
SDL_RenderClear(_jlRenderer);
// Display.
r.x = _jlWindowZoom * BORDER_WIDTH;
r.y = _jlWindowZoom * BORDER_WIDTH;
r.w = 320 * _jlWindowZoom;
r.h = 200 * _jlWindowZoom;
SDL_RenderCopy(_jlRenderer, _jlTexture, NULL, &r);
SDL_RenderPresent(_jlRenderer);
}
@ -615,18 +646,18 @@ void jlUtilIdle(void) {
// Track keydown/keyup and remember last key pressed.
switch (event.key.keysym.sym) {
case SDLK_F1:
//SDL_RenderSetScale(_jlRenderer, 1.0f, 1.0f);
SDL_SetWindowSize(_jlWindow, 320, 200);
_jlWindowZoom = 1;
SDL_SetWindowSize(_jlWindow, (320 + BORDER_WIDTH * 2) * _jlWindowZoom, (200 + BORDER_WIDTH * 2) * _jlWindowZoom);
break;
case SDLK_F2:
//SDL_RenderSetScale(_jlRenderer, 2.0f, 2.0f);
SDL_SetWindowSize(_jlWindow, 640, 400);
_jlWindowZoom = 2;
SDL_SetWindowSize(_jlWindow, (320 + BORDER_WIDTH * 2) * _jlWindowZoom, (200 + BORDER_WIDTH * 2) * _jlWindowZoom);
break;
case SDLK_F3:
//SDL_RenderSetScale(_jlRenderer, 3.0f, 3.0f);
SDL_SetWindowSize(_jlWindow, 860, 600);
_jlWindowZoom = 3;
SDL_SetWindowSize(_jlWindow, (320 + BORDER_WIDTH * 2) * _jlWindowZoom, (200 + BORDER_WIDTH * 2) * _jlWindowZoom);
break;
default:
@ -706,7 +737,7 @@ int main(int argc, char *argv[]) {
}
// Create a window and renderer using SDL
_jlWindow = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 400, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
_jlWindow = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (320 + BORDER_WIDTH * 2) * _jlWindowZoom, (200 + BORDER_WIDTH * 2) * _jlWindowZoom, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
_jlRenderer = SDL_CreateRenderer(_jlWindow, -1, SDL_RENDERER_SOFTWARE);
_jlTexture = SDL_CreateTexture(_jlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
_jlPixelFormat = SDL_AllocFormat(SDL_GetWindowPixelFormat(_jlWindow));

View file

@ -307,6 +307,8 @@ void musicTest(void) {
jlSoundPlay(sound1, CHANNEL_FRONT_LEFT, 255);
jlSoundPlay(sound2, CHANNEL_FRONT_RIGHT, 255);
jlDisplayBorder(BORDER_DEEP_BLUE);
while (!jlKeyPressed()) {
fontPrint(font, NULL, 1, 1, "%dx%d %d %d ", jlGameGetAxis(0), jlGameGetAxis(1), jlGameGetButton(0), jlGameGetButton(1));
jlDisplayPresent();