#include#include int main() { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFOEX csbi; csbi.cbSize = sizeof(csbi); GetConsoleScreenBufferInfoEx(hConsole, &csbi); csbi.wAttributes = FOREGROUND_BLUE | BACKGROUND_GREEN; csbi.wAttributes |= (128 << 8); // set alpha value to 128 SetConsoleScreenBufferInfoEx(hConsole, &csbi); std::cout << "Hello, world!" << std::endl; return 0; }
#includeThis code creates an SDL2 window with a red background color that has an alpha value of 128. We set the renderer's blend mode to be "blend", which enables alpha blending. We then clear the renderer with the transparent red color and present it to the window. Finally, we delay for 5 seconds before closing the window and quitting SDL. Package/library: SDL2.#include int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Window* window = SDL_CreateWindow("My Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN); SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(renderer, 255, 0, 0, 128); // set alpha value to 128 SDL_RenderClear(renderer); SDL_RenderPresent(renderer); SDL_Delay(5000); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return 0; }