Atlas - testsoftwaretransparent.c

Home / ext / SDL / test Lines: 1 | Size: 3433 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 3 4 This software is provided 'as-is', without any express or implied 5 warranty. In no event will the authors be held liable for any damages 6 arising from the use of this software. 7 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it 10 freely. 11*/ 12#include <SDL3/SDL.h> 13#include <SDL3/SDL_main.h> 14#include <SDL3/SDL_test.h> 15 16#define SQUARE_SIZE 100.0f 17 18/* Draw opaque red squares at the four corners of the form, and draw a red square with an alpha value of 180 in the center of the form */ 19static void draw(SDL_Renderer *renderer) 20{ 21 SDL_FRect rect = { 0.0f, 0.0f, SQUARE_SIZE, SQUARE_SIZE }; 22 int w, h; 23 24 SDL_GetCurrentRenderOutputSize(renderer, &w, &h); 25 26 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); 27 SDL_RenderClear(renderer); 28 29 if (w >= 3 * SQUARE_SIZE && h >= 3 * SQUARE_SIZE) { 30 SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); 31 32 rect.x = 0.0f; 33 rect.y = 0.0f; 34 SDL_RenderFillRect(renderer, &rect); 35 36 rect.y = h - SQUARE_SIZE; 37 SDL_RenderFillRect(renderer, &rect); 38 39 rect.x = w - SQUARE_SIZE; 40 SDL_RenderFillRect(renderer, &rect); 41 42 rect.y = 0.0f; 43 SDL_RenderFillRect(renderer, &rect); 44 } 45 46 SDL_SetRenderDrawColor(renderer, 255, 0, 0, 180); 47 rect.x = (w - SQUARE_SIZE) / 2; 48 rect.y = (h - SQUARE_SIZE) / 2; 49 SDL_RenderFillRect(renderer, &rect); 50} 51 52int main(int argc, char *argv[]) 53{ 54 SDL_Window *window = NULL; 55 SDL_Renderer *renderer = NULL; 56 bool done = false; 57 SDL_Event event; 58 SDLTest_CommonState *state; 59 60 int return_code = 1; 61 62 state = SDLTest_CommonCreateState(argv, 0); 63 if (!state) { 64 return 1; 65 } 66 67 if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { 68 goto quit; 69 } 70 71 window = SDL_CreateWindow("SDL Software Renderer Transparent Test", 800, 600, SDL_WINDOW_TRANSPARENT | SDL_WINDOW_RESIZABLE); 72 if (!window) { 73 SDL_Log("Couldn't create transparent window: %s", SDL_GetError()); 74 goto quit; 75 } 76 77 /* Create a software renderer */ 78 renderer = SDL_CreateRenderer(window, SDL_SOFTWARE_RENDERER); 79 if (!renderer) { 80 SDL_Log("Couldn't create renderer: %s", SDL_GetError()); 81 goto quit; 82 } 83 84 /* Make sure we're setting the alpha channel while drawing */ 85 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); 86 87 /* We're ready to go! */ 88 while (!done) { 89 while (SDL_PollEvent(&event)) { 90 switch (event.type) { 91 case SDL_EVENT_KEY_DOWN: 92 if (event.key.key == SDLK_ESCAPE) { 93 done = true; 94 } 95 break; 96 case SDL_EVENT_WINDOW_EXPOSED: 97 /* The software renderer is persistent, so only redraw as-needed */ 98 draw(renderer); 99 break; 100 case SDL_EVENT_QUIT: 101 done = true; 102 break; 103 default: 104 break; 105 } 106 } 107 108 /* Show everything on the screen and wait a bit */ 109 SDL_RenderPresent(renderer); 110 SDL_Delay(100); 111 } 112 113 /* Success! */ 114 return_code = 0; 115 116quit: 117 SDL_DestroyRenderer(renderer); 118 SDL_DestroyWindow(window); 119 SDL_Quit(); 120 SDLTest_CommonDestroyState(state); 121 return return_code; 122} 123
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.