Window scaling fixed in SDL 1.2 backend.
This commit is contained in:
parent
19854fef80
commit
fe87646e62
1 changed files with 79 additions and 34 deletions
|
@ -93,7 +93,7 @@ static jbool _jlModPlaying = jfalse;
|
||||||
static jlPlatformModT *_jlModCurrent = NULL;
|
static jlPlatformModT *_jlModCurrent = NULL;
|
||||||
static jbyte _jlModVolume = 255;
|
static jbyte _jlModVolume = 255;
|
||||||
static jlSoundPlayingT *_jlSoundList = NULL;
|
static jlSoundPlayingT *_jlSoundList = NULL;
|
||||||
static jint16 _jlWindowZoom = 2;
|
static jint16 _jlWindowZoom = 3;
|
||||||
|
|
||||||
|
|
||||||
static Uint32 _jlUtilTimer(Uint32 interval, void *param);
|
static Uint32 _jlUtilTimer(Uint32 interval, void *param);
|
||||||
|
@ -103,10 +103,10 @@ static void _jlAudioCallback(void *userdata, Uint8 *buffer, int bytes);
|
||||||
extern jbool _jlSwapChannels;
|
extern jbool _jlSwapChannels;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||||
|
|
||||||
|
/*
|
||||||
Uint32 _jlGetPixel(SDL_Surface *surface, int x, int y) {
|
Uint32 _jlGetPixel(SDL_Surface *surface, int x, int y) {
|
||||||
|
|
||||||
int bpp = surface->format->BytesPerPixel;
|
int bpp = surface->format->BytesPerPixel;
|
||||||
|
@ -138,6 +138,7 @@ Uint32 _jlGetPixel(SDL_Surface *surface, int x, int y) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
void _jlPutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
|
void _jlPutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
|
||||||
|
@ -173,7 +174,6 @@ void _jlPutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
static void _jlAudioCallback(void *userdata, Uint8 *buffer, int bytes) {
|
static void _jlAudioCallback(void *userdata, Uint8 *buffer, int bytes) {
|
||||||
|
@ -257,44 +257,89 @@ static void _jlAudioCallback(void *userdata, Uint8 *buffer, int bytes) {
|
||||||
|
|
||||||
|
|
||||||
void jlDisplayPresent(void) {
|
void jlDisplayPresent(void) {
|
||||||
int i = 0;
|
|
||||||
int j = 0;
|
|
||||||
Uint16 *pixels = NULL;
|
|
||||||
SDL_Rect r;
|
|
||||||
|
|
||||||
jlUtilIdle();
|
jlUtilIdle();
|
||||||
|
|
||||||
// Render 4 bit copy to proper pixel format.
|
jint16 sourceX;
|
||||||
// This extra step preserves palette effects.
|
jint16 sourceY;
|
||||||
SDL_LockSurface(_jlTexture);
|
jint16 targetX;
|
||||||
pixels = (Uint16 *)_jlTexture->pixels;
|
jint16 targetY;
|
||||||
for (int y=0; y<200; y++) {
|
juint16 pixelLeft;
|
||||||
for (int x=0; x<160; x++) {
|
juint16 pixelRight;
|
||||||
// We decode this R/L instead of L/R for some reason. NO idea why yet. Endians?
|
juint16 p = 0;
|
||||||
pixels[i++] = SDL_MapRGBA(_jlTexture->format,
|
|
||||||
_jlBackingStore->palette[_jlBackingStore->pixels[j].r].r * 16,
|
SDL_LockSurface(_jlWindow);
|
||||||
_jlBackingStore->palette[_jlBackingStore->pixels[j].r].g * 16,
|
|
||||||
_jlBackingStore->palette[_jlBackingStore->pixels[j].r].b * 16,
|
|
||||||
255);
|
|
||||||
pixels[i++] = SDL_MapRGBA(_jlTexture->format,
|
|
||||||
_jlBackingStore->palette[_jlBackingStore->pixels[j].l].r * 16,
|
|
||||||
_jlBackingStore->palette[_jlBackingStore->pixels[j].l].g * 16,
|
|
||||||
_jlBackingStore->palette[_jlBackingStore->pixels[j].l].b * 16,
|
|
||||||
255);
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SDL_UnlockSurface(_jlTexture);
|
|
||||||
|
|
||||||
// Border.
|
// Border.
|
||||||
SDL_FillRect(_jlWindow, NULL, SDL_MapRGB(_jlWindow->format, _jlBorderRGBs[_jlBorderColor][0], _jlBorderRGBs[_jlBorderColor][1], _jlBorderRGBs[_jlBorderColor][2]));
|
SDL_FillRect(_jlWindow, NULL, SDL_MapRGB(_jlWindow->format, _jlBorderRGBs[_jlBorderColor][0], _jlBorderRGBs[_jlBorderColor][1], _jlBorderRGBs[_jlBorderColor][2]));
|
||||||
|
|
||||||
// Display.
|
// Render 4 bit copy to proper pixel format.
|
||||||
r.x = _jlWindowZoom * BORDER_WIDTH;
|
// This extra step preserves palette effects.
|
||||||
r.y = _jlWindowZoom * BORDER_WIDTH;
|
targetY = _jlWindowZoom * BORDER_WIDTH;
|
||||||
r.w = 320 * _jlWindowZoom;
|
for (sourceY = 0; sourceY < 200; sourceY++) {
|
||||||
r.h = 200 * _jlWindowZoom;
|
targetX = _jlWindowZoom * BORDER_WIDTH;
|
||||||
SDL_BlitSurface(_jlTexture, NULL, _jlWindow, &r);
|
for (sourceX = 0; sourceX < 160; sourceX++) {
|
||||||
|
// We decode this R/L instead of L/R for some reason. NO idea why yet. Endians?
|
||||||
|
pixelLeft = SDL_MapRGBA(_jlWindow->format,
|
||||||
|
_jlBackingStore->palette[_jlBackingStore->pixels[p].r].r * 16,
|
||||||
|
_jlBackingStore->palette[_jlBackingStore->pixels[p].r].g * 16,
|
||||||
|
_jlBackingStore->palette[_jlBackingStore->pixels[p].r].b * 16,
|
||||||
|
255);
|
||||||
|
pixelRight = SDL_MapRGBA(_jlWindow->format,
|
||||||
|
_jlBackingStore->palette[_jlBackingStore->pixels[p].l].r * 16,
|
||||||
|
_jlBackingStore->palette[_jlBackingStore->pixels[p].l].g * 16,
|
||||||
|
_jlBackingStore->palette[_jlBackingStore->pixels[p].l].b * 16,
|
||||||
|
255);
|
||||||
|
// Copy to display. SDL 1.2 does not scale surfaces, so we have to do it manually.
|
||||||
|
switch (_jlWindowZoom) {
|
||||||
|
case 1:
|
||||||
|
_jlPutPixel(_jlWindow, targetX, targetY, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 1, targetY, pixelRight);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
_jlPutPixel(_jlWindow, targetX, targetY, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 1, targetY, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX, targetY + 1, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 1, targetY + 1, pixelLeft);
|
||||||
|
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 2, targetY, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 3, targetY, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 2, targetY + 1, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 3, targetY + 1, pixelRight);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// There is no way this is efficient.
|
||||||
|
_jlPutPixel(_jlWindow, targetX, targetY, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 1, targetY, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 2, targetY, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX, targetY + 1, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 1, targetY + 1, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 2, targetY + 1, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX, targetY + 2, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 1, targetY + 2, pixelLeft);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 2, targetY + 2, pixelLeft);
|
||||||
|
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 3, targetY, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 4, targetY, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 5, targetY, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 3, targetY + 1, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 4, targetY + 1, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 5, targetY + 1, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 3, targetY + 2, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 4, targetY + 2, pixelRight);
|
||||||
|
_jlPutPixel(_jlWindow, targetX + 5, targetY + 2, pixelRight);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Increment pixel locations.
|
||||||
|
p++;
|
||||||
|
targetX += _jlWindowZoom + _jlWindowZoom;
|
||||||
|
}
|
||||||
|
targetY += _jlWindowZoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_UnlockSurface(_jlWindow);
|
||||||
SDL_Flip(_jlWindow);
|
SDL_Flip(_jlWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue