Now it display a message of progress...

This commit is contained in:
José Carlos Cuevas 2013-09-01 14:40:48 +02:00
parent 1320af37d0
commit 9dfb20c051
4 changed files with 75 additions and 7 deletions

View file

@ -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)

BIN
font.ttf Normal file

Binary file not shown.

38
main.c
View file

@ -11,6 +11,7 @@
#endif
#include <SDL.h>
#include <SDL_ttf.h>
#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);
}

View file

@ -7,10 +7,10 @@
#include <time.h>
#include <SDL.h>
#include <SDL_ttf.h>
#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);
}