#+TITLE: sdl2 org src
#+AUTHOR: screwtape
* Rich media sdl2 C applications
(skip past window settings in your reading; they are just better at the top)
** Window settings
#+NAME: w-sizing
#+HEADER: :includes "/usr/local/include/SDL2/SDL.h"
#+begin_src C
SDL_WINDOW_RESIZABLE
#+end_src
#+NAME: w-height
#+begin_src C
768
#+end_src
#+NAME: w-width
#+begin_src C
1280
#+end_src
** template
#+BEGIN_EXAMPLE
This template does seem a little bit goto cleanup rather than some clunky
long, but that is because it handles quit flag; but then, it was easier
keyboard and mouse events and mouse to goto quit which gotos cleanup. At
position in the general case. I do least the loop isn't goto based!
#+END_EXAMPLE
includes and libs might need to be customized. I found that my sdl2-config
flags on arm64 openbsd didn't actually work!
#+name: template
#+HEADER: :includes "/usr/local/include/SDL2/SDL.h"
#+HEADER: :libs "-L/usr/local/lib -lSDL2"
#+HEADER: :exports code
#+HEADER: :results none
#+HEADER: :noweb yes
#+begin_src C
SDL_Event e;
int mx, my;
Uint32 mdown;
/* spinning animation */
int ticks = 0;
int tox, toy, centerx, centery;
float xoff=0.0, yoff=0.0, l;
/*/spinning animation */
<<sdlstart>>
for(;;){
while(SDL_PollEvent(&e))
if (e.type == SDL_QUIT)
quit:
goto cleanup;
else if (e.type == SDL_MOUSEBUTTONDOWN)
switch (1){
default:
break;
}
else if (e.type == SDL_MOUSEBUTTONUP)
switch (1){
default:
break;
}
else if (e.type == SDL_KEYDOWN)
switch (e.key.keysym.sym){
case SDLK_q:
goto quit;
default:
break;
}
else if (e.type == SDL_KEYUP)
switch (1){
default:
break;
}