The prototype of Zen Zoom. Made on ubuntu, I guess.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

158 lines
3.7 KiB

#ifndef APP_H
#define APP_H
#include <algorithm>
#include <iterator>
#include <iostream>
#include <fstream>
#include <cmath>
#include <array>
#include <ratio>
#include "stfu/stf.hpp"
#include "pngwriter/pngwriter.h"
#include "shader.h"
#include "fbo.h"
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 {
public:
int counter;
unsigned int width, height;
shader mshader;
shader clear_shader;
shader texture_shader;
shader blur_shader;
fbo fbo1;
fbo fbo2;
std::array<bool, 3> mouse_buttons;
std::array<GLfloat, 2> mouse;
App(unsigned int w, unsigned int h) :
counter(0),
width(w),
height(h),
mshader("resources/myTeaShader.vert", "resources/myTeaShader.frag"),
clear_shader("resources/myClearShader.vert", "resources/myClearShader.frag"),
texture_shader("resources/myTextureShader.vert", "resources/myTextureShader.frag"),
blur_shader("resources/myHBlurShader.vert", "resources/myHBlurShader.frag"),
fbo1(width, height),
fbo2(width, height),
mouse_buttons{{false, false, false}},
mouse{{0.0f, 0.0f}}{
//glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
}
~App() {
}
void resize(int w, int h) {
std::cout << w << "x" << h << std::endl;
}
void update() {
++counter;
if(counter % 100 == 0){
std::cout << counter << std::endl;
}
}
void draw() {
fbo & read_fbo = (counter % 2) ? fbo1 : fbo2;
fbo & draw_fbo = (counter % 2) ? fbo2 : fbo1;
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
draw_fbo.begin();
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);
if(true){
blur_shader.set_uniform("fade", 0.75f);
blur_shader.set_uniform("inter", 0.55f);
} else {
blur_shader.set_uniform("fade", 0.96f);
blur_shader.set_uniform("inter", 0.9f);
}
texture(blur_shader, read_fbo);
mshader.begin();
glBlendFunc(GL_ONE, GL_ONE);
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();
}
void fade() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, &quad[0]);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
}
void texture(shader const & tex_shader, fbo const & read_fbo) {
tex_shader.set_texture("tex", GL_TEXTURE_2D, read_fbo.texture_id, 0);
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);
}
void scene() {
if(mouse_buttons[0] || mouse_buttons[1] || mouse_buttons[2]){
mshader.set_uniform("steps", counter/10);
mshader.set_uniform("button", (mouse_buttons[0] ? 0 : (mouse_buttons[1] ? 1 : 2)));
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, &mouse[0]);
glPointSize(50.0);
glDrawArrays(GL_POINTS, 0, 1);
glDisableClientState(GL_VERTEX_ARRAY);
}
}
void save_screen(){
unsigned char data[width*height*6];
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_SHORT, data);
char filename[256];
sprintf(filename, "render/shot_%08d.png", counter);
pngwriter png(width, height, &data[0], filename);
png.close();
}
};
#endif // APP_H