diff --git a/Makefile b/Makefile index 263dce0..a509c22 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,12 @@ CC=gcc # Flags! SDLFLAGS=$(shell sdl-config --cflags) -# Comment this line and uncomment the next to get Julia fractals +# Comment this line and uncomment the next to get debug symbols CFLAGS=-c -Wall -O2 $(SDLFLAGS) -# CFLAGS=-c -Wall -O2 -DJULIA $(SDLFLAGS) # CFLAGS=-c -Wall -ggdb $(SDLFLAGS) # Libs! -SDLLIBS=$(shell sdl-config --libs) +SDLLIBS=$(shell sdl-config --libs) -lSDL_ttf OPENCLLIBS=-lOpenCL LIBS=-lm -lpthread $(SDLLIBS) diff --git a/font.ttf b/font.ttf new file mode 100644 index 0000000..6e7575a Binary files /dev/null and b/font.ttf differ diff --git a/main.c b/main.c index 30b8ccd..889badc 100644 --- a/main.c +++ b/main.c @@ -11,6 +11,7 @@ #endif #include +#include #define MAX_SOURCE_SIZE (0x100000) @@ -23,7 +24,7 @@ int main(int argn, char **argv) { printf("SDL Initialized\n"); // Create screen surface - SDL_Surface *screen; + SDL_Surface *screen, *message; int res_x = 800; int res_y = 600; int current_line = 0; @@ -43,6 +44,29 @@ int main(int argn, char **argv) { if(!screen) fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError()); + // Set the title bar + SDL_WM_SetCaption("CLFract", "CLFract"); + + //Initialize SDL_ttf + if( TTF_Init() == -1 ) + { + printf("Error setting up TTF module.\n"); + return 1; + } + + // Load a font + TTF_Font *font; + font = TTF_OpenFont("font.ttf", 24); + if (font == NULL) + { + printf("TTF_OpenFont() Failed: %s", TTF_GetError()); + SDL_Quit(); + return 1; + } + + //The color of the font + SDL_Color textColor = { 255, 255, 255 }; + // Prepare the resolution and sizes and colors... const int ITERATIONS = 256; @@ -214,11 +238,23 @@ int main(int argn, char **argv) { } } } + + // Step, iterate our zoom levels if we're doing mandelbrot or julia set if (julia_mode == 0) zoom = zoom * 0.98; else zoom -= 0.01; + // Draw message on a corner... + char* msg = (char *)malloc(100 * sizeof(char)); + sprintf(msg, "Zoom level: %0.3f", zoom * 100.0); + message = TTF_RenderText_Solid( font, msg, textColor ); + free(msg); + if (message != NULL) + SDL_BlitSurface(message, NULL, screen, NULL); + + free(message); + // Draw to the screen SDL_Flip(screen); } diff --git a/mandel_classic.c b/mandel_classic.c index 7d5edfb..018eed4 100644 --- a/mandel_classic.c +++ b/mandel_classic.c @@ -7,10 +7,10 @@ #include #include +#include #define MAX_SOURCE_SIZE (0x100000) - #ifdef CACHE int** cached_points; int** cached_x; @@ -249,7 +249,6 @@ int julia_point(int res_x, int res_y, int image_x, int image_y, float zoom, int } } - // Splits the image in pieces and calls the corresponding algorithm void *thread_launcher(void *arguments) { @@ -302,6 +301,7 @@ void *thread_launcher(void *arguments) } } + int get_cpus() { int number_of_cores = 0; @@ -309,6 +309,7 @@ int get_cpus() return number_of_cores; } + int main(int argn, char **argv) { // Init SDL @@ -318,7 +319,7 @@ int main(int argn, char **argv) printf("SDL Initialized\n"); // Create screen surface - SDL_Surface *screen; + SDL_Surface *screen, *message; int res_x = 800; int res_y = 600; int julia_mode = 0; @@ -373,6 +374,28 @@ int main(int argn, char **argv) screen = SDL_SetVideoMode(res_x, res_y, 0, SDL_DOUBLEBUF); if(!screen) fprintf(stderr,"Could not set video mode: %s\n",SDL_GetError()); + // Set the title bar + SDL_WM_SetCaption("CLFract", "CLFract"); + + //Initialize SDL_ttf + if( TTF_Init() == -1 ) + { + printf("Error setting up TTF module.\n"); + return 1; + } + + // Load a font + TTF_Font *font; + font = TTF_OpenFont("font.ttf", 24); + if (font == NULL) + { + printf("TTF_OpenFont() Failed: %s", TTF_GetError()); + SDL_Quit(); + return 1; + } + + //The color of the font + SDL_Color textColor = { 255, 255, 255 }; // Prepare the resolution and sizes and colors, threads... iteration_pixels = malloc(res_x * res_y * sizeof(int)); @@ -468,6 +491,16 @@ int main(int argn, char **argv) else zoom -= 0.01; + // Draw message on a corner... + char* msg = (char *)malloc(100 * sizeof(char)); + sprintf(msg, "Zoom level: %0.3f", zoom * 100.0); + message = TTF_RenderText_Solid( font, msg, textColor ); + free(msg); + if (message != NULL) + SDL_BlitSurface(message, NULL, screen, NULL); + + free(message); + SDL_Flip(screen); }