Modified to compile against SDL 2.0
This commit is contained in:
parent
e5ee37a27d
commit
7c71af8aa1
4 changed files with 115 additions and 44 deletions
6
Makefile
6
Makefile
|
@ -2,21 +2,21 @@
|
|||
CC=gcc
|
||||
|
||||
# Flags!
|
||||
SDLFLAGS=$(shell sdl-config --cflags)
|
||||
SDLFLAGS=$(shell sdl2-config --cflags)
|
||||
|
||||
# Comment this line and uncomment the next to get debug symbols
|
||||
CFLAGS=-c -Wall -O2 $(SDLFLAGS)
|
||||
# CFLAGS=-c -Wall -ggdb $(SDLFLAGS)
|
||||
|
||||
# Libs!
|
||||
SDLLIBS=$(shell sdl-config --libs) -lSDL_ttf
|
||||
SDLLIBS=$(shell sdl2-config --libs) -lSDL2_ttf
|
||||
OPENCLLIBS=-lOpenCL
|
||||
|
||||
LIBS=-lm -lpthread $(SDLLIBS)
|
||||
|
||||
# Includes!
|
||||
|
||||
INCLUDE=-I/usr/include/SDL -I./
|
||||
INCLUDE=-I/usr/include/SDL2 -I./
|
||||
|
||||
all: mandelclassic clfract test clfractinteractive
|
||||
|
||||
|
|
|
@ -15,19 +15,21 @@
|
|||
|
||||
#define MAX_SOURCE_SIZE (0x100000)
|
||||
|
||||
float map_x_mandelbrot(int x, int width, float zoom)
|
||||
float map_x_mandelbrot(float x, int width, float zoom)
|
||||
{
|
||||
return (((float)x / (float)width) * (3.5 * zoom)) - 2.5;
|
||||
// return (((float)x / (float)width) * (3.5 * zoom)) - 2.5;
|
||||
return ((x / (float)width) * (3.5 * zoom));
|
||||
}
|
||||
|
||||
float map_x_julia(int x, int width, float zoom)
|
||||
float map_x_julia(float x, int width, float zoom)
|
||||
{
|
||||
return (((float)x / (float)width) * (3.5 * zoom)) - 1.75;
|
||||
return ((x / (float)width) * (3.5 * zoom)) - 1.75;
|
||||
}
|
||||
|
||||
float map_y(int y, int height, float zoom)
|
||||
float map_y(float y, int height, float zoom)
|
||||
{
|
||||
return (((float)y / (float)height) * (2.0 * zoom)) - 1.0;
|
||||
// return (((float)y / (float)height) * (2.0 * zoom)) - 1.0;
|
||||
return ((y / (float)height) * (2.0 * zoom));
|
||||
}
|
||||
|
||||
int main(int argn, char **argv) {
|
||||
|
@ -55,12 +57,27 @@ int main(int argn, char **argv) {
|
|||
printf("Julia mode activated...\n");
|
||||
}
|
||||
|
||||
screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF);
|
||||
if(!screen)
|
||||
SDL_Window *window = SDL_CreateWindow("MandelClassic",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
res_x, res_y, 0);
|
||||
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
||||
if ((!window) || (!renderer))
|
||||
fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError());
|
||||
|
||||
// Set the title bar
|
||||
SDL_WM_SetCaption("CLFract", "CLFract");
|
||||
// Blank the window
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_Texture *texture_screen = SDL_CreateTexture(renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
res_x, res_y);
|
||||
|
||||
screen = SDL_CreateRGBSurface(0, res_x, res_y , 32, 0, 0, 0, 0);
|
||||
|
||||
//Initialize SDL_ttf
|
||||
if( TTF_Init() == -1 )
|
||||
|
@ -172,6 +189,8 @@ int main(int argn, char **argv) {
|
|||
float stop_point;
|
||||
float center_x = 2.5;
|
||||
float center_y = 1.75;
|
||||
float mouse_x = res_x / 2;
|
||||
float mouse_y = res_y / 2;
|
||||
|
||||
if (julia_mode == 0)
|
||||
stop_point = 0.00001;
|
||||
|
@ -249,26 +268,26 @@ int main(int argn, char **argv) {
|
|||
iteration = graph_line[line_count];
|
||||
if ((iteration < 128) && (iteration > 0)) {
|
||||
pixel[(current_line * res_x) + line_count] = SDL_MapRGBA(screen->format,
|
||||
0,
|
||||
20 + iteration,
|
||||
0,
|
||||
255);
|
||||
0,
|
||||
20 + iteration,
|
||||
0,
|
||||
255);
|
||||
}
|
||||
else if ((iteration >= 128) && (iteration < ITERATIONS))
|
||||
{
|
||||
pixel[(current_line * res_x) + line_count] = SDL_MapRGBA(screen->format,
|
||||
iteration,
|
||||
148,
|
||||
iteration,
|
||||
255);
|
||||
iteration,
|
||||
148,
|
||||
iteration,
|
||||
255);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel[(current_line * res_x) + line_count] = SDL_MapRGBA(screen->format,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
255);
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,13 +310,10 @@ int main(int argn, char **argv) {
|
|||
{
|
||||
motion = -1;
|
||||
}
|
||||
|
||||
mouse_x = ( (float) button.x - ((float) res_x / 2.0) ) / 10.0;
|
||||
mouse_y = ( (float) button.y - ((float) res_y / 2.0) ) / 10.0;
|
||||
|
||||
if (julia_mode == 0)
|
||||
center_x = map_x_mandelbrot(button.x, res_x, zoom);
|
||||
else
|
||||
center_x = map_x_julia(button.x, res_x, zoom);
|
||||
|
||||
center_y = map_y(button.y, res_y, zoom);
|
||||
}
|
||||
else if ( (ev.type == SDL_MOUSEBUTTONUP) )
|
||||
{
|
||||
|
@ -322,6 +338,16 @@ int main(int argn, char **argv) {
|
|||
zoom += 0.01;
|
||||
}
|
||||
|
||||
if (motion != 0)
|
||||
{
|
||||
if (julia_mode == 0)
|
||||
center_x = map_x_mandelbrot(center_x + mouse_x, res_x, zoom);
|
||||
else
|
||||
center_x = map_x_julia(center_x + mouse_x, res_x, zoom);
|
||||
|
||||
center_y = map_y(center_y + mouse_y, res_y, zoom);
|
||||
}
|
||||
|
||||
// Draw message on a corner...
|
||||
char* msg = (char *)malloc(100 * sizeof(char));
|
||||
sprintf(msg, "Zoom level: %0.3f", zoom * 100.0);
|
||||
|
@ -332,8 +358,12 @@ int main(int argn, char **argv) {
|
|||
|
||||
free(message);
|
||||
|
||||
SDL_UpdateTexture(texture_screen, NULL, (Uint32*)screen->pixels, 800 * sizeof (Uint32));
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture_screen, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
// Draw to the screen
|
||||
SDL_Flip(screen);
|
||||
// SDL_Flip(screen);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
|
|
29
main.c
29
main.c
|
@ -40,12 +40,27 @@ int main(int argn, char **argv) {
|
|||
printf("Julia mode activated...\n");
|
||||
}
|
||||
|
||||
screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF);
|
||||
if(!screen)
|
||||
SDL_Window *window = SDL_CreateWindow("CLFract",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
res_x, res_y, 0);
|
||||
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
||||
if ((!window) || (!renderer))
|
||||
fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError());
|
||||
|
||||
// Set the title bar
|
||||
SDL_WM_SetCaption("CLFract", "CLFract");
|
||||
// Blank the window
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_Texture *texture_screen = SDL_CreateTexture(renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
res_x, res_y);
|
||||
|
||||
screen = SDL_CreateRGBSurface(0, res_x, res_y , 32, 0, 0, 0, 0);
|
||||
|
||||
//Initialize SDL_ttf
|
||||
if( TTF_Init() == -1 )
|
||||
|
@ -255,8 +270,12 @@ int main(int argn, char **argv) {
|
|||
|
||||
free(message);
|
||||
|
||||
SDL_UpdateTexture(texture_screen, NULL, (Uint32*)screen->pixels, 800 * sizeof (Uint32));
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture_screen, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
// Draw to the screen
|
||||
SDL_Flip(screen);
|
||||
// SDL_Flip(screen);
|
||||
}
|
||||
|
||||
printf("Time elapsed %0.5f seconds\n", ((double)clock() - start) / CLOCKS_PER_SEC);
|
||||
|
|
|
@ -314,11 +314,11 @@ int main(int argn, char **argv)
|
|||
{
|
||||
// Init SDL
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
|
||||
fprintf(stderr, "Could not initialize SDL2: %s\n", SDL_GetError());
|
||||
|
||||
printf("SDL Initialized\n");
|
||||
|
||||
// Create screen surface
|
||||
// Create screen texture
|
||||
SDL_Surface *screen, *message;
|
||||
int res_x = 800;
|
||||
int res_y = 600;
|
||||
|
@ -371,11 +371,28 @@ int main(int argn, char **argv)
|
|||
#endif
|
||||
|
||||
// screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_HWSURFACE|SDL_DOUBLEBUF);
|
||||
screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF);
|
||||
if(!screen)
|
||||
// screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF);
|
||||
SDL_Window *window = SDL_CreateWindow("MandelClassic",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
res_x, res_y, 0);
|
||||
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
||||
if ((!window) || (!renderer))
|
||||
fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError());
|
||||
// Set the title bar
|
||||
SDL_WM_SetCaption("CLFract", "CLFract");
|
||||
|
||||
// Blank the window
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_Texture *texture_screen = SDL_CreateTexture(renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
res_x, res_y);
|
||||
|
||||
screen = SDL_CreateRGBSurface(0, res_x, res_y , 32, 0, 0, 0, 0);
|
||||
|
||||
//Initialize SDL_ttf
|
||||
if( TTF_Init() == -1 )
|
||||
|
@ -501,7 +518,12 @@ int main(int argn, char **argv)
|
|||
|
||||
free(message);
|
||||
|
||||
SDL_Flip(screen);
|
||||
SDL_UpdateTexture(texture_screen, NULL, (Uint32*)screen->pixels, 800 * sizeof (Uint32));
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture_screen, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
// SDL_Flip(screen);
|
||||
}
|
||||
|
||||
printf("Time elapsed %0.5f seconds\n", ((double)clock() - start) / CLOCKS_PER_SEC);
|
||||
|
|
Loading…
Reference in a new issue