[Change] Moved some code from perlin to nebulae.
This commit is contained in:
parent
7b7ddae70e
commit
1e7d19b2a6
@ -33,10 +33,11 @@ static double nebu_view = 0.;
|
|||||||
static double nebu_dt = 0.;
|
static double nebu_dt = 0.;
|
||||||
|
|
||||||
static int nebu_checkCompat(const char* file);
|
static int nebu_checkCompat(const char* file);
|
||||||
|
static void nebu_generate(void);
|
||||||
static void saveNebulae(float* map, const uint32_t w, const uint32_t h,
|
static void saveNebulae(float* map, const uint32_t w, const uint32_t h,
|
||||||
const char* file);
|
const char* file);
|
||||||
static SDL_Surface* loadNebulae(const char* file);
|
static SDL_Surface* loadNebulae(const char* file);
|
||||||
static void nebu_generate(void);
|
static SDL_Surface* nebu_surfaceFromNebulaeMap(float* map, const int w, const int h);
|
||||||
|
|
||||||
/* Initialize the nebulae. */
|
/* Initialize the nebulae. */
|
||||||
void nebu_init(void) {
|
void nebu_init(void) {
|
||||||
@ -345,7 +346,7 @@ static void saveNebulae(float* map, const uint32_t w, const uint32_t h,
|
|||||||
char file_path[PATH_MAX];
|
char file_path[PATH_MAX];
|
||||||
SDL_Surface* sur;
|
SDL_Surface* sur;
|
||||||
|
|
||||||
sur = noise_surfaceFromNebulaeMap(map, w, h);
|
sur = nebu_surfaceFromNebulaeMap(map, w, h);
|
||||||
|
|
||||||
snprintf(file_path, PATH_MAX, "%s%s", lfile_basePath(), file);
|
snprintf(file_path, PATH_MAX, "%s%s", lfile_basePath(), file);
|
||||||
|
|
||||||
@ -370,3 +371,24 @@ static SDL_Surface* loadNebulae(const char* file) {
|
|||||||
return sur;
|
return sur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Generate an SDL_Surface from a 2d nebulae map. */
|
||||||
|
SDL_Surface* nebu_surfaceFromNebulaeMap(float* map, const int w, const int h) {
|
||||||
|
int i;
|
||||||
|
SDL_Surface* sur;
|
||||||
|
uint32_t* pix;
|
||||||
|
double c;
|
||||||
|
|
||||||
|
sur = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RGBAMASK);
|
||||||
|
pix = sur->pixels;
|
||||||
|
|
||||||
|
/* Convert from mapping to actual colours. */
|
||||||
|
SDL_LockSurface(sur);
|
||||||
|
for(i = 0; i < h*w; i++) {
|
||||||
|
c = map[i];
|
||||||
|
pix[i] = RMASK + BMASK + GMASK + (AMASK & (uint32_t)((double)AMASK*c));
|
||||||
|
}
|
||||||
|
SDL_UnlockSurface(sur);
|
||||||
|
|
||||||
|
return sur;
|
||||||
|
}
|
||||||
|
|
||||||
|
21
src/perlin.c
21
src/perlin.c
@ -239,24 +239,3 @@ float* noise_genNebulaeMap(const int w, const int h, const int n, float rug) {
|
|||||||
return nebulae;
|
return nebulae;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate an SDL_Surface from a 2d nebulae map. */
|
|
||||||
SDL_Surface* noise_surfaceFromNebulaeMap(float* map, const int w, const int h) {
|
|
||||||
int i;
|
|
||||||
SDL_Surface* sur;
|
|
||||||
uint32_t* pix;
|
|
||||||
double c;
|
|
||||||
|
|
||||||
sur = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RGBAMASK);
|
|
||||||
pix = sur->pixels;
|
|
||||||
|
|
||||||
/* Convert from mapping to actual colours. */
|
|
||||||
SDL_LockSurface(sur);
|
|
||||||
for(i = 0; i < h*w; i++) {
|
|
||||||
c = map[i];
|
|
||||||
pix[i] = RMASK + BMASK + GMASK + (AMASK & (uint32_t)((double)AMASK*c));
|
|
||||||
}
|
|
||||||
SDL_UnlockSurface(sur);
|
|
||||||
|
|
||||||
return sur;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -3,5 +3,3 @@
|
|||||||
|
|
||||||
float* noise_genNebulaeMap(const int w, const int h, const int n, float rug);
|
float* noise_genNebulaeMap(const int w, const int h, const int n, float rug);
|
||||||
|
|
||||||
SDL_Surface* noise_surfaceFromNebulaeMap(float* map, const int w, const int h);
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user