|
|
@ -11,10 +11,68 @@ |
|
|
|
|
|
|
|
#include "stfu/stf.hpp" |
|
|
|
#include "pngwriter/pngwriter.h" |
|
|
|
#include "bmp.h" |
|
|
|
|
|
|
|
#include "shader.h" |
|
|
|
#include "fbo.h" |
|
|
|
|
|
|
|
static const unsigned int colors = 7; |
|
|
|
|
|
|
|
static const GLfloat color_transformations[][16] = { |
|
|
|
{ |
|
|
|
1.0, 0.0, 0.0, 0.0, |
|
|
|
0.0, 1.0, 0.0, 0.0, |
|
|
|
0.0, 0.0, 1.0, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
-0.1, -2.0, -0.9, 0.0, |
|
|
|
-0.4, -0.5, -0.9, 0.0, |
|
|
|
-2.0, -0.1, -0.9, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
0.1, 0.0, -0.9, 0.0, |
|
|
|
0.4, 1.0, 0.0, 0.0, |
|
|
|
0.0, 0.1, 0.3, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
0.5, -0.3, -0.5, 0.0, |
|
|
|
0.5, 0.0, -0.5, 0.0, |
|
|
|
0.5, 1.0, -0.5, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
0.0, 0.0, 0.0, 0.0, |
|
|
|
0.0, 0.0, 0.0, 0.0, |
|
|
|
0.0, 0.0, 0.0, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
5.0, -1.0, -5.0, 0.0, |
|
|
|
-5.0, 5.0, -1.0, 0.0, |
|
|
|
-1.0, -5.0, 5.0, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
}, |
|
|
|
{ |
|
|
|
1.0, 1.0, 1.0, 0.0, |
|
|
|
0.0, 1.0, 0.0, 0.0, |
|
|
|
0.0, 1.0, 0.8, 0.0, |
|
|
|
0.0, 0.0, 0.0, 1.0 |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
static const GLfloat background_colors[][4] = { |
|
|
|
{ 0.0, 0.0, 0.0, 0.0 }, |
|
|
|
{ 1.0, 1.0, 1.0, 0.0 }, |
|
|
|
{ 0.4, 0.0, 0.0, 0.0 }, |
|
|
|
{ 0.5, 0.5, 0.5, 0.0 }, |
|
|
|
{ 0.0, 0.5, 0.1, 0.0 }, |
|
|
|
{ -0.5, -0.5, -0.5, 0.0}, |
|
|
|
{ 0.1, 0.0, 0.2, 0.0} |
|
|
|
}; |
|
|
|
|
|
|
|
static const GLfloat quad[] = { |
|
|
|
1.0, 1.0, |
|
|
|
1.0, -1.0, |
|
|
@ -27,10 +85,25 @@ static const GLfloat tex_quad[] = { |
|
|
|
0.0, 0.0, |
|
|
|
0.0, 1.0 }; |
|
|
|
|
|
|
|
static const GLfloat heart[] = { |
|
|
|
0.0, 0.3, |
|
|
|
0.06, 0.45, |
|
|
|
0.16, 0.5, |
|
|
|
0.3, 0.4, |
|
|
|
0.33, 0.25, |
|
|
|
0.0, -0.5, |
|
|
|
-0.33, 0.25, |
|
|
|
-0.3, 0.4, |
|
|
|
-0.16, 0.5, |
|
|
|
-0.06, 0.45, |
|
|
|
-0.0, 0.3 |
|
|
|
}; |
|
|
|
|
|
|
|
class App { |
|
|
|
public: |
|
|
|
int counter; |
|
|
|
int counter, counter2; |
|
|
|
unsigned int width, height; |
|
|
|
unsigned int color_scheme; |
|
|
|
|
|
|
|
shader mshader; |
|
|
|
shader clear_shader; |
|
|
@ -42,10 +115,15 @@ public: |
|
|
|
std::array<bool, 3> mouse_buttons; |
|
|
|
std::array<GLfloat, 2> mouse; |
|
|
|
|
|
|
|
std::array<GLfloat, 16> color_transformation; |
|
|
|
std::array<GLfloat, 4> background_color; |
|
|
|
|
|
|
|
App(unsigned int w, unsigned int h) : |
|
|
|
counter(0), |
|
|
|
counter2(0), |
|
|
|
width(w), |
|
|
|
height(h), |
|
|
|
color_scheme(6), |
|
|
|
mshader("resources/myTeaShader.vert", "resources/myTeaShader.frag"), |
|
|
|
clear_shader("resources/myClearShader.vert", "resources/myClearShader.frag"), |
|
|
|
texture_shader("resources/myTextureShader.vert", "resources/myTextureShader.frag"), |
|
|
@ -53,7 +131,9 @@ public: |
|
|
|
fbo1(width, height), |
|
|
|
fbo2(width, height), |
|
|
|
mouse_buttons{{false, false, false}}, |
|
|
|
mouse{{0.0f, 0.0f}}{ |
|
|
|
mouse{{0.0f, 0.0f}}, |
|
|
|
color_transformation(), |
|
|
|
background_color(){ |
|
|
|
|
|
|
|
//glEnable(GL_DEPTH_TEST);
|
|
|
|
glEnable(GL_BLEND); |
|
|
@ -67,16 +147,47 @@ public: |
|
|
|
std::cout << w << "x" << h << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
void pressed(char x){ |
|
|
|
switch(x){ |
|
|
|
case ' ': save_bmp(); break; |
|
|
|
case 'z': ++color_scheme %= colors; break; |
|
|
|
default: break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void update() { |
|
|
|
++counter; |
|
|
|
if(counter % 100 == 0){ |
|
|
|
std::cout << counter << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
const float fade_speed = 0.1; |
|
|
|
|
|
|
|
for(unsigned int i = 0; i < color_transformation.size(); ++i) |
|
|
|
color_transformation[i] = (1.0 - fade_speed)*color_transformation[i] + fade_speed*color_transformations[color_scheme][i]; |
|
|
|
for(unsigned int i = 0; i < background_color.size(); ++i) |
|
|
|
background_color[i] = (1.0 - fade_speed)*background_color[i] + fade_speed*background_colors[color_scheme][i]; |
|
|
|
} |
|
|
|
|
|
|
|
void draw() { |
|
|
|
fbo & read_fbo = (counter % 2) ? fbo1 : fbo2; |
|
|
|
fbo & draw_fbo = (counter % 2) ? fbo2 : fbo1; |
|
|
|
for(int i = 0; i < 2; ++i) |
|
|
|
magic(); |
|
|
|
auto const & draw_fbo = magic(); |
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
texture_shader.begin(); |
|
|
|
texture_shader.set_matrix("color_transformation", true, &color_transformation[0]); |
|
|
|
texture_shader.set_vector("background_color", &background_color[0]); |
|
|
|
texture(texture_shader, draw_fbo); |
|
|
|
|
|
|
|
//if(counter % 4 == 0)
|
|
|
|
// save_bmp();
|
|
|
|
} |
|
|
|
|
|
|
|
fbo const & magic(){ |
|
|
|
++counter2; |
|
|
|
fbo & read_fbo = (counter2 % 2) ? fbo1 : fbo2; |
|
|
|
fbo & draw_fbo = (counter2 % 2) ? fbo2 : fbo1; |
|
|
|
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
@ -87,7 +198,7 @@ public: |
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
blur_shader.begin(); |
|
|
|
blur_shader.set_uniform("offset", (float) cos(counter) / width, (float) sin(counter) / height); |
|
|
|
blur_shader.set_uniform("offset", (float) cos(counter2) / width * 2.0f, (float) sin(counter2) / height * 2.0f); |
|
|
|
if(true){ |
|
|
|
blur_shader.set_uniform("fade", 0.75f); |
|
|
|
blur_shader.set_uniform("inter", 0.55f); |
|
|
@ -101,12 +212,7 @@ public: |
|
|
|
scene(); |
|
|
|
draw_fbo.end(); |
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
texture_shader.begin(); |
|
|
|
texture(texture_shader, draw_fbo); |
|
|
|
|
|
|
|
if(counter % 4 == 0) |
|
|
|
save_screen(); |
|
|
|
return draw_fbo; |
|
|
|
} |
|
|
|
|
|
|
|
void fade() { |
|
|
@ -137,10 +243,20 @@ public: |
|
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
|
glVertexPointer(2, GL_FLOAT, 0, &mouse[0]); |
|
|
|
glPointSize(50.0); |
|
|
|
glPointSize(50.0/1.0); |
|
|
|
glDrawArrays(GL_POINTS, 0, 1); |
|
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
|
} |
|
|
|
if(counter < 50 || counter > 1200){ |
|
|
|
mshader.set_uniform("steps", counter/10); |
|
|
|
mshader.set_uniform("button", counter % 4); |
|
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY); |
|
|
|
glVertexPointer(2, GL_FLOAT, 0, &heart[0]); |
|
|
|
glLineWidth(15.0); |
|
|
|
glDrawArrays(GL_LINE_STRIP, 0, 11); |
|
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void save_screen(){ |
|
|
@ -153,6 +269,20 @@ public: |
|
|
|
pngwriter png(width, height, &data[0], filename); |
|
|
|
png.close(); |
|
|
|
} |
|
|
|
|
|
|
|
void save_bmp(){ |
|
|
|
unsigned char data[width*height*3]; |
|
|
|
glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, data); |
|
|
|
|
|
|
|
char filename[256]; |
|
|
|
sprintf(filename, "render/shot_%08d.bmp", counter); |
|
|
|
|
|
|
|
bmp::bitmap<GLubyte> image(width, height); |
|
|
|
image.data = data; |
|
|
|
|
|
|
|
std::ofstream file(filename); |
|
|
|
image.write(file); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
#endif // APP_H
|
|
|
|