SDL2 example
authorTomas Mudrunka <tomas@mudrunka.cz>
Wed, 15 Jul 2020 18:41:36 +0000 (20:41 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Wed, 15 Jul 2020 18:41:36 +0000 (20:41 +0200)
c/SDL2_putpixel_click/main.c [new file with mode: 0644]
c/SDL2_putpixel_click/test_fb.sh [new file with mode: 0644]

diff --git a/c/SDL2_putpixel_click/main.c b/c/SDL2_putpixel_click/main.c
new file mode 100644 (file)
index 0000000..1acfdb2
--- /dev/null
@@ -0,0 +1,55 @@
+//gcc -Wextra -pedantic-errors -o main.out main.c -lSDL2
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <SDL2/SDL.h>
+
+#define WINDOW_WIDTH 600
+
+int main(void) {
+    SDL_Event event;
+    SDL_Renderer *renderer;
+    SDL_Window *window;
+    int i;
+
+    SDL_Init(SDL_INIT_VIDEO);
+    SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_WIDTH, 0, &window, &renderer);
+    //SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+
+    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
+    SDL_RenderClear(renderer);
+    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
+
+    for (i = 0; i < WINDOW_WIDTH; ++i)
+      SDL_RenderDrawPoint(renderer, i, i);
+
+    SDL_RenderPresent(renderer);
+
+    int running = 1;
+    int mouseX, mouseY;
+    while(running) {
+       event.type = 0;
+       if(SDL_PollEvent(&event)) {
+          switch(event.type){
+             case SDL_QUIT:
+                running = 0;
+                break;
+             case SDL_MOUSEBUTTONDOWN:
+                //do whatever you want to do after a mouse button was pressed,
+                // e.g.:
+               //if(event.button.button == SDL_BUTTON_LEFT) {
+                 SDL_GetMouseState(&mouseX, &mouseY);
+                 printf("Click %d, %d, %d\n", mouseX, mouseY, event.button.button);
+                 SDL_RenderDrawPoint(renderer, mouseX, mouseY);
+                 SDL_RenderPresent(renderer);
+               //}
+                break;
+           }
+        }
+    }
+    SDL_DestroyRenderer(renderer);
+    SDL_DestroyWindow(window);
+    SDL_Quit();
+    return EXIT_SUCCESS;
+}
diff --git a/c/SDL2_putpixel_click/test_fb.sh b/c/SDL2_putpixel_click/test_fb.sh
new file mode 100644 (file)
index 0000000..1821241
--- /dev/null
@@ -0,0 +1 @@
+SDL_VIDEODRIVER=directfb ./main.out
This page took 0.436066 seconds and 4 git commands to generate.