[ Video ]
[ About ]
ofFboをテキスチャにしてofMeshへバインドする。
ofMeshの座標を回転させて遊ぶ。
Texture the ofFbo and bind it to the ofMesh.
Play with the coordinates ofMesh by rotating it.
[ 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 27 28 29 30 |
#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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; vector<ofPixels> pixcels_list; ofTrueTypeFont font; int font_size; vector<vector<ofMesh>> face_list; }; |
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(239); ofSetLineWidth(2); ofEnableDepthTest(); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->font_size = 195; ofTrueTypeFontSettings font_settings("fonts/msgothic.ttc", this->font_size); font_settings.antialiased = true; font_settings.addRanges(ofAlphabet::Japanese); this->font.load(font_settings); ofFbo fbo; ofPixels pixcels; fbo.allocate(320, 320); fbo.begin(); ofClear(0); ofBackground(0); ofTranslate(fbo.getWidth() * 0.5, fbo.getHeight() * 0.5); ofSetColor(255); this->font.drawString(u8"壱", -130, 90); ofNoFill(); ofDrawRectangle(glm::vec2(0, 0), 300, 300); fbo.end(); fbo.readToPixels(pixcels); this->pixcels_list.push_back(pixcels); fbo.begin(); ofClear(0); ofBackground(0); ofTranslate(fbo.getWidth() * 0.5, fbo.getHeight() * 0.5); ofSetColor(255); this->font.drawString(u8"零", -130, 90); ofNoFill(); ofDrawRectangle(glm::vec2(0, 0), 300, 300); fbo.end(); fbo.readToPixels(pixcels); this->pixcels_list.push_back(pixcels); } //-------------------------------------------------------------- void ofApp::update() { this->face_list.clear(); int x_span = 20; int y_span = 5; for (int i = 0; i < 2; i++) { vector<ofMesh> mesh_list; for (int x = 0; x < 320; x += x_span) { ofMesh mesh; for (int y = 0; y < 320; y += y_span) { int index = mesh.getNumVertices(); float z = -160; vector<glm::vec3> vertices; vertices.push_back(glm::vec3(x, y, z) - glm::vec3(160, 160, 0)); vertices.push_back(glm::vec3(x + x_span, y, z) - glm::vec3(160, 160, 0)); vertices.push_back(glm::vec3(x + x_span, y + y_span, z) - glm::vec3(160, 160, 0)); vertices.push_back(glm::vec3(x, y + y_span, z) - glm::vec3(160, 160, 0)); auto deg = (x / 3 + ofGetFrameNum()) % 360; if (deg < 90) { deg = 0; } else if (deg < 180) { deg = ofMap(deg, 90, 180, 0, 180); } else if (deg < 270) { deg = 180; } else if (deg < 360) { deg = ofMap(deg, 270, 360, 180, 360); } deg += i * 180; auto rotation_x = glm::rotate(glm::mat4(), deg * (float)DEG_TO_RAD, glm::vec3(1, 0, 0)); for (auto& vertex : vertices) { vertex = glm::vec4(vertex, 0) * rotation_x; } mesh.addVertices(vertices); mesh.addTexCoord(glm::vec3(x, y, 0)); mesh.addTexCoord(glm::vec3(x + x_span, y, 0)); mesh.addTexCoord(glm::vec3(x + x_span, y + y_span, 0)); mesh.addTexCoord(glm::vec3(x, y + y_span, 0)); mesh.addIndex(index + 0); mesh.addIndex(index + 1); mesh.addIndex(index + 2); mesh.addIndex(index + 0); mesh.addIndex(index + 2); mesh.addIndex(index + 3); } mesh_list.push_back(mesh); } this->face_list.push_back(mesh_list); } } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateX(180); int i = 0; for (auto& mesh_list : this->face_list) { ofImage image; image.setFromPixels(this->pixcels_list[i++]); for (auto& mesh : mesh_list) { image.bind(); mesh.draw(); image.unbind(); } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |