mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Use SDL_Color for colors instead of colourTransform
colourTransform is a struct with only one member, a Uint32. The issue with `Uint32`s is that it requires a bunch of bit shifting logic to edit the colors. The issue with bit shifting logic is that people have a tendency to hardcode the shift amounts instead of using the shift amount variables of the SDL_PixelFormat, which makes it annoying to change the color masks of surfaces. This commit fixes both issues by unhardcoding the bit shift amounts in DrawPixel and ReadPixel, and by axing the `Uint32`s in favor of using SDL_Color. According to the SDL_PixelFormat documentation ( https://wiki.libsdl.org/SDL2/SDL_PixelFormat ), the logic to read and draw to pixels from colors below 32-bit was just wrong. Specifically, for 8-bit, there's a color palette used instead of some intrinsic color information stored in the pixel itself. But we shouldn't need that logic anyways because we don't use colors below 32-bit. So I axed that too.
This commit is contained in:
parent
f24265f0fb
commit
351a022ebd
13 changed files with 309 additions and 327 deletions
|
@ -1604,7 +1604,7 @@ void customlevelclass::generatecustomminimap(void)
|
|||
|
||||
// Return a graphics-ready color based off of the given tileset and tilecol
|
||||
// Much kudos to Dav999 for saving me a lot of work, because I stole these colors from const.lua in Ved! -Info Teddy
|
||||
Uint32 customlevelclass::getonewaycol(const int rx, const int ry)
|
||||
SDL_Color customlevelclass::getonewaycol(const int rx, const int ry)
|
||||
{
|
||||
const RoomProperty* const room = getroomprop(rx, ry);
|
||||
switch (room->tileset) {
|
||||
|
@ -1763,7 +1763,7 @@ Uint32 customlevelclass::getonewaycol(const int rx, const int ry)
|
|||
}
|
||||
|
||||
// This version detects the room automatically
|
||||
Uint32 customlevelclass::getonewaycol(void)
|
||||
SDL_Color customlevelclass::getonewaycol(void)
|
||||
{
|
||||
#ifndef NO_EDITOR
|
||||
if (game.gamestate == EDITORMODE)
|
||||
|
|
|
@ -155,8 +155,8 @@ public:
|
|||
|
||||
int version;
|
||||
|
||||
Uint32 getonewaycol(const int rx, const int ry);
|
||||
Uint32 getonewaycol(void);
|
||||
SDL_Color getonewaycol(int rx, int ry);
|
||||
SDL_Color getonewaycol(void);
|
||||
bool onewaycol_override;
|
||||
};
|
||||
|
||||
|
|
|
@ -279,20 +279,20 @@ static int edentat( int xp, int yp )
|
|||
return -1;
|
||||
}
|
||||
|
||||
static void fillbox( int x, int y, int x2, int y2, int c )
|
||||
static void fillbox(const int x, const int y, const int x2, const int y2, const SDL_Color color)
|
||||
{
|
||||
FillRect(graphics.backBuffer, x, y, x2-x, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y2-1, x2-x, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2-y, c);
|
||||
FillRect(graphics.backBuffer, x2-1, y, 1, y2-y, c);
|
||||
FillRect(graphics.backBuffer, x, y, x2-x, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y2-1, x2-x, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2-y, color);
|
||||
FillRect(graphics.backBuffer, x2-1, y, 1, y2-y, color);
|
||||
}
|
||||
|
||||
static void fillboxabs( int x, int y, int x2, int y2, int c )
|
||||
static void fillboxabs(const int x, const int y, const int x2, const int y2, const SDL_Color color)
|
||||
{
|
||||
FillRect(graphics.backBuffer, x, y, x2, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y+y2-1, x2, 1, c);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2, c);
|
||||
FillRect(graphics.backBuffer, x+x2-1, y, 1, y2, c);
|
||||
FillRect(graphics.backBuffer, x, y, x2, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y+y2-1, x2, 1, color);
|
||||
FillRect(graphics.backBuffer, x, y, 1, y2, color);
|
||||
FillRect(graphics.backBuffer, x+x2-1, y, 1, y2, color);
|
||||
}
|
||||
|
||||
|
||||
|
@ -595,8 +595,7 @@ void editorrender(void)
|
|||
|
||||
// Special case for drawing gray entities
|
||||
bool custom_gray = room->tileset == 3 && room->tilecol == 6;
|
||||
colourTransform gray_ct;
|
||||
gray_ct.colour = 0xFFFFFFFF;
|
||||
const SDL_Color gray_ct = {255, 255, 255, 255};
|
||||
|
||||
// Draw entities backward to remain accurate with ingame
|
||||
for (int i = customentities.size() - 1; i >= 0; i--)
|
||||
|
@ -610,9 +609,10 @@ void editorrender(void)
|
|||
switch(customentities[i].t)
|
||||
{
|
||||
case 1: //Entities
|
||||
if (custom_gray) {
|
||||
if (custom_gray)
|
||||
{
|
||||
graphics.setcol(18);
|
||||
ed.entcolreal = graphics.ct.colour;
|
||||
ed.entcolreal = graphics.ct;
|
||||
}
|
||||
graphics.drawsprite((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),ed.getenemyframe(room->enemytype),ed.entcolreal);
|
||||
if(customentities[i].p1==0) graphics.Print((customentities[i].x*8)- (ed.levx*40*8)+4,(customentities[i].y*8)- (ed.levy*30*8)+4, "V", 255, 255, 255 - help.glow, false);
|
||||
|
@ -933,10 +933,8 @@ void editorrender(void)
|
|||
tpoint.x = ed.ghosts[i].x;
|
||||
tpoint.y = ed.ghosts[i].y;
|
||||
graphics.setcolreal(ed.ghosts[i].realcol);
|
||||
Uint32 alpha = graphics.ct.colour & graphics.backBuffer->format->Amask;
|
||||
Uint32 therest = graphics.ct.colour & 0x00FFFFFF;
|
||||
alpha = (3 * (alpha >> 24) / 4) << 24;
|
||||
graphics.ct.colour = therest | alpha;
|
||||
const int alpha = 3 * graphics.ct.a / 4;
|
||||
graphics.ct.a = (Uint8) alpha;
|
||||
SDL_Rect drawRect = graphics.sprites_rect;
|
||||
drawRect.x += tpoint.x;
|
||||
drawRect.y += tpoint.y;
|
||||
|
@ -1607,7 +1605,7 @@ void editorrenderfixed(void)
|
|||
ed.entcol=cl.getenemycol(game.customcol);
|
||||
|
||||
graphics.setcol(ed.entcol);
|
||||
ed.entcolreal = graphics.ct.colour;
|
||||
ed.entcolreal = graphics.ct;
|
||||
|
||||
if (game.ghostsenabled)
|
||||
{
|
||||
|
@ -1621,7 +1619,7 @@ void editorrenderfixed(void)
|
|||
}
|
||||
|
||||
graphics.setcol(ghost.col);
|
||||
ghost.realcol = graphics.ct.colour;
|
||||
ghost.realcol = graphics.ct;
|
||||
}
|
||||
|
||||
if (ed.currentghosts + 1 < (int)ed.ghosts.size()) {
|
||||
|
|
|
@ -42,7 +42,7 @@ struct GhostInfo
|
|||
int x; // .xp
|
||||
int y; // .yp
|
||||
int col; // .colour
|
||||
Uint32 realcol;
|
||||
SDL_Color realcol;
|
||||
int frame; // .drawframe
|
||||
};
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
void switch_warpdir(const bool reversed);
|
||||
|
||||
int entcol;
|
||||
Uint32 entcolreal;
|
||||
SDL_Color entcolreal;
|
||||
|
||||
int kludgewarpdir[customlevelclass::numrooms];
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ void entclass::clear(void)
|
|||
dir = 0;
|
||||
actionframe = 0;
|
||||
|
||||
realcol = 0;
|
||||
SDL_zero(realcol);
|
||||
lerpoldxp = 0;
|
||||
lerpoldyp = 0;
|
||||
}
|
||||
|
@ -618,14 +618,14 @@ void entclass::updatecolour(void)
|
|||
case 10: // 2x1 Sprite
|
||||
case 13: // Special for epilogue: huge hero!
|
||||
graphics.setcol(colour);
|
||||
realcol = graphics.ct.colour;
|
||||
realcol = graphics.ct;
|
||||
break;
|
||||
case 3: // Big chunky pixels!
|
||||
realcol = graphics.bigchunkygetcol(colour);
|
||||
break;
|
||||
case 4: // Small pickups
|
||||
graphics.huetilesetcol(colour);
|
||||
realcol = graphics.ct.colour;
|
||||
realcol = graphics.ct;
|
||||
break;
|
||||
case 11: // The fucking elephant
|
||||
if (game.noflashingmode)
|
||||
|
@ -636,7 +636,7 @@ void entclass::updatecolour(void)
|
|||
{
|
||||
graphics.setcol(colour);
|
||||
}
|
||||
realcol = graphics.ct.colour;
|
||||
realcol = graphics.ct;
|
||||
break;
|
||||
case 12: // Regular sprites that don't wrap
|
||||
// if we're outside the screen, we need to draw indicators
|
||||
|
@ -648,7 +648,7 @@ void entclass::updatecolour(void)
|
|||
{
|
||||
graphics.setcol(colour);
|
||||
}
|
||||
realcol = graphics.ct.colour;
|
||||
realcol = graphics.ct;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
int visualonground, visualonroof;
|
||||
int yp;int xp;
|
||||
|
||||
Uint32 realcol;
|
||||
SDL_Color realcol;
|
||||
int lerpoldxp, lerpoldyp;
|
||||
};
|
||||
|
||||
|
|
|
@ -84,8 +84,8 @@ void Graphics::init(void)
|
|||
backgrounddrawn = false;
|
||||
|
||||
warpskip = 0;
|
||||
warpfcol = 0x000000;
|
||||
warpbcol = 0x000000;
|
||||
SDL_zero(warpfcol);
|
||||
SDL_zero(warpbcol);
|
||||
|
||||
spcol = 0;
|
||||
spcoldel = 0;
|
||||
|
@ -106,7 +106,7 @@ void Graphics::init(void)
|
|||
|
||||
// initialize everything else to zero
|
||||
backBuffer = NULL;
|
||||
ct = colourTransform();
|
||||
SDL_zero(ct);
|
||||
foregrounddrawn = false;
|
||||
foregroundBuffer = NULL;
|
||||
backgrounddrawn = false;
|
||||
|
@ -132,15 +132,15 @@ void Graphics::init(void)
|
|||
screenshake_x = 0;
|
||||
screenshake_y = 0;
|
||||
|
||||
col_crewred = 0x00000000;
|
||||
col_crewyellow = 0x00000000;
|
||||
col_crewgreen = 0x00000000;
|
||||
col_crewcyan = 0x00000000;
|
||||
col_crewblue = 0x00000000;
|
||||
col_crewpurple = 0x00000000;
|
||||
col_crewinactive = 0x00000000;
|
||||
col_clock = 0x00000000;
|
||||
col_trinket = 0x00000000;
|
||||
SDL_zero(col_crewred);
|
||||
SDL_zero(col_crewyellow);
|
||||
SDL_zero(col_crewgreen);
|
||||
SDL_zero(col_crewcyan);
|
||||
SDL_zero(col_crewblue);
|
||||
SDL_zero(col_crewpurple);
|
||||
SDL_zero(col_crewinactive);
|
||||
SDL_zero(col_clock);
|
||||
SDL_zero(col_trinket);
|
||||
col_tr = 0;
|
||||
col_tg = 0;
|
||||
col_tb = 0;
|
||||
|
@ -199,12 +199,12 @@ void Graphics::create_buffers(const SDL_PixelFormat* fmt)
|
|||
footerbuffer = CREATE_SURFACE(320, 10);
|
||||
SDL_SetSurfaceBlendMode(footerbuffer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetSurfaceAlphaMod(footerbuffer, 127);
|
||||
FillRect(footerbuffer, SDL_MapRGB(fmt, 0, 0, 0));
|
||||
FillRect(footerbuffer, 0, 0, 0);
|
||||
|
||||
roomname_translator::dimbuffer = CREATE_SURFACE(320, 240);
|
||||
SDL_SetSurfaceBlendMode(roomname_translator::dimbuffer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetSurfaceAlphaMod(roomname_translator::dimbuffer, 96);
|
||||
FillRect(roomname_translator::dimbuffer, SDL_MapRGB(fmt, 0, 0, 0));
|
||||
FillRect(roomname_translator::dimbuffer, 0, 0, 0);
|
||||
|
||||
ghostbuffer = CREATE_SURFACE(320, 240);
|
||||
SDL_SetSurfaceBlendMode(ghostbuffer, SDL_BLENDMODE_BLEND);
|
||||
|
@ -299,24 +299,24 @@ void Graphics::drawspritesetcol(int x, int y, int t, int c)
|
|||
void Graphics::updatetitlecolours(void)
|
||||
{
|
||||
setcol(15);
|
||||
col_crewred = ct.colour;
|
||||
col_crewred = ct;
|
||||
setcol(14);
|
||||
col_crewyellow = ct.colour;
|
||||
col_crewyellow = ct;
|
||||
setcol(13);
|
||||
col_crewgreen = ct.colour;
|
||||
col_crewgreen = ct;
|
||||
setcol(0);
|
||||
col_crewcyan = ct.colour;
|
||||
col_crewcyan = ct;
|
||||
setcol(16);
|
||||
col_crewblue = ct.colour;
|
||||
col_crewblue = ct;
|
||||
setcol(20);
|
||||
col_crewpurple = ct.colour;
|
||||
col_crewpurple = ct;
|
||||
setcol(19);
|
||||
col_crewinactive = ct.colour;
|
||||
col_crewinactive = ct;
|
||||
|
||||
setcol(18);
|
||||
col_clock = ct.colour;
|
||||
col_clock = ct;
|
||||
setcol(18);
|
||||
col_trinket = ct.colour;
|
||||
col_trinket = ct;
|
||||
}
|
||||
|
||||
#define PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
||||
|
@ -496,7 +496,7 @@ static void print_char(
|
|||
const int x,
|
||||
const int y,
|
||||
const int scale,
|
||||
colourTransform& ct
|
||||
const SDL_Color color
|
||||
) {
|
||||
SDL_Rect font_rect = {x, y, 8*scale, 8*scale};
|
||||
SDL_Surface* surface;
|
||||
|
@ -514,7 +514,7 @@ static void print_char(
|
|||
surface = font;
|
||||
}
|
||||
|
||||
BlitSurfaceColoured(surface, NULL, buffer, &font_rect, ct);
|
||||
BlitSurfaceColoured(surface, NULL, buffer, &font_rect, color);
|
||||
|
||||
if (scale > 1)
|
||||
{
|
||||
|
@ -542,7 +542,7 @@ void Graphics::do_print(
|
|||
b = SDL_clamp(b, 0, 255);
|
||||
a = SDL_clamp(a, 0, 255);
|
||||
|
||||
ct.colour = getRGBA(r, g, b, a);
|
||||
ct = getRGBA(r, g, b, a);
|
||||
|
||||
while (iter != text.end())
|
||||
{
|
||||
|
@ -1033,7 +1033,7 @@ void Graphics::drawsprite( int x, int y, int t, int r, int g, int b )
|
|||
BlitSurfaceColoured(sprites[t], NULL, backBuffer, &rect, ct);
|
||||
}
|
||||
|
||||
void Graphics::drawsprite(int x, int y, int t, Uint32 c)
|
||||
void Graphics::drawsprite(int x, int y, int t, const SDL_Color color)
|
||||
{
|
||||
if (!INBOUNDS_VEC(t, sprites))
|
||||
{
|
||||
|
@ -1042,7 +1042,7 @@ void Graphics::drawsprite(int x, int y, int t, Uint32 c)
|
|||
}
|
||||
|
||||
SDL_Rect rect = {x, y, sprites_rect.w, sprites_rect.h};
|
||||
setcolreal(c);
|
||||
setcolreal(color);
|
||||
BlitSurfaceColoured(sprites[t], NULL, backBuffer, &rect, ct);
|
||||
}
|
||||
|
||||
|
@ -1068,7 +1068,7 @@ void Graphics::drawtile( int x, int y, int t )
|
|||
#if !defined(NO_CUSTOM_LEVELS)
|
||||
if (shouldrecoloroneway(t, tiles1_mounted))
|
||||
{
|
||||
colourTransform thect = {cl.getonewaycol()};
|
||||
const SDL_Color thect = cl.getonewaycol();
|
||||
BlitSurfaceTinted(tiles[t], NULL, backBuffer, &rect, thect);
|
||||
}
|
||||
else
|
||||
|
@ -1092,7 +1092,7 @@ void Graphics::drawtile2( int x, int y, int t )
|
|||
#if !defined(NO_CUSTOM_LEVELS)
|
||||
if (shouldrecoloroneway(t, tiles2_mounted))
|
||||
{
|
||||
colourTransform thect = {cl.getonewaycol()};
|
||||
const SDL_Color thect = cl.getonewaycol();
|
||||
BlitSurfaceTinted(tiles2[t], NULL, backBuffer, &rect, thect);
|
||||
}
|
||||
else
|
||||
|
@ -1431,14 +1431,14 @@ void Graphics::cutscenebars(void)
|
|||
const int usethispos = lerp(oldcutscenebarspos, cutscenebarspos);
|
||||
if (showcutscenebars)
|
||||
{
|
||||
FillRect(backBuffer, 0, 0, usethispos, 16, 0x000000);
|
||||
FillRect(backBuffer, 360-usethispos, 224, usethispos, 16, 0x000000);
|
||||
FillRect(backBuffer, 0, 0, usethispos, 16, 0, 0, 0);
|
||||
FillRect(backBuffer, 360-usethispos, 224, usethispos, 16, 0, 0, 0);
|
||||
}
|
||||
else if (cutscenebarspos > 0) //disappearing
|
||||
{
|
||||
//draw
|
||||
FillRect(backBuffer, 0, 0, usethispos, 16, 0x000000);
|
||||
FillRect(backBuffer, 360-usethispos, 224, usethispos, 16, 0x000000);
|
||||
FillRect(backBuffer, 0, 0, usethispos, 16, 0, 0, 0);
|
||||
FillRect(backBuffer, 360-usethispos, 224, usethispos, 16, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1702,13 +1702,13 @@ void Graphics::drawfade(void)
|
|||
case FADE_FADING_OUT:
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
FillRect(backBuffer, fadebars[i], i * 16, usethisamount, 16, 0x000000 );
|
||||
FillRect(backBuffer, fadebars[i], i * 16, usethisamount, 16, 0, 0, 0);
|
||||
}
|
||||
break;
|
||||
case FADE_FADING_IN:
|
||||
for (size_t i = 0; i < SDL_arraysize(fadebars); i++)
|
||||
{
|
||||
FillRect(backBuffer, fadebars[i]-usethisamount, i * 16, 500, 16, 0x000000 );
|
||||
FillRect(backBuffer, fadebars[i]-usethisamount, i * 16, 500, 16, 0, 0, 0);
|
||||
}
|
||||
break;
|
||||
case FADE_NONE:
|
||||
|
@ -1924,13 +1924,12 @@ bool Graphics::Hitest(SDL_Surface* surface1, point p1, SDL_Surface* surface2, po
|
|||
{
|
||||
for(int y = r3_bottom; y < r3_top; y++)
|
||||
{
|
||||
Uint32 pixel1 = ReadPixel(surface1 , x - p1.x, y - p1.y);
|
||||
Uint32 pixel2 = ReadPixel(surface2 , x - p2.x, y - p2.y);
|
||||
const SDL_Color pixel1 = ReadPixel(surface1, x - p1.x, y - p1.y);
|
||||
const SDL_Color pixel2 = ReadPixel(surface2, x - p2.x, y - p2.y);
|
||||
/* INTENTIONAL BUG! In previous versions, the game mistakenly
|
||||
* checked the red channel, not the alpha channel.
|
||||
* We preserve it here because some people abuse this. */
|
||||
if ((pixel1 & surface1->format->Rmask)
|
||||
&& (pixel2 & surface2->format->Rmask))
|
||||
if (pixel1.r != 0 && pixel2.r != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -2269,8 +2268,7 @@ void Graphics::drawentity(const int i, const int yoff)
|
|||
drawRect.x += 8 * ii;
|
||||
if (custom_gray)
|
||||
{
|
||||
colourTransform temp_ct;
|
||||
temp_ct.colour = 0xFFFFFFFF;
|
||||
const SDL_Color temp_ct = {255, 255, 255, 255};
|
||||
BlitSurfaceTinted(tilesvec[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, temp_ct);
|
||||
}
|
||||
else
|
||||
|
@ -2501,7 +2499,10 @@ void Graphics::drawbackground( int t )
|
|||
break;
|
||||
case 2:
|
||||
{
|
||||
int bcol = 0, bcol2 = 0;
|
||||
SDL_Color bcol;
|
||||
SDL_Color bcol2;
|
||||
SDL_zero(bcol);
|
||||
SDL_zero(bcol2);
|
||||
|
||||
//Lab
|
||||
switch(rcol)
|
||||
|
@ -3096,15 +3097,15 @@ void Graphics::setcol( int t )
|
|||
{
|
||||
//Player Normal
|
||||
case 0:
|
||||
ct.colour = getRGB(160- help.glow/2 - (fRandom()*20), 200- help.glow/2, 220 - help.glow);
|
||||
ct = getRGB(160 - help.glow/2 - (fRandom() * 20), 200 - help.glow/2, 220 - help.glow);
|
||||
break;
|
||||
//Player Hurt
|
||||
case 1:
|
||||
ct.colour = getRGB(196 - (fRandom() * 64), 10, 10);
|
||||
ct = getRGB(196 - (fRandom() * 64), 10, 10);
|
||||
break;
|
||||
//Enemies and stuff
|
||||
case 2:
|
||||
ct.colour = getRGB(225-(help.glow/2), 75, 30);
|
||||
ct = getRGB(225 - (help.glow / 2), 75, 30);
|
||||
break;
|
||||
case 3: //Trinket
|
||||
if (!trinketcolset)
|
||||
|
@ -3114,109 +3115,109 @@ void Graphics::setcol( int t )
|
|||
trinketb = 164 + (fRandom() * 60);
|
||||
trinketcolset = true;
|
||||
}
|
||||
ct.colour = getRGB(trinketr, trinketg, trinketb);
|
||||
ct = getRGB(trinketr, trinketg, trinketb);
|
||||
break;
|
||||
case 4: //Inactive savepoint
|
||||
{
|
||||
const int temp = (help.glow / 2) + (fRandom() * 8);
|
||||
ct.colour = getRGB(80 + temp, 80 + temp, 80 + temp);
|
||||
ct = getRGB(80 + temp, 80 + temp, 80 + temp);
|
||||
break;
|
||||
}
|
||||
case 5: //Active savepoint
|
||||
ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
|
||||
ct = getRGB(164 + (fRandom() * 64), 164 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
break;
|
||||
case 6: //Enemy : Red
|
||||
ct.colour = getRGB(250 - help.glow/2, 60- help.glow/2, 60 - help.glow/2);
|
||||
ct = getRGB(250 - help.glow/2, 60- help.glow/2, 60 - help.glow/2);
|
||||
break;
|
||||
case 7: //Enemy : Green
|
||||
ct.colour = getRGB(100 - help.glow/2 - (fRandom()*30), 250 - help.glow/2, 100 - help.glow/2 - (fRandom()*30));
|
||||
ct = getRGB(100 - help.glow/2 - (fRandom() * 30), 250 - help.glow/2, 100 - help.glow/2 - (fRandom() * 30));
|
||||
break;
|
||||
case 8: //Enemy : Purple
|
||||
ct.colour = getRGB(250 - help.glow/2, 20, 128 - help.glow/2 + (fRandom()*30));
|
||||
ct = getRGB(250 - help.glow/2, 20, 128 - help.glow/2 + (fRandom() * 30));
|
||||
break;
|
||||
case 9: //Enemy : Yellow
|
||||
ct.colour = getRGB(250 - help.glow/2, 250 - help.glow/2, 20);
|
||||
ct = getRGB(250 - help.glow/2, 250 - help.glow/2, 20);
|
||||
break;
|
||||
case 10: //Warp point (white)
|
||||
ct.colour = getRGB(255 - (fRandom() * 64), 255 - (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
ct = getRGB(255 - (fRandom() * 64), 255 - (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
break;
|
||||
case 11: //Enemy : Cyan
|
||||
ct.colour = getRGB(20, 250 - help.glow/2, 250 - help.glow/2);
|
||||
ct = getRGB(20, 250 - help.glow/2, 250 - help.glow/2);
|
||||
break;
|
||||
case 12: //Enemy : Blue
|
||||
ct.colour = getRGB(90- help.glow/2, 90 - help.glow/2, 250 - help.glow/2);
|
||||
ct = getRGB(90 - help.glow/2, 90 - help.glow/2, 250 - help.glow/2);
|
||||
break;
|
||||
//Crew Members
|
||||
//green
|
||||
case 13:
|
||||
ct.colour = getRGB(120- help.glow/4 - (fRandom()*20), 220 - help.glow/4, 120- help.glow/4);
|
||||
ct = getRGB(120 - help.glow/4 - (fRandom() * 20), 220 - help.glow/4, 120 - help.glow/4);
|
||||
break;
|
||||
//Yellow
|
||||
case 14:
|
||||
ct.colour = getRGB(220- help.glow/4 - (fRandom()*20), 210 - help.glow/4, 120- help.glow/4);
|
||||
ct = getRGB(220 - help.glow/4 - (fRandom() * 20), 210 - help.glow/4, 120 - help.glow/4);
|
||||
break;
|
||||
//pink
|
||||
case 15:
|
||||
ct.colour = getRGB(255 - help.glow/8, 70 - help.glow/4, 70 - help.glow / 4);
|
||||
ct = getRGB(255 - help.glow/8, 70 - help.glow/4, 70 - help.glow / 4);
|
||||
break;
|
||||
//Blue
|
||||
case 16:
|
||||
ct.colour = getRGB(75, 75, 255- help.glow/4 - (fRandom()*20));
|
||||
ct = getRGB(75, 75, 255 - help.glow/4 - (fRandom() * 20));
|
||||
break;
|
||||
|
||||
|
||||
case 17: //Enemy : Orange
|
||||
ct.colour = getRGB(250 - help.glow/2, 130 - help.glow/2, 20);
|
||||
ct = getRGB(250 - help.glow/2, 130 - help.glow/2, 20);
|
||||
break;
|
||||
case 18: //Enemy : Gray
|
||||
ct.colour = getRGB(130- help.glow/2, 130 - help.glow/2, 130 - help.glow/2);
|
||||
ct = getRGB(130 - help.glow/2, 130 - help.glow/2, 130 - help.glow/2);
|
||||
break;
|
||||
case 19: //Enemy : Dark gray
|
||||
ct.colour = getRGB(60- help.glow/8, 60 - help.glow/8, 60 - help.glow/8);
|
||||
ct = getRGB(60 - help.glow/8, 60 - help.glow/8, 60 - help.glow/8);
|
||||
break;
|
||||
//Purple
|
||||
case 20:
|
||||
ct.colour = getRGB(220 - help.glow / 4 - (fRandom() * 20), 120 - help.glow / 4, 210 - help.glow / 4);
|
||||
ct = getRGB(220 - help.glow/4 - (fRandom() * 20), 120 - help.glow/4, 210 - help.glow/4);
|
||||
break;
|
||||
|
||||
case 21: //Enemy : Light Gray
|
||||
ct.colour = getRGB(180- help.glow/2, 180 - help.glow/2, 180 - help.glow/2);
|
||||
ct = getRGB(180 - help.glow/2, 180 - help.glow/2, 180 - help.glow/2);
|
||||
break;
|
||||
case 22: //Enemy : Indicator Gray
|
||||
ct.colour = getRGB(230- help.glow/2, 230- help.glow/2, 230- help.glow/2);
|
||||
ct = getRGB(230 - help.glow/2, 230- help.glow/2, 230 - help.glow/2);
|
||||
break;
|
||||
case 23: //Enemy : Indicator Gray
|
||||
ct.colour = getRGB(255- help.glow/2 - (fRandom() * 40) , 255- help.glow/2 - (fRandom() * 40), 255- help.glow/2 - (fRandom() * 40));
|
||||
ct = getRGB(255 - help.glow/2 - (fRandom() * 40) , 255 - help.glow/2 - (fRandom() * 40), 255 - help.glow/2 - (fRandom() * 40));
|
||||
break;
|
||||
|
||||
//Trophies
|
||||
//cyan
|
||||
case 30:
|
||||
ct.colour = RGBf(160, 200, 220);
|
||||
ct = RGBf(160, 200, 220);
|
||||
break;
|
||||
//Purple
|
||||
case 31:
|
||||
ct.colour = RGBf(220, 120, 210);
|
||||
ct = RGBf(220, 120, 210);
|
||||
break;
|
||||
//Yellow
|
||||
case 32:
|
||||
ct.colour = RGBf(220, 210, 120);
|
||||
ct = RGBf(220, 210, 120);
|
||||
break;
|
||||
//red
|
||||
case 33:
|
||||
ct.colour = RGBf(255, 70, 70);
|
||||
ct = RGBf(255, 70, 70);
|
||||
break;
|
||||
//green
|
||||
case 34:
|
||||
ct.colour = RGBf(120, 220, 120);
|
||||
ct = RGBf(120, 220, 120);
|
||||
break;
|
||||
//Blue
|
||||
case 35:
|
||||
ct.colour = RGBf(75, 75, 255);
|
||||
ct = RGBf(75, 75, 255);
|
||||
break;
|
||||
//Gold
|
||||
case 36:
|
||||
ct.colour = getRGB(180, 120, 20);
|
||||
ct = getRGB(180, 120, 20);
|
||||
break;
|
||||
case 37: //Trinket
|
||||
if (!trinketcolset)
|
||||
|
@ -3226,15 +3227,15 @@ void Graphics::setcol( int t )
|
|||
trinketb = 164 + (fRandom() * 60);
|
||||
trinketcolset = true;
|
||||
}
|
||||
ct.colour = RGBf(trinketr, trinketg, trinketb);
|
||||
ct = RGBf(trinketr, trinketg, trinketb);
|
||||
break;
|
||||
//Silver
|
||||
case 38:
|
||||
ct.colour = RGBf(196, 196, 196);
|
||||
ct = RGBf(196, 196, 196);
|
||||
break;
|
||||
//Bronze
|
||||
case 39:
|
||||
ct.colour = RGBf(128, 64, 10);
|
||||
ct = RGBf(128, 64, 10);
|
||||
break;
|
||||
//Awesome
|
||||
case 40: //Teleporter in action!
|
||||
|
@ -3242,19 +3243,19 @@ void Graphics::setcol( int t )
|
|||
const int temp = fRandom() * 150;
|
||||
if(temp<33)
|
||||
{
|
||||
ct.colour = RGBf(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
ct = RGBf(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
}
|
||||
else if (temp < 66)
|
||||
{
|
||||
ct.colour = RGBf(64 + (fRandom() * 64), 255 - (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
ct = RGBf(64 + (fRandom() * 64), 255 - (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
}
|
||||
else if (temp < 100)
|
||||
{
|
||||
ct.colour = RGBf(64 + (fRandom() * 64), 64 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
ct = RGBf(64 + (fRandom() * 64), 64 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
}
|
||||
else
|
||||
{
|
||||
ct.colour = RGBf(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
|
||||
ct = RGBf(164 + (fRandom() * 64), 164 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3262,36 +3263,36 @@ void Graphics::setcol( int t )
|
|||
case 100: //Inactive Teleporter
|
||||
{
|
||||
const int temp = (help.glow / 2) + (fRandom() * 8);
|
||||
ct.colour = getRGB(42 + temp, 42 + temp, 42 + temp);
|
||||
ct = getRGB(42 + temp, 42 + temp, 42 + temp);
|
||||
break;
|
||||
}
|
||||
case 101: //Active Teleporter
|
||||
ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
|
||||
ct = getRGB(164 + (fRandom() * 64), 164 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
break;
|
||||
case 102: //Teleporter in action!
|
||||
{
|
||||
const int temp = fRandom() * 150;
|
||||
if (temp < 33)
|
||||
{
|
||||
ct.colour = getRGB(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
ct = getRGB(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
}
|
||||
else if (temp < 66)
|
||||
{
|
||||
ct.colour = getRGB(64 + (fRandom() * 64), 255 - (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
ct = getRGB(64 + (fRandom() * 64), 255 - (fRandom() * 64), 64 + (fRandom() * 64));
|
||||
}
|
||||
else if (temp < 100)
|
||||
{
|
||||
ct.colour = getRGB(64 + (fRandom() * 64), 64 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
ct = getRGB(64 + (fRandom() * 64), 64 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
}
|
||||
else
|
||||
{
|
||||
ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
|
||||
ct = getRGB(164 + (fRandom() * 64), 164 + (fRandom() * 64), 255 - (fRandom() * 64));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ct.colour = getRGB(255, 255, 255);
|
||||
ct = getRGB(255, 255, 255);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3341,7 +3342,7 @@ void Graphics::huetilesetcol(int t)
|
|||
}
|
||||
}
|
||||
|
||||
Uint32 Graphics::bigchunkygetcol(int t)
|
||||
SDL_Color Graphics::bigchunkygetcol(int t)
|
||||
{
|
||||
//A seperate index of colours, for simplicity
|
||||
switch (t)
|
||||
|
@ -3351,7 +3352,8 @@ Uint32 Graphics::bigchunkygetcol(int t)
|
|||
case 2:
|
||||
return getRGB(int(160- help.glow/2 - (fRandom()*20)), 200- help.glow/2, 220 - help.glow);
|
||||
}
|
||||
return 0x00000000;
|
||||
const SDL_Color color = {0, 0, 0, 0};
|
||||
return color;
|
||||
}
|
||||
|
||||
void Graphics::setwarprect( int a, int b, int c, int d )
|
||||
|
@ -3498,7 +3500,7 @@ int Graphics::crewcolour(const int t)
|
|||
|
||||
void Graphics::flashlight(void)
|
||||
{
|
||||
FillRect(backBuffer, 0xBBBBBBBB);
|
||||
FillRect(backBuffer, 0xBB, 0xBB, 0xBB, 0xBB);
|
||||
}
|
||||
|
||||
void Graphics::screenshake(void)
|
||||
|
@ -3608,7 +3610,7 @@ void Graphics::bigbrprint(int x, int y, const std::string& s, int r, int g, int
|
|||
bigrprint(x, y, s, r, g, b, cen, sc);
|
||||
}
|
||||
|
||||
void Graphics::drawtele(int x, int y, int t, Uint32 c)
|
||||
void Graphics::drawtele(int x, int y, int t, const SDL_Color color)
|
||||
{
|
||||
setcolreal(getRGB(16,16,16));
|
||||
|
||||
|
@ -3619,7 +3621,7 @@ void Graphics::drawtele(int x, int y, int t, Uint32 c)
|
|||
BlitSurfaceColoured(tele[0], NULL, backBuffer, &telerect, ct);
|
||||
}
|
||||
|
||||
setcolreal(c);
|
||||
setcolreal(color);
|
||||
if (t > 9) t = 8;
|
||||
if (t < 1) t = 1;
|
||||
|
||||
|
@ -3630,32 +3632,30 @@ void Graphics::drawtele(int x, int y, int t, Uint32 c)
|
|||
}
|
||||
}
|
||||
|
||||
Uint32 Graphics::getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
SDL_Color Graphics::getRGBA(const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a)
|
||||
{
|
||||
return SDL_MapRGBA(backBuffer->format, r, g, b, a);
|
||||
const SDL_Color color = {r, g, b, a};
|
||||
return color;
|
||||
}
|
||||
|
||||
Uint32 Graphics::getRGB(Uint8 r, Uint8 g, Uint8 b)
|
||||
SDL_Color Graphics::getRGB(const Uint8 r, const Uint8 g, const Uint8 b)
|
||||
{
|
||||
return SDL_MapRGB(backBuffer->format, r, g, b);
|
||||
const SDL_Color color = {r, g, b, 255};
|
||||
return color;
|
||||
}
|
||||
|
||||
Uint32 Graphics::getRGB(Uint32 _col)
|
||||
{
|
||||
return ( _col);
|
||||
}
|
||||
|
||||
Uint32 Graphics::RGBf(int r, int g, int b)
|
||||
SDL_Color Graphics::RGBf(int r, int g, int b)
|
||||
{
|
||||
r = (r + 128) / 3;
|
||||
g = (g + 128) / 3;
|
||||
b = (b + 128) / 3;
|
||||
return SDL_MapRGB(backBuffer->format, r, g, b);
|
||||
const SDL_Color color = {(Uint8) r, (Uint8) g, (Uint8) b, 255};
|
||||
return color;
|
||||
}
|
||||
|
||||
void Graphics::setcolreal(Uint32 t)
|
||||
void Graphics::setcolreal(const SDL_Color color)
|
||||
{
|
||||
ct.colour = t;
|
||||
ct = color;
|
||||
}
|
||||
|
||||
void Graphics::drawforetile(int x, int y, int t)
|
||||
|
@ -3672,7 +3672,7 @@ void Graphics::drawforetile(int x, int y, int t)
|
|||
#if !defined(NO_CUSTOM_LEVELS)
|
||||
if (shouldrecoloroneway(t, tiles1_mounted))
|
||||
{
|
||||
colourTransform thect = {cl.getonewaycol()};
|
||||
const SDL_Color thect = cl.getonewaycol();
|
||||
BlitSurfaceTinted(tiles[t], NULL, foregroundBuffer, &rect, thect);
|
||||
}
|
||||
else
|
||||
|
@ -3696,7 +3696,7 @@ void Graphics::drawforetile2(int x, int y, int t)
|
|||
#if !defined(NO_CUSTOM_LEVELS)
|
||||
if (shouldrecoloroneway(t, tiles2_mounted))
|
||||
{
|
||||
colourTransform thect = {cl.getonewaycol()};
|
||||
const SDL_Color thect = cl.getonewaycol();
|
||||
BlitSurfaceTinted(tiles2[t], NULL, foregroundBuffer, &rect, thect);
|
||||
}
|
||||
else
|
||||
|
@ -3800,7 +3800,7 @@ fail:
|
|||
return false;
|
||||
}
|
||||
|
||||
Uint32 Graphics::crewcolourreal(int t)
|
||||
SDL_Color Graphics::crewcolourreal(int t)
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
|
@ -3830,7 +3830,7 @@ void Graphics::render_roomname(const char* roomname, int r, int g, int b)
|
|||
}
|
||||
else
|
||||
{
|
||||
FillRect(backBuffer, footerrect, 0);
|
||||
FillRect(backBuffer, footerrect, 0, 0, 0);
|
||||
Print(5, 231, roomname, r, g, b, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "Game.h"
|
||||
#include "GraphicsResources.h"
|
||||
#include "GraphicsUtil.h"
|
||||
#include "Maths.h"
|
||||
#include "Textbox.h"
|
||||
#include "TowerBG.h"
|
||||
|
@ -42,7 +41,7 @@ public:
|
|||
|
||||
void drawhuetile(int x, int y, int t);
|
||||
void huetilesetcol(int t);
|
||||
Uint32 bigchunkygetcol(int t);
|
||||
SDL_Color bigchunkygetcol(int t);
|
||||
|
||||
void drawgravityline(int t);
|
||||
|
||||
|
@ -141,7 +140,7 @@ public:
|
|||
void drawgui(void);
|
||||
|
||||
void drawsprite(int x, int y, int t, int r, int g, int b);
|
||||
void drawsprite(int x, int y, int t, Uint32 c);
|
||||
void drawsprite(int x, int y, int t, SDL_Color color);
|
||||
|
||||
void printcrewname(int x, int y, int t);
|
||||
void printcrewnamedark(int x, int y, int t);
|
||||
|
@ -202,18 +201,15 @@ public:
|
|||
void bigbrprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
|
||||
|
||||
|
||||
void drawtele(int x, int y, int t, Uint32 c);
|
||||
void drawtele(int x, int y, int t, SDL_Color c);
|
||||
|
||||
Uint32 getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
SDL_Color getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
Uint32 getRGB(Uint8 r, Uint8 g, Uint8 b);
|
||||
SDL_Color getRGB(Uint8 r, Uint8 g, Uint8 b);
|
||||
|
||||
Uint32 getRGB(Uint32 _col);
|
||||
SDL_Color RGBf(int r, int g, int b);
|
||||
|
||||
|
||||
Uint32 RGBf(int r, int g, int b);
|
||||
|
||||
void setcolreal(Uint32 t);
|
||||
void setcolreal(SDL_Color color);
|
||||
|
||||
void drawbackground(int t);
|
||||
void updatebackground(int t);
|
||||
|
@ -263,7 +259,7 @@ public:
|
|||
void setcol(int t);
|
||||
void drawfinalmap(void);
|
||||
|
||||
colourTransform ct;
|
||||
SDL_Color ct;
|
||||
|
||||
int rcol;
|
||||
|
||||
|
@ -346,7 +342,9 @@ public:
|
|||
int backboxvy[numbackboxes];
|
||||
float backboxint[numbackboxes];
|
||||
|
||||
int warpskip, warpfcol, warpbcol;
|
||||
int warpskip;
|
||||
SDL_Color warpfcol;
|
||||
SDL_Color warpbcol;
|
||||
|
||||
bool translucentroomname;
|
||||
|
||||
|
@ -366,15 +364,15 @@ public:
|
|||
#endif
|
||||
float alpha;
|
||||
|
||||
Uint32 col_crewred;
|
||||
Uint32 col_crewyellow;
|
||||
Uint32 col_crewgreen;
|
||||
Uint32 col_crewcyan;
|
||||
Uint32 col_crewblue;
|
||||
Uint32 col_crewpurple; //actually pink
|
||||
Uint32 col_crewinactive;
|
||||
Uint32 col_clock;
|
||||
Uint32 col_trinket;
|
||||
SDL_Color col_crewred;
|
||||
SDL_Color col_crewyellow;
|
||||
SDL_Color col_crewgreen;
|
||||
SDL_Color col_crewcyan;
|
||||
SDL_Color col_crewblue;
|
||||
SDL_Color col_crewpurple; //actually pink
|
||||
SDL_Color col_crewinactive;
|
||||
SDL_Color col_clock;
|
||||
SDL_Color col_trinket;
|
||||
int col_tr;
|
||||
int col_tg;
|
||||
int col_tb;
|
||||
|
@ -382,7 +380,7 @@ public:
|
|||
|
||||
bool kludgeswnlinewidth;
|
||||
|
||||
Uint32 crewcolourreal(int t);
|
||||
SDL_Color crewcolourreal(int t);
|
||||
|
||||
void render_roomname(const char* roomname, int r, int g, int b);
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include "GraphicsUtil.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -91,62 +89,65 @@ SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, i
|
|||
return preSurface;
|
||||
}
|
||||
|
||||
static void DrawPixel( SDL_Surface *_surface, int x, int y, Uint32 pixel )
|
||||
static void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_Color color)
|
||||
{
|
||||
int bpp = _surface->format->BytesPerPixel;
|
||||
/* Here p is the address to the pixel we want to set */
|
||||
Uint8 *p = (Uint8 *)_surface->pixels + y * _surface->pitch + x * bpp;
|
||||
const SDL_PixelFormat* fmt = surface->format;
|
||||
const int bpp = fmt->BytesPerPixel;
|
||||
Uint32* pixel = (Uint32*) ((Uint8*) surface->pixels + y * surface->pitch + x * bpp);
|
||||
const Uint32 packed =
|
||||
(color.r << fmt->Rshift) |
|
||||
(color.g << fmt->Gshift) |
|
||||
(color.b << fmt->Bshift) |
|
||||
(color.a << fmt->Ashift);
|
||||
|
||||
switch (bpp)
|
||||
{
|
||||
case 1:
|
||||
*p = pixel;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
*(Uint16 *)p = pixel;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
p[0] = (pixel >> 16) & 0xff;
|
||||
p[1] = (pixel >> 8) & 0xff;
|
||||
p[2] = pixel & 0xff;
|
||||
break;
|
||||
SDL_assert(0 && "Non-32-bit colors not supported!");
|
||||
return;
|
||||
|
||||
case 4:
|
||||
*(Uint32 *)p = pixel;
|
||||
*pixel = packed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 ReadPixel( SDL_Surface *_surface, int x, int y )
|
||||
SDL_Color ReadPixel(const SDL_Surface* surface, const int x, const int y)
|
||||
{
|
||||
int bpp = _surface->format->BytesPerPixel;
|
||||
/* Here p is the address to the pixel we want to retrieve */
|
||||
Uint8 *p = (Uint8 *)_surface->pixels + y * _surface->pitch + x * bpp;
|
||||
const SDL_PixelFormat* fmt = surface->format;
|
||||
const int bpp = surface->format->BytesPerPixel;
|
||||
const Uint32* pixel = (Uint32*) ((Uint8*) surface->pixels + y * surface->pitch + x * bpp);
|
||||
|
||||
switch (bpp)
|
||||
{
|
||||
case 1:
|
||||
return *p;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
return *(Uint16 *)p;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
return p[0] | p[1] << 8 | p[2] << 16;
|
||||
{
|
||||
SDL_assert(0 && "Non-32-bit colors not supported!");
|
||||
const SDL_Color color = {0, 0, 0, 0};
|
||||
return color;
|
||||
}
|
||||
|
||||
case 4:
|
||||
return *(Uint32 *)p;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0; /* shouldn't happen, but avoids warnings */
|
||||
{
|
||||
const SDL_Color color = {
|
||||
(Uint8) ((*pixel & fmt->Rmask) >> fmt->Rshift),
|
||||
(Uint8) ((*pixel & fmt->Gmask) >> fmt->Gshift),
|
||||
(Uint8) ((*pixel & fmt->Bmask) >> fmt->Bshift),
|
||||
(Uint8) ((*pixel & fmt->Amask) >> fmt->Ashift)
|
||||
};
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
/* shouldn't happen, but avoids warnings */
|
||||
const SDL_Color color = {0, 0, 0, 0};
|
||||
return color;
|
||||
}
|
||||
|
||||
SDL_Surface * ScaleSurface( SDL_Surface *_surface, int Width, int Height, SDL_Surface * Dest )
|
||||
{
|
||||
if(!_surface || !Width || !Height)
|
||||
|
@ -199,95 +200,70 @@ void BlitSurfaceStandard( SDL_Surface* _src, SDL_Rect* _srcRect, SDL_Surface* _d
|
|||
}
|
||||
|
||||
void BlitSurfaceColoured(
|
||||
SDL_Surface* _src,
|
||||
SDL_Rect* _srcRect,
|
||||
SDL_Surface* _dest,
|
||||
SDL_Rect* _destRect,
|
||||
colourTransform& ct
|
||||
SDL_Surface* src,
|
||||
const SDL_Rect* src_rect,
|
||||
SDL_Surface* dest,
|
||||
SDL_Rect* dest_rect,
|
||||
const SDL_Color color
|
||||
) {
|
||||
SDL_Rect *tempRect = _destRect;
|
||||
|
||||
const SDL_PixelFormat& fmt = *(_src->format);
|
||||
|
||||
SDL_Surface* tempsurface = RecreateSurface(_src);
|
||||
SDL_Surface* tempsurface = RecreateSurface(src);
|
||||
|
||||
for (int x = 0; x < tempsurface->w; x++)
|
||||
{
|
||||
for (int y = 0; y < tempsurface->h; y++)
|
||||
{
|
||||
Uint32 pixel = ReadPixel(_src, x, y);
|
||||
Uint32 Alpha = pixel & fmt.Amask;
|
||||
Uint32 result = ct.colour & 0x00FFFFFF;
|
||||
Uint32 CTAlpha = ct.colour & fmt.Amask;
|
||||
float div1 = ((Alpha >> 24) / 255.0f);
|
||||
float div2 = ((CTAlpha >> 24) / 255.0f);
|
||||
Uint32 UseAlpha = (div1 * div2) * 255.0f;
|
||||
DrawPixel(tempsurface, x, y, result | (UseAlpha << 24));
|
||||
const SDL_Color pixel = ReadPixel(src, x, y);
|
||||
const float div1 = pixel.a / 255.0f;
|
||||
const float div2 = color.a / 255.0f;
|
||||
const Uint8 alpha = (div1 * div2) * 255.0f;
|
||||
const SDL_Color result = {color.r, color.g, color.b, alpha};
|
||||
DrawPixel(tempsurface, x, y, result);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_BlitSurface(tempsurface, _srcRect, _dest, tempRect);
|
||||
SDL_BlitSurface(tempsurface, src_rect, dest, dest_rect);
|
||||
VVV_freefunc(SDL_FreeSurface, tempsurface);
|
||||
}
|
||||
|
||||
void BlitSurfaceTinted(
|
||||
SDL_Surface* _src,
|
||||
SDL_Rect* _srcRect,
|
||||
SDL_Surface* _dest,
|
||||
SDL_Rect* _destRect,
|
||||
colourTransform& ct
|
||||
SDL_Surface* src,
|
||||
const SDL_Rect* src_rect,
|
||||
SDL_Surface* dest,
|
||||
SDL_Rect* dest_rect,
|
||||
const SDL_Color color
|
||||
) {
|
||||
SDL_Rect *tempRect = _destRect;
|
||||
SDL_Surface* tempsurface = RecreateSurface(src);
|
||||
|
||||
const SDL_PixelFormat& fmt = *(_src->format);
|
||||
for (int x = 0; x < tempsurface->w; x++)
|
||||
{
|
||||
for (int y = 0; y < tempsurface->h; y++)
|
||||
{
|
||||
const SDL_Color pixel = ReadPixel(src, x, y);
|
||||
|
||||
SDL_Surface* tempsurface = RecreateSurface(_src);
|
||||
double red = pixel.r * 0.299;
|
||||
double green = pixel.g * 0.587;
|
||||
double blue = pixel.b * 0.114;
|
||||
|
||||
for (int x = 0; x < tempsurface->w; x++) {
|
||||
for (int y = 0; y < tempsurface->h; y++) {
|
||||
Uint32 pixel = ReadPixel(_src, x, y);
|
||||
const double gray = SDL_floor(red + green + blue + 0.5);
|
||||
|
||||
Uint8 pixred = (pixel & _src->format->Rmask) >> 16;
|
||||
Uint8 pixgreen = (pixel & _src->format->Gmask) >> 8;
|
||||
Uint8 pixblue = (pixel & _src->format->Bmask) >> 0;
|
||||
red = gray * color.r / 255.0;
|
||||
green = gray * color.g / 255.0;
|
||||
blue = gray * color.b / 255.0;
|
||||
|
||||
double temp_pixred = pixred * 0.299;
|
||||
double temp_pixgreen = pixgreen * 0.587;
|
||||
double temp_pixblue = pixblue * 0.114;
|
||||
red = SDL_clamp(red, 0, 255);
|
||||
green = SDL_clamp(green, 0, 255);
|
||||
blue = SDL_clamp(blue, 0, 255);
|
||||
|
||||
double gray = SDL_floor((temp_pixred + temp_pixgreen + temp_pixblue + 0.5));
|
||||
const float div1 = pixel.a / 255.0f;
|
||||
const float div2 = color.a / 255.0f;
|
||||
const Uint8 alpha = (div1 * div2) * 255.0f;
|
||||
|
||||
Uint8 ctred = (ct.colour & graphics.backBuffer->format->Rmask) >> 16;
|
||||
Uint8 ctgreen = (ct.colour & graphics.backBuffer->format->Gmask) >> 8;
|
||||
Uint8 ctblue = (ct.colour & graphics.backBuffer->format->Bmask) >> 0;
|
||||
|
||||
temp_pixred = gray * ctred / 255.0;
|
||||
temp_pixgreen = gray * ctgreen / 255.0;
|
||||
temp_pixblue = gray * ctblue / 255.0;
|
||||
|
||||
if (temp_pixred > 255)
|
||||
temp_pixred = 255;
|
||||
if (temp_pixgreen > 255)
|
||||
temp_pixgreen = 255;
|
||||
if (temp_pixblue > 255)
|
||||
temp_pixblue = 255;
|
||||
|
||||
pixred = temp_pixred;
|
||||
pixgreen = temp_pixgreen;
|
||||
pixblue = temp_pixblue;
|
||||
|
||||
Uint32 Alpha = pixel & fmt.Amask;
|
||||
Uint32 result = (pixred << 16) + (pixgreen << 8) + (pixblue << 0);
|
||||
Uint32 CTAlpha = ct.colour & fmt.Amask;
|
||||
float div1 = ((Alpha >> 24) / 255.0f);
|
||||
float div2 = ((CTAlpha >> 24) / 255.0f);
|
||||
Uint32 UseAlpha = (div1 * div2) * 255.0f;
|
||||
|
||||
DrawPixel(tempsurface, x, y, result | (UseAlpha << 24));
|
||||
const SDL_Color result = {(Uint8) red, (Uint8) green, (Uint8) blue, alpha};
|
||||
DrawPixel(tempsurface, x, y, result);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_BlitSurface(tempsurface, _srcRect, _dest, tempRect);
|
||||
SDL_BlitSurface(tempsurface, src_rect, dest, dest_rect);
|
||||
VVV_freefunc(SDL_FreeSurface, tempsurface);
|
||||
}
|
||||
|
||||
|
@ -316,25 +292,25 @@ void UpdateFilter(void)
|
|||
}
|
||||
}
|
||||
|
||||
SDL_Surface* ApplyFilter( SDL_Surface* _src )
|
||||
SDL_Surface* ApplyFilter(SDL_Surface* src)
|
||||
{
|
||||
SDL_Surface* _ret = RecreateSurface(_src);
|
||||
SDL_Surface* ret = RecreateSurface(src);
|
||||
|
||||
int redOffset = rand() % 4;
|
||||
const int red_offset = rand() % 4;
|
||||
|
||||
for(int x = 0; x < _src->w; x++)
|
||||
for (int x = 0; x < ret->w; x++)
|
||||
{
|
||||
for(int y = 0; y < _src->h; y++)
|
||||
for (int y = 0; y < ret->h; y++)
|
||||
{
|
||||
int sampley = (y + (int) graphics.lerp(oldscrollamount, scrollamount) )% 240;
|
||||
const int sampley = (y + (int) graphics.lerp(oldscrollamount, scrollamount)) % 240;
|
||||
|
||||
Uint32 pixel = ReadPixel(_src, x,sampley);
|
||||
const SDL_Color pixel = ReadPixel(src, x, sampley);
|
||||
|
||||
Uint8 green = (pixel & _src->format->Gmask) >> 8;
|
||||
Uint8 blue = (pixel & _src->format->Bmask) >> 0;
|
||||
Uint8 green = pixel.g;
|
||||
Uint8 blue = pixel.b;
|
||||
|
||||
Uint32 pixelOffset = ReadPixel(_src, SDL_min(x+redOffset, 319), sampley) ;
|
||||
Uint8 red = (pixelOffset & _src->format->Rmask) >> 16 ;
|
||||
const SDL_Color pixel_offset = ReadPixel(src, SDL_min(x + red_offset, 319), sampley);
|
||||
Uint8 red = pixel_offset.r;
|
||||
|
||||
double mult;
|
||||
int tmp; /* needed to avoid char overflow */
|
||||
|
@ -356,24 +332,24 @@ SDL_Surface* ApplyFilter( SDL_Surface* _src )
|
|||
|
||||
if (y % 2 == 0)
|
||||
{
|
||||
red = static_cast<Uint8>(red / 1.2f);
|
||||
green = static_cast<Uint8>(green / 1.2f);
|
||||
blue = static_cast<Uint8>(blue / 1.2f);
|
||||
red = (Uint8) (red / 1.2f);
|
||||
green = (Uint8) (green / 1.2f);
|
||||
blue = (Uint8) (blue / 1.2f);
|
||||
}
|
||||
|
||||
int distX = static_cast<int>((SDL_abs (160.0f -x ) / 160.0f) *16);
|
||||
int distY = static_cast<int>((SDL_abs (120.0f -y ) / 120.0f)*32);
|
||||
int distX = (int) ((SDL_abs(160.0f - x) / 160.0f) * 16);
|
||||
int distY = (int) ((SDL_abs(120.0f - y) / 120.0f) * 32);
|
||||
|
||||
red = SDL_max(red - (distX + distY), 0);
|
||||
green = SDL_max(green - (distX + distY), 0);
|
||||
blue = SDL_max(blue - (distX + distY), 0);
|
||||
|
||||
Uint32 finalPixel = ((red<<16) + (green<<8) + (blue<<0)) | (pixel &_src->format->Amask);
|
||||
DrawPixel(_ret,x,y, finalPixel);
|
||||
const SDL_Color color = {red, green, blue, pixel.a};
|
||||
DrawPixel(ret, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return _ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FillRect( SDL_Surface* _surface, const int _x, const int _y, const int _w, const int _h, const int r, int g, int b )
|
||||
|
@ -389,26 +365,35 @@ void FillRect( SDL_Surface* _surface, const int r, int g, int b )
|
|||
SDL_FillRect(_surface, NULL, color);
|
||||
}
|
||||
|
||||
void FillRect( SDL_Surface* _surface, const int color )
|
||||
{
|
||||
SDL_FillRect(_surface, NULL, color);
|
||||
}
|
||||
|
||||
void FillRect( SDL_Surface* _surface, const int x, const int y, const int w, const int h, int rgba )
|
||||
{
|
||||
SDL_Rect rect = {x, y, w, h};
|
||||
SDL_FillRect(_surface, &rect, rgba);
|
||||
}
|
||||
|
||||
void FillRect( SDL_Surface* _surface, SDL_Rect& _rect, const int r, int g, int b )
|
||||
{
|
||||
Uint32 color = SDL_MapRGB(_surface->format, r, g, b);
|
||||
SDL_FillRect(_surface, &_rect, color);
|
||||
}
|
||||
|
||||
void FillRect( SDL_Surface* _surface, SDL_Rect rect, int rgba )
|
||||
void FillRect(SDL_Surface* surface, const SDL_Rect rect, const SDL_Color color)
|
||||
{
|
||||
SDL_FillRect(_surface, &rect, rgba);
|
||||
const Uint32 mapped = SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a);
|
||||
SDL_FillRect(surface, &rect, mapped);
|
||||
}
|
||||
|
||||
void FillRect(SDL_Surface* surface, const SDL_Color color)
|
||||
{
|
||||
const Uint32 mapped = SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a);
|
||||
SDL_FillRect(surface, NULL, mapped);
|
||||
}
|
||||
|
||||
void FillRect(SDL_Surface* surface, const int x, const int y, const int w, const int h, const SDL_Color color)
|
||||
{
|
||||
const SDL_Rect rect = {x, y, w, h};
|
||||
const Uint32 mapped = SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a);
|
||||
SDL_FillRect(surface, &rect, mapped);
|
||||
}
|
||||
|
||||
void FillRect(SDL_Surface* surface, const int r, const int g, const int b, const int a)
|
||||
{
|
||||
const Uint32 mapped = SDL_MapRGBA(surface->format, r, g, b, a);
|
||||
SDL_FillRect(surface, NULL, mapped);
|
||||
}
|
||||
|
||||
void ClearSurface(SDL_Surface* surface)
|
||||
|
|
|
@ -3,37 +3,33 @@
|
|||
|
||||
#include <SDL.h>
|
||||
|
||||
struct colourTransform
|
||||
{
|
||||
Uint32 colour;
|
||||
};
|
||||
|
||||
|
||||
void setRect(SDL_Rect& _r, int x, int y, int w, int h);
|
||||
|
||||
SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height );
|
||||
|
||||
Uint32 ReadPixel( SDL_Surface *surface, int x, int y );
|
||||
SDL_Color ReadPixel(const SDL_Surface* surface, int x, int y);
|
||||
|
||||
SDL_Surface * ScaleSurface( SDL_Surface *Surface, int Width, int Height, SDL_Surface * Dest = NULL );
|
||||
|
||||
void BlitSurfaceStandard( SDL_Surface* _src, SDL_Rect* _srcRect, SDL_Surface* _dest, SDL_Rect* _destRect );
|
||||
|
||||
void BlitSurfaceColoured( SDL_Surface* _src, SDL_Rect* _srcRect, SDL_Surface* _dest, SDL_Rect* _destRect, colourTransform& ct );
|
||||
void BlitSurfaceColoured(SDL_Surface* src, const SDL_Rect* src_rect, SDL_Surface* dest, SDL_Rect* dest_rect, SDL_Color color);
|
||||
|
||||
void BlitSurfaceTinted( SDL_Surface* _src, SDL_Rect* _srcRect, SDL_Surface* _dest, SDL_Rect* _destRect, colourTransform& ct );
|
||||
void BlitSurfaceTinted(SDL_Surface* src, const SDL_Rect* src_rect, SDL_Surface* dest, SDL_Rect* dest_rect, SDL_Color color);
|
||||
|
||||
void FillRect( SDL_Surface* surface, const int x, const int y, const int w, const int h, const int r, int g, int b );
|
||||
|
||||
void FillRect( SDL_Surface* surface, const int r, int g, int b );
|
||||
|
||||
void FillRect( SDL_Surface* surface, const int color );
|
||||
|
||||
void FillRect( SDL_Surface* surface, const int x, const int y, const int w, const int h, int rgba );
|
||||
|
||||
void FillRect( SDL_Surface* surface, SDL_Rect& rect, const int r, int g, int b );
|
||||
|
||||
void FillRect( SDL_Surface* surface, SDL_Rect rect, int rgba );
|
||||
void FillRect(SDL_Surface* surface, SDL_Rect rect, SDL_Color color);
|
||||
|
||||
void FillRect(SDL_Surface* surface, SDL_Color color);
|
||||
|
||||
void FillRect(SDL_Surface* surface, int x, int y, int w, int h, SDL_Color color);
|
||||
|
||||
void FillRect(SDL_Surface* surface, int r, int g, int b, int a);
|
||||
|
||||
void ClearSurface(SDL_Surface* surface);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "Game.h"
|
||||
#include "GlitchrunnerMode.h"
|
||||
#include "Graphics.h"
|
||||
#include "GraphicsUtil.h"
|
||||
#include "KeyPoll.h"
|
||||
#include "Localization.h"
|
||||
#include "LocalizationMaint.h"
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "FileSystemUtils.h"
|
||||
#include "Game.h"
|
||||
#include "Graphics.h"
|
||||
#include "GraphicsUtil.h"
|
||||
#include "Input.h"
|
||||
#include "InterimVersion.h"
|
||||
#include "KeyPoll.h"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "Enums.h"
|
||||
#include "Game.h"
|
||||
#include "Graphics.h"
|
||||
#include "GraphicsUtil.h"
|
||||
#include "Localization.h"
|
||||
#include "KeyPoll.h"
|
||||
#include "UtilityClass.h"
|
||||
|
@ -9,7 +10,9 @@
|
|||
|
||||
static int pre_fakepercent=0, pre_transition=30;
|
||||
static bool pre_startgame=false;
|
||||
static int pre_darkcol=0, pre_lightcol=0, pre_curcol=0, pre_coltimer=0, pre_offset=0;
|
||||
static SDL_Color pre_darkcol = {0, 0, 0, 0};
|
||||
static SDL_Color pre_lightcol = {0, 0, 0, 0};
|
||||
static int pre_curcol = 0, pre_coltimer = 0, pre_offset = 0;
|
||||
|
||||
static int pre_frontrectx=30, pre_frontrecty=20, pre_frontrectw=260, pre_frontrecth=200;
|
||||
static int pre_temprectx=0, pre_temprecty=0, pre_temprectw=320, pre_temprecth=240;
|
||||
|
|
Loading…
Reference in a new issue