ScrapExplorer - sdl2.cpp

Home / lab / archive Lines: 1 | Size: 2301 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* CPP_SDL 2 * Ignore my crap code please 3 */ 4 5#include <SDL.h> 6 7int main(int argc, char** argv) 8{ 9 SDL_Init(SDL_INIT_VIDEO); 10 SDL_Window* window = SDL_CreateWindow("Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); 11 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 12 SDL_SetWindowResizable(window, SDL_TRUE); 13 14 int cursor_last_x = 1, cursor_last_y = 1; 15 int pixel_size = 10; 16 bool running = true; 17 SDL_Rect box = {0, 0, pixel_size, pixel_size}; 18 19 while (running) 20 { 21 SDL_Event e; 22 while (SDL_PollEvent(&e)) 23 { 24 switch (e.type) 25 { 26 case SDL_QUIT: 27 running = false; 28 break; 29 case SDL_KEYDOWN: 30 switch (e.key.keysym.sym) 31 { 32 case SDLK_ESCAPE: 33 running = false; 34 break; 35 case SDLK_UP: 36 box.y--; 37 break; 38 case SDLK_DOWN: 39 box.y++; 40 break; 41 case SDLK_LEFT: 42 box.x--; 43 break; 44 case SDLK_RIGHT: 45 box.x++; 46 break; 47 default: 48 break; 49 } 50 break; 51 default: 52 break; 53 } 54 } 55 56 if (box.x != cursor_last_x || box.y != cursor_last_y) 57 { 58 SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); 59 SDL_RenderClear(renderer); 60 61 SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF); 62 box.x = box.x * pixel_size; 63 box.y = box.y * pixel_size; 64 SDL_RenderFillRect(renderer, &box); 65 66 SDL_RenderPresent(renderer); 67 68 cursor_last_x = box.x; 69 cursor_last_y = box.y; 70 } 71 SDL_Delay(1000 / 60); 72 } 73 74 SDL_DestroyRenderer(renderer); 75 SDL_DestroyWindow(window); 76 SDL_Quit(); 77 78 return 0; 79} 80
[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.