[Add] Hellz YEAH! Here's some initial plasma fractals, all working and stuff.
This commit is contained in:
parent
5cbb97b279
commit
0890ce4a2e
@ -19,6 +19,7 @@ glColour cRed = { .r = 0.80, .g = 0.20, .b = 0.20, .a = 1. };
|
|||||||
glColour cYellow = { .r = 0.80, .g = 0.80, .b = 0.00, .a = 1. };
|
glColour cYellow = { .r = 0.80, .g = 0.80, .b = 0.00, .a = 1. };
|
||||||
glColour cDarkBlue = { .r = 0.10, .g = 0.20, .b = 0.80, .a = 1. };
|
glColour cDarkBlue = { .r = 0.10, .g = 0.20, .b = 0.80, .a = 1. };
|
||||||
glColour cBlue = { .r = 0.20, .g = 0.20, .b = 0.80, .a = 1. };
|
glColour cBlue = { .r = 0.20, .g = 0.20, .b = 0.80, .a = 1. };
|
||||||
|
glColour cPurple = { .r = 0.90, .g = 0.10, .b = 0.90, .a = 1. };
|
||||||
|
|
||||||
// Game specific.
|
// Game specific.
|
||||||
glColour cConsole = { .r = 0.1, .g = 0.9, .b = 0.1, .a = 1. };
|
glColour cConsole = { .r = 0.1, .g = 0.9, .b = 0.1, .a = 1. };
|
||||||
|
@ -28,6 +28,7 @@ extern glColour cRed;
|
|||||||
extern glColour cYellow;
|
extern glColour cYellow;
|
||||||
extern glColour cDarkBlue;
|
extern glColour cDarkBlue;
|
||||||
extern glColour cBlue;
|
extern glColour cBlue;
|
||||||
|
extern glColour cPurple;
|
||||||
|
|
||||||
// Game specific.
|
// Game specific.
|
||||||
extern glColour cConsole;
|
extern glColour cConsole;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "pilot.h"
|
#include "pilot.h"
|
||||||
#include "space.h"
|
#include "space.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "plasmaf.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
#define MAIN_WIDTH 130
|
#define MAIN_WIDTH 130
|
||||||
@ -45,10 +46,15 @@ static void menu_death_main(char* str);
|
|||||||
|
|
||||||
void menu_main(void) {
|
void menu_main(void) {
|
||||||
unsigned int bwid, wid;
|
unsigned int bwid, wid;
|
||||||
|
glTexture* tex;
|
||||||
|
|
||||||
|
tex = pf_genFractal(gl_screen.w, gl_screen.h, 10.);
|
||||||
|
|
||||||
// Create background image window.
|
// Create background image window.
|
||||||
bwid = window_create("BG", -1, -1, gl_screen.w, gl_screen.h);
|
bwid = window_create("BG", -1, -1, gl_screen.w, gl_screen.h);
|
||||||
window_addRect(bwid, 0, 0, gl_screen.w, gl_screen.h, "rctBG", &cBlack, 0);
|
window_addRect(bwid, 0, 0, gl_screen.w, gl_screen.h, "rctBG", &cBlack, 0);
|
||||||
|
window_addImage(bwid, 0, 0, "imgBG", tex, 0);
|
||||||
|
window_imgColour(bwid, "imgBG", &cPurple);
|
||||||
|
|
||||||
// Create menu window.
|
// Create menu window.
|
||||||
wid = window_create("Main Menu", -1, -1, MAIN_WIDTH, MAIN_HEIGHT);
|
wid = window_create("Main Menu", -1, -1, MAIN_WIDTH, MAIN_HEIGHT);
|
||||||
@ -69,6 +75,8 @@ void menu_main(void) {
|
|||||||
|
|
||||||
static void menu_main_close(void) {
|
static void menu_main_close(void) {
|
||||||
window_destroy(window_get("Main Menu"));
|
window_destroy(window_get("Main Menu"));
|
||||||
|
|
||||||
|
gl_freeTexture(window_getImage(window_get("BG"), "imgBG"));
|
||||||
window_destroy(window_get("BG"));
|
window_destroy(window_get("BG"));
|
||||||
|
|
||||||
menu_Close(MENU_MAIN);
|
menu_Close(MENU_MAIN);
|
||||||
|
99
src/plasmaf.c
Normal file
99
src/plasmaf.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "rng.h"
|
||||||
|
#include "opengl.h"
|
||||||
|
#include "plasmaf.h"
|
||||||
|
|
||||||
|
static double* pf_genFractalMap(const int w, const int h, double rug);
|
||||||
|
static void pf_divFractal(double* map, const double x, const double y,
|
||||||
|
const double w, const double h, const
|
||||||
|
double rw, const double rh, double c1,
|
||||||
|
double c2, double c3, double c4, double rug);
|
||||||
|
|
||||||
|
// Acutally generate the fractal and loads it up in an opengl texture.
|
||||||
|
glTexture* pf_genFractal(const int w, const int h, double rug) {
|
||||||
|
int i;
|
||||||
|
double* map;
|
||||||
|
SDL_Surface* sur;
|
||||||
|
uint32_t* pix;
|
||||||
|
glTexture* tex;
|
||||||
|
|
||||||
|
map = pf_genFractalMap(w, h, rug);
|
||||||
|
|
||||||
|
sur = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RGBMASK);
|
||||||
|
pix = sur->pixels;
|
||||||
|
|
||||||
|
// Convert from mapping to actual colours.
|
||||||
|
SDL_LockSurface(sur);
|
||||||
|
for(i = 0; i < h*w; i++) {
|
||||||
|
pix[i] = RMASK + BMASK + GMASK + (AMASK & (uint32_t)(AMASK*5000*map[i]));
|
||||||
|
//DEBUG("amask [%d]: %f [%u]", i, 1000*map[i],
|
||||||
|
//(AMASK & (uint32_t)(AMASK*1000*map[i])));
|
||||||
|
}
|
||||||
|
SDL_UnlockSurface(sur);
|
||||||
|
|
||||||
|
free(map);
|
||||||
|
|
||||||
|
tex = gl_loadImage(sur);
|
||||||
|
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double* pf_genFractalMap(const int w, const int h, double rug) {
|
||||||
|
double* map; // We'll use it to map out the fractal before saving.
|
||||||
|
double cx, cy;
|
||||||
|
|
||||||
|
map = malloc(w*h * sizeof(double));
|
||||||
|
|
||||||
|
// Set up initial values.
|
||||||
|
cx = (double)w/2;
|
||||||
|
cy = (double)h/2;
|
||||||
|
|
||||||
|
// Start by doing the four squares.
|
||||||
|
pf_divFractal(map, 0, 0, cx, cy, w, h, 0., 0., 1., 0., rug);
|
||||||
|
pf_divFractal(map, cx, 0, cx, cy, w, h, 0., 0., 0., 1., rug);
|
||||||
|
pf_divFractal(map, cx, cy, cx, cy, w, h, 1., 0., 0., 0., rug);
|
||||||
|
pf_divFractal(map, 0, cy, cx, cy, w, h, 0., 1., 0., 0., rug);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pf_divFractal(double* map, const double x, const double y,
|
||||||
|
const double w, const double h, const double rw,
|
||||||
|
const double rh, double c1, double c2, double c3,
|
||||||
|
double c4, double rug) {
|
||||||
|
|
||||||
|
double nw, nh; // New dimensions.
|
||||||
|
double m, e1, e2, e3, e4; // Middle and edges.
|
||||||
|
|
||||||
|
// Still need to subdivide.
|
||||||
|
if((w>1.) || (h>1.)) {
|
||||||
|
// Calculate new dimensions.
|
||||||
|
nw = w/2.;
|
||||||
|
nh = h/2.;
|
||||||
|
|
||||||
|
// Edges.
|
||||||
|
m = (c1 + c2 + c3 + c4)/4.;
|
||||||
|
e1 = (c1 + c2)/2.;
|
||||||
|
e2 = (c2 + c3)/2.;
|
||||||
|
e3 = (c3 + c4)/2.;
|
||||||
|
e4 = (c4 + c1)/2.;
|
||||||
|
|
||||||
|
// Now change the middle colour.
|
||||||
|
//DEBUG("%f + %f", m, rug*(RNGF()-0.5) * ((nw+nh)/(rw+rh)*1000));
|
||||||
|
m += rug*(RNGF()-0.5)*((nw+nh)/(rw+rh)*3.);
|
||||||
|
if(m < 0.) m = 0.;
|
||||||
|
else if(m>1.) m = 1.;
|
||||||
|
|
||||||
|
// Recursivation.
|
||||||
|
pf_divFractal(map, x, y, nw, nh, rw, rh, c1, e1, m, e4, rug);
|
||||||
|
pf_divFractal(map, x+nw, y, nw, nh, rw, rh, e1, c2, e2, m, rug);
|
||||||
|
pf_divFractal(map, x+nw, y+nh, nw, nh, rw, rh, m, e2, c3, e3, rug);
|
||||||
|
pf_divFractal(map, x, y+nh, nw, nh, rw, rh, e4, m, e3, c4, rug);
|
||||||
|
} else
|
||||||
|
// Actually write the pixel.
|
||||||
|
//map[y*rw+x] = (c1 + c2 + c3 + c4)/4.;
|
||||||
|
map[(int)round(y)*(int)rw+(int)round(x)] = (c1 + c2 + c3 + c4)/4.;
|
||||||
|
}
|
||||||
|
|
5
src/plasmaf.h
Normal file
5
src/plasmaf.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "opengl.h"
|
||||||
|
|
||||||
|
glTexture* pf_genFractal(const int w, const int h, const double rug);
|
||||||
|
|
@ -50,6 +50,7 @@ typedef struct Widget_ {
|
|||||||
struct {
|
struct {
|
||||||
// Widget image.
|
// Widget image.
|
||||||
glTexture* image;
|
glTexture* image;
|
||||||
|
glColour* colour;
|
||||||
int border;
|
int border;
|
||||||
} img;
|
} img;
|
||||||
struct {
|
struct {
|
||||||
@ -218,6 +219,8 @@ void window_addImage(const unsigned int wid, const int x, const int y,
|
|||||||
// Set the properties.
|
// Set the properties.
|
||||||
wgt->dat.img.image = image;
|
wgt->dat.img.image = image;
|
||||||
wgt->dat.img.border = border;
|
wgt->dat.img.border = border;
|
||||||
|
wgt->dat.img.colour = NULL; // Normal colour.
|
||||||
|
|
||||||
wgt->w = (image == NULL) ? 0 : wgt->dat.img.image->sw;
|
wgt->w = (image == NULL) ? 0 : wgt->dat.img.image->sw;
|
||||||
wgt->h = (image == NULL) ? 0 : wgt->dat.img.image->sh;
|
wgt->h = (image == NULL) ? 0 : wgt->dat.img.image->sh;
|
||||||
if(x < 0) wgt->x = wdw->w - wgt->w + x;
|
if(x < 0) wgt->x = wdw->w - wgt->w + x;
|
||||||
@ -375,6 +378,12 @@ void window_modifyImage(const unsigned int wid, char* name, glTexture* image) {
|
|||||||
wgt->dat.img.image = image;
|
wgt->dat.img.image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void window_imgColour(const unsigned int wid, char* name, glColour* colour) {
|
||||||
|
Widget* wgt = window_getwgt(wid, name);
|
||||||
|
|
||||||
|
wgt->dat.img.colour = colour;
|
||||||
|
}
|
||||||
|
|
||||||
glTexture* window_getImage(const unsigned int wid, char* name) {
|
glTexture* window_getImage(const unsigned int wid, char* name) {
|
||||||
Widget* wgt = window_getwgt(wid, name);
|
Widget* wgt = window_getwgt(wid, name);
|
||||||
return (wgt) ? wgt->dat.img.image : NULL;
|
return (wgt) ? wgt->dat.img.image : NULL;
|
||||||
@ -849,7 +858,8 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
|
|||||||
// Image.
|
// Image.
|
||||||
gl_blitStatic(img->dat.img.image,
|
gl_blitStatic(img->dat.img.image,
|
||||||
x + (double)gl_screen.w/2.,
|
x + (double)gl_screen.w/2.,
|
||||||
y + (double)gl_screen.h/2., NULL);
|
y + (double)gl_screen.h/2.,
|
||||||
|
img->dat.img.colour);
|
||||||
|
|
||||||
if(img->dat.img.border) {
|
if(img->dat.img.border) {
|
||||||
// Inner outline (outwards).
|
// Inner outline (outwards).
|
||||||
|
@ -51,7 +51,9 @@ char* dialogue_input(char* title, int min, int max, const char* fmt, ...);
|
|||||||
// Modification.
|
// Modification.
|
||||||
void window_setFptr(const unsigned int wid, void(*fptr)(char*));
|
void window_setFptr(const unsigned int wid, void(*fptr)(char*));
|
||||||
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
||||||
|
// Image.
|
||||||
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
||||||
|
void window_imgColour(const unsigned int wid, char* name, glColour* colour);
|
||||||
|
|
||||||
// Get the window by name.
|
// Get the window by name.
|
||||||
int window_exists(const char* wdwname);
|
int window_exists(const char* wdwname);
|
||||||
|
Loading…
Reference in New Issue
Block a user