[ Video ]
[ About ]
あけましておめでとうございます。何となく始めた毎日投稿も気づけば3年目。なるべく続けられるようにします
A happy new year.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {}; void keyReleased(int key) {}; void mouseMoved(int x, int y) {}; void mouseDragged(int x, int y, int button) {}; void mousePressed(int x, int y, int button) {}; void mouseReleased(int x, int y, int button) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofShader shader; ofTrueTypeFont font; ofFbo tex1; ofFbo tex2; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(0); ofEnableDepthTest(); this->shader.load("shader/shader.vert", "shader/shader.frag"); this->font.loadFont("fonts/Kazesawa-bold.ttf", 150, true, true, true); this->tex1.allocate(ofGetWidth(), ofGetHeight()); this->tex2.allocate(ofGetWidth(), ofGetHeight()); this->tex1.begin(); ofClear(0); string word = "2019"; this->font.drawString(word, ofGetWidth() * 0.5 - this->font.stringWidth(word) * 0.5, ofGetHeight() - this->font.stringHeight(word) * 0.5); ofBeginShape(); for (int deg = 0; deg < 360; deg += 5) { ofVertex(200 * cos(deg * DEG_TO_RAD) + ofGetWidth() * 0.5, 200 * sin(deg * DEG_TO_RAD) + ofGetHeight() * 0.35); } ofEndShape(); this->tex1.end(); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); this->tex2.begin(); ofClear(0); for (int i = 0; i < 8; i++) { vector<glm::vec2> vertices; float noise_seed = ofRandom(1000); float noise_step = ofRandom(0.001, 0.0005); for (int x = 0; x <= ofGetWidth(); x += 10) { vertices.push_back(glm::vec2(x, ofNoise(noise_seed, x * noise_step, ofGetFrameNum() * 0.001) * ofGetHeight())); } int count = vertices.size(); for (int vertices_index = count - 1; vertices_index > -1; vertices_index--) { vertices.push_back(vertices[vertices_index] - glm::vec2(0, -5)); } ofBeginShape(); ofVertices(vertices); ofEndShape(); } this->tex2.end(); } //-------------------------------------------------------------- void ofApp::draw() { ofFill(); this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniformTexture("tex1", this->tex1.getTexture(), 1); this->shader.setUniformTexture("tex2", this->tex2.getTexture(), 2); ofDrawRectangle(glm::vec2(0, 0), ofGetWidth(), ofGetHeight()); this->shader.end(); } //-------------------------------------------------------------- int main() { ofGLWindowSettings settings; settings.setGLVersion(3, 2); settings.setSize(720, 720); ofCreateWindow(settings); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 |
#version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; in vec2 texcoord; out vec2 texCoordVarying; void main(){ texCoordVarying = texcoord; gl_Position = modelViewProjectionMatrix * position; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#version 150 uniform float time; uniform vec2 resolution; uniform sampler2DRect tex1; uniform sampler2DRect tex2; in vec2 texCoordVarying; out vec4 outputColor; void main() { vec4 t1 = texture(tex1, vec2(gl_FragCoord.x, resolution.y - gl_FragCoord.y)); vec4 t2 = texture(tex2, vec2(gl_FragCoord.x, resolution.y - gl_FragCoord.y)); vec4 c; if(t1 == t2){ c = vec4(vec3(0.937), 1.0); }else{ c = vec4(vec3(0.5450, 0.153, 0.153), 1.0); } outputColor = c; } |