mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-06-26 14:38:30 +02:00
So, earlier in the development of 2.0, Simon Roth (I presume) encountered a problem: Oh no, all my backgrounds aren't appearing! And this is because my foregroundBuffer, which contains all the drawn tiles, is drawing complete black over it! So he had a solution that seems ingenius, but is actually really really hacky and super 100% NOT the proper solution. Just, take the foregroundBuffer, iterate over each pixel, and DON'T draw any pixel that's 0xDEADBEEF. 0xDEADBEEF is a special signal meaning "don't draw this pixel". It is called a 'key'. Unfortunately, this causes a bug where translucent pixels on tiles (pixels between 0% and 100% opacity) didn't get drawn correctly. They would be drawn against this weird blue color. Now, in #103, I came across this weird constant and decided "hey, this looks awfully like that weird blue color I came across, maybe if I set it to 0x00000000, i.e. complete and transparent black, the issue will be fixed". And it DID appear to be fixed. However, I didn't look too closely, nor did I test it that much, and all that ended up doing was drawing the pixels against black, which more subtly disguised the problem with translucent pixels. So, after some investigation, I noticed that BlitSurfaceColoured() was drawing translucent pixels just fine. And I thought at the time that there was something wrong with BlitSurfaceStandard(), or something. Further along later I realized that all drawn tiles were passing through this weird OverlaySurfaceKeyed() function. And removing it in favor of a straight SDL_BlitSurface() produced the bug I mentioned above: Oh no, all the backgrounds don't show up, because my foregroundBuffer is drawing pure black over them! Well... just... set the proper blend mode for foregroundBuffer. It should be SDL_BLENDMODE_BLEND instead of SDL_BLENDMODE_NONE. Then you don't have to worry about your transparency at all. If you did it right, you won't have to resort this hacky color-keying business. *sigh*
51 lines
1.7 KiB
C
51 lines
1.7 KiB
C
#ifndef GRAPHICSUTIL_H
|
|
#define GRAPHICSUTIL_H
|
|
|
|
#include <SDL.h>
|
|
|
|
struct colourTransform
|
|
{
|
|
Uint32 colour;
|
|
};
|
|
|
|
|
|
void setRect(SDL_Rect& _r, int x, int y, int w, int h);
|
|
|
|
unsigned int endian_swap(unsigned int x);
|
|
|
|
SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height );
|
|
|
|
void DrawPixel( SDL_Surface *surface, int x, int y, Uint32 pixel );
|
|
|
|
Uint32 ReadPixel( 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 BlitSurfaceTinted( SDL_Surface* _src, SDL_Rect* _srcRect, SDL_Surface* _dest, SDL_Rect* _destRect, colourTransform& ct );
|
|
|
|
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 ScrollSurface(SDL_Surface* _src, int pX, int py);
|
|
|
|
SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src);
|
|
SDL_Surface * FlipSurfaceVerticle(SDL_Surface* _src);
|
|
SDL_Surface * ScaleSurfaceSlow( SDL_Surface *_surface, int Width, int Height );
|
|
void UpdateFilter();
|
|
SDL_Surface* ApplyFilter( SDL_Surface* _src );
|
|
|
|
#endif /* GRAPHICSUTIL_H */
|