|
@ -21,15 +21,31 @@ static const std::string filenames[] = { |
|
|
"resources/attractor_2011-04-29_04-34-41-9.stf", |
|
|
"resources/attractor_2011-04-29_04-34-41-9.stf", |
|
|
"resources/attractor_2011-04-29_15-19-03-9.stf" }; |
|
|
"resources/attractor_2011-04-29_15-19-03-9.stf" }; |
|
|
|
|
|
|
|
|
|
|
|
static const GLfloat quad[] = { |
|
|
|
|
|
1.0, 1.0, |
|
|
|
|
|
1.0, -1.0, |
|
|
|
|
|
-1.0, -1.0, |
|
|
|
|
|
-1.0, 1.0 }; |
|
|
|
|
|
|
|
|
|
|
|
static const GLfloat tex_quad[] = { |
|
|
|
|
|
1.0, 1.0, |
|
|
|
|
|
1.0, 0.0, |
|
|
|
|
|
0.0, 0.0, |
|
|
|
|
|
0.0, 1.0 }; |
|
|
|
|
|
|
|
|
class App { |
|
|
class App { |
|
|
int counter; |
|
|
int counter; |
|
|
unsigned int width, height; |
|
|
unsigned int width, height; |
|
|
|
|
|
|
|
|
shader mshader; |
|
|
shader mshader; |
|
|
shader clear_shader; |
|
|
shader clear_shader; |
|
|
fbo mfbo; |
|
|
shader texture_shader; |
|
|
|
|
|
shader blur_shader1; |
|
|
|
|
|
shader blur_shader2; |
|
|
|
|
|
fbo fbo1; |
|
|
|
|
|
fbo fbo2; |
|
|
|
|
|
|
|
|
static constexpr size_t number_of_lines = 6*50000; |
|
|
static constexpr size_t number_of_lines = 40000; |
|
|
static constexpr size_t number_of_vertices = 2*number_of_lines; |
|
|
static constexpr size_t number_of_vertices = 2*number_of_lines; |
|
|
std::array<GLfloat, 3*number_of_vertices> lines; |
|
|
std::array<GLfloat, 3*number_of_vertices> lines; |
|
|
std::array<GLfloat, 7> parameters; |
|
|
std::array<GLfloat, 7> parameters; |
|
@ -42,12 +58,19 @@ public: |
|
|
height(h), |
|
|
height(h), |
|
|
mshader("resources/myTeaShader.vert", "resources/myTeaShader.frag"), |
|
|
mshader("resources/myTeaShader.vert", "resources/myTeaShader.frag"), |
|
|
clear_shader("resources/myClearShader.vert", "resources/myClearShader.frag"), |
|
|
clear_shader("resources/myClearShader.vert", "resources/myClearShader.frag"), |
|
|
mfbo(width, height) { |
|
|
texture_shader("resources/myTextureShader.vert", "resources/myTextureShader.frag"), |
|
|
|
|
|
blur_shader1("resources/myHBlurShader.vert", "resources/myHBlurShader.frag"), |
|
|
|
|
|
blur_shader2("resources/myVBlurShader.vert", "resources/myVBlurShader.frag"), |
|
|
|
|
|
fbo1(width, height), |
|
|
|
|
|
fbo2(width, height), |
|
|
|
|
|
lines(), |
|
|
|
|
|
parameters(), |
|
|
|
|
|
random_parameters() { |
|
|
|
|
|
|
|
|
set_points(); |
|
|
set_points(); |
|
|
//glEnable(GL_DEPTH_TEST);
|
|
|
//glEnable(GL_DEPTH_TEST);
|
|
|
glEnable(GL_BLEND); |
|
|
glEnable(GL_BLEND); |
|
|
glPointSize(1.0); |
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
|
|
|
|
|
std::string filename = filenames[3]; |
|
|
std::string filename = filenames[3]; |
|
|
set_parameters(filename); |
|
|
set_parameters(filename); |
|
@ -57,63 +80,79 @@ public: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void resize(int w, int h) { |
|
|
void resize(int w, int h) { |
|
|
|
|
|
std::cout << w << "x" << h << std::endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void update() { |
|
|
void update() { |
|
|
++counter; |
|
|
++counter; |
|
|
iterate(); |
|
|
iterate(); |
|
|
|
|
|
|
|
|
if(counter % 500 == 0) { |
|
|
if(counter % 5000 == 0) { |
|
|
set_parameters(filenames[rand() % 4]); |
|
|
set_parameters(filenames[rand() % 4]); |
|
|
set_points(); |
|
|
set_points(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void draw() { |
|
|
void draw() { |
|
|
clear_shader.begin(); |
|
|
fbo & read_fbo = (counter % 2) ? fbo1 : fbo2; |
|
|
clear_shader.set_uniform("fade", .5f); |
|
|
fbo & draw_fbo = (counter % 2) ? fbo2 : fbo1; |
|
|
if( counter < 5 ) |
|
|
shader & blur_shader = (counter % 2) ? blur_shader1 : blur_shader2; |
|
|
clear_shader.set_uniform("fade", 1.0f); |
|
|
|
|
|
fade(); |
|
|
glClearColor(0.0, 0.0, 0.0, 0.0); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
draw_fbo.begin(); |
|
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
blur_shader.begin(); |
|
|
|
|
|
texture(read_fbo); |
|
|
mshader.begin(); |
|
|
mshader.begin(); |
|
|
mshader.set_uniform("steps", counter); |
|
|
scene(); |
|
|
|
|
|
draw_fbo.end(); |
|
|
|
|
|
|
|
|
glRotatef(0.5, std::sin(counter/1337.0), 1.0, 0.0); |
|
|
texture_shader.begin(); |
|
|
|
|
|
texture(draw_fbo); |
|
|
|
|
|
|
|
|
scene(); |
|
|
//save_screen();
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void fade() { |
|
|
void fade() { |
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
static const GLfloat quad[] = { |
|
|
|
|
|
1.0, 1.0, |
|
|
|
|
|
1.0, -1.0, |
|
|
|
|
|
-1.0, -1.0, |
|
|
|
|
|
-1.0, 1.0 }; |
|
|
|
|
|
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
glVertexPointer(2, GL_FLOAT, 0, &quad[0]); |
|
|
glVertexPointer(2, GL_FLOAT, 0, &quad[0]); |
|
|
|
|
|
|
|
|
// draw a cube
|
|
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4); |
|
|
glDrawArrays(GL_QUADS, 0, 4); |
|
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void texture(fbo const & read_fbo) { |
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
|
|
texture_shader.set_texture("tex", GL_TEXTURE_2D, read_fbo.texture_id, 0); |
|
|
|
|
|
|
|
|
// deactivate vertex arrays after drawing
|
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, &quad[0]); |
|
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, &tex_quad[0]); |
|
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4); |
|
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void scene() { |
|
|
void scene() { |
|
|
glBlendFunc(GL_ONE, GL_ONE); |
|
|
glBlendFunc(GL_ONE, GL_ONE); |
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
|
|
|
glVertexPointer(3, GL_FLOAT, 0, &lines[0]); |
|
|
|
|
|
|
|
|
|
|
|
// draw a cube
|
|
|
mshader.set_uniform("steps", counter/10); |
|
|
glDrawArrays(GL_POINTS, 0, number_of_vertices); |
|
|
glRotatef(0.05, std::sin(counter/13370.0), 1.0, 0.0); |
|
|
|
|
|
|
|
|
// deactivate vertex arrays after drawing
|
|
|
const unsigned int part = 8; |
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
|
|
|
|
|
|
|
|
|
//save_screen();
|
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
|
|
|
glVertexPointer(3, GL_FLOAT, 0, &lines[0]); |
|
|
|
|
|
glPointSize(3.0); |
|
|
|
|
|
glDrawArrays(GL_POINTS, 0, number_of_vertices/part); |
|
|
|
|
|
glPointSize(1.0); |
|
|
|
|
|
glDrawArrays(GL_POINTS, number_of_vertices/part, (part-1)*number_of_vertices/part); |
|
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void iterate() { |
|
|
void iterate() { |
|
@ -159,7 +198,7 @@ public: |
|
|
for(unsigned int i = 0; i < 7; ++i) { |
|
|
for(unsigned int i = 0; i < 7; ++i) { |
|
|
stfu::node const attractorParameters = file.getChild("AttractorKernel").getChild("parameters"); |
|
|
stfu::node const attractorParameters = file.getChild("AttractorKernel").getChild("parameters"); |
|
|
parameters[i] = atof(attractorParameters.getValue(i).c_str()); |
|
|
parameters[i] = atof(attractorParameters.getValue(i).c_str()); |
|
|
random_parameters[i] = (rand() / (double)RAND_MAX - 0.5) * counter / 500000.0; |
|
|
random_parameters[i] = (rand() / (double)RAND_MAX - 0.5) * counter / 5000000.0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|