Reputation: 21
This code shows just a simple window with a color:
#include<SDL.h>
SDL_Window* g_pWindow = 0;
SDL_Renderer* g_pRenderer = 0;
int main(int argc, char* args[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) >= 0)
{
g_pWindow = SDL_CreateWindow("Chapter 1: Setting up SDL",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_SHOWN);
if (g_pWindow != 0)
{
g_pRenderer = SDL_CreateRenderer(g_pWindow, -1, 0);
}
}
else
{
return 1; // sdl could not initialize
}
SDL_SetRenderDrawColor(g_pRenderer, 80, 80, 253, 0);
// clear the window to black
SDL_RenderClear(g_pRenderer);
// show the window
SDL_RenderPresent(g_pRenderer);
// set a delay before quitting
SDL_Delay(2000);
// clean up SDL
SDL_Quit();
return 0;
}
I'm testing to see what happens when I change the alpha factor in SDL_SetRenderDrawColor(g_pRenderer, 80, 80, 253, 0)
. When I change the alpha value from 0 to 255 it doesn't effect anything.
What's the problem here?
Upvotes: 1
Views: 3775
Reputation: 103
Writing this line will make alpha values have effect on transparency:
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
No need to rewrite every time & for every effert, just write once before using transparency
see documentation on more blend modes: https://wiki.libsdl.org/SDL2/SDL_BlendMode
Upvotes: 0
Reputation: 18409
First of all, you haven't enabled blending (e.g. SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
).
But anyway, it makes no sense for clear
operation to use blending, and I bet SDL_RenderClear
ignores it.
If you want fullscreen blend, you should draw fullscreen rectangle with SDL_RenderFillRect
.
Upvotes: 4