# HG changeset patch
# User John Tsiombikas <nuclear@member.fsf.org>
# Date 1394761177 -7200
# Node ID 3a893f9831ac256cc1183ec9ee867f323d822460
# Parent  e9ae6289e14fb1b061398d327f6d3636a7e4f99e
ported to SDL2

diff -r e9ae6289e14f -r 3a893f9831ac Makefile
--- a/Makefile	Fri Mar 07 07:42:48 2014 +0200
+++ b/Makefile	Fri Mar 14 03:39:37 2014 +0200
@@ -2,8 +2,8 @@
 obj = $(src:.c=.o)
 bin = mbrot
 
-CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl`
-LDFLAGS = `pkg-config --libs sdl`
+CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl2`
+LDFLAGS = `pkg-config --libs sdl2`
 
 $(bin): $(obj)
 	$(CC) -o $@ $(obj) $(LDFLAGS)
diff -r e9ae6289e14f -r 3a893f9831ac src/mbrot-mt.c
--- a/src/mbrot-mt.c	Fri Mar 07 07:42:48 2014 +0200
+++ b/src/mbrot-mt.c	Fri Mar 14 03:39:37 2014 +0200
@@ -1,17 +1,43 @@
 #include <stdio.h>
 #include <complex.h>
-#include <SDL/SDL.h>
+#include <SDL2/SDL.h>
 
 void display(void);
 int mandelbrot(float x, float y, int max_iter, int *iter);
 int handle_event(SDL_Event *ev);
 
-static SDL_Surface *fbsurf;
+static SDL_Window *win;
+static SDL_Surface *winsurf;
 static int win_width, win_height;
 static float win_aspect;
 static float xoffs, yoffs, zoom = 1.0;
 static int max_iter = 64;
 
+static void trysdl2stuff(void)
+{
+	int i, j, num_modes, num_scr;
+
+	num_scr = SDL_GetNumVideoDisplays();
+
+	for(i=0; i<num_scr; i++) {
+		printf("Screen %d: %s\n", i, SDL_GetDisplayName(i));
+
+		num_modes = SDL_GetNumDisplayModes(i);
+		for(j=0; j<num_modes; j++) {
+			SDL_DisplayMode mode;
+			int bpp;
+			unsigned int rmask, gmask, bmask, amask;
+
+			SDL_GetDisplayMode(i, j, &mode);
+			SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask);
+
+			printf("  %dx%d %dbpp %dhz\n", mode.w, mode.h, bpp, mode.refresh_rate);
+		}
+	}
+
+	SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Information", "Mandelbrot rules!", 0);
+}
+
 int main(void)
 {
 	win_width = 800;
@@ -19,12 +45,13 @@
 	win_aspect = (float)win_width / (float)win_height;
 
 	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
-	if(!(fbsurf = SDL_SetVideoMode(win_width, win_height, 32, SDL_SWSURFACE | SDL_RESIZABLE))) {
+	trysdl2stuff();
+
+	if(!(win = SDL_CreateWindow("Mandelbrot", 0, 0, win_width, win_height, SDL_WINDOW_RESIZABLE))) {
 		fprintf(stderr, "failed to create framebuffer\n");
 		return 1;
 	}
-
-	SDL_WM_SetCaption("Mandelbrot", 0);
+	winsurf = SDL_GetWindowSurface(win);
 
 	for(;;) {
 		SDL_Event ev;
@@ -48,12 +75,12 @@
 	unsigned char *fbuf, *pixptr;
 	int i, j, xsz, ysz;
 
-	if(SDL_MUSTLOCK(fbsurf)) {
-		SDL_LockSurface(fbsurf);
+	if(SDL_MUSTLOCK(winsurf)) {
+		SDL_LockSurface(winsurf);
 	}
-	fbuf = fbsurf->pixels;
-	xsz = fbsurf->w;
-	ysz = fbsurf->h;
+	fbuf = winsurf->pixels;
+	xsz = winsurf->w;
+	ysz = winsurf->h;
 
 	pixptr = fbuf;
 	for(i=0; i<ysz; i++) {
@@ -79,10 +106,10 @@
 		}
 	}
 
-	if(SDL_MUSTLOCK(fbsurf)) {
-		SDL_UnlockSurface(fbsurf);
+	if(SDL_MUSTLOCK(winsurf)) {
+		SDL_UnlockSurface(winsurf);
 	}
-	SDL_Flip(fbsurf);
+	SDL_UpdateWindowSurface(win);
 }
 
 int mandelbrot(float x, float y, int max_iter, int *iter)
@@ -146,10 +173,12 @@
 		}
 		break;
 
-	case SDL_VIDEORESIZE:
-		win_width = ev->resize.w;
-		win_height = ev->resize.h;
-		win_aspect = (float)win_width / (float)win_height;
+	case SDL_WINDOWEVENT:
+		if(ev->window.event == SDL_WINDOWEVENT_RESIZED) {
+			win_width = ev->window.data1;
+			win_height = ev->window.data2;
+			win_aspect = (float)win_width / (float)win_height;
+		}
 		break;
 
 	default: