Created
March 12, 2017 19:25
-
-
Save mfandl/77988643d4f6f79789fe81e0c92a4606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
#include "ofApp.h" | |
//======================================================================== | |
int main( ){ | |
ofGLFWWindowSettings settings; | |
settings.windowMode = OF_FULLSCREEN; | |
settings.glVersionMajor = 4; | |
settings.glVersionMinor = 1; | |
ofCreateWindow(settings); | |
ofRunApp(new ofApp()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
ofSetBackgroundColor(0, 0, 0); | |
shader.load("shaders/shader"); | |
const float side = 4.0; | |
const vector<float> vertices { | |
side, side, 0.0f, | |
-side, side, 0.0f, | |
side, -side, 0.0f, | |
-side, -side, 0.0f | |
}; | |
const vector<ofIndexType> indices {0, 1, 2, 1, 2, 3}; | |
for (int i = 0; i < 10000; ++i) { | |
ofVec2f pos {ofRandom(ofGetWidth()), ofRandom(ofGetHeight())}; | |
shared_ptr<ofVboMesh> mesh = make_shared<ofVboMesh>(); | |
for (int j = 0; j < vertices.size(); j += 3) { | |
ofVec3f vertex { | |
vertices[j] + pos.x, | |
vertices[j + 1] + pos.y, | |
vertices[j + 2] | |
}; | |
mesh->addVertex(vertex); | |
} | |
mesh->addIndices(indices); | |
meshes.push_back(mesh); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofDrawBitmapString(ofGetFrameRate(), 100, 100); | |
shader.begin(); | |
shader.setUniform1f("elapsedTime", ofGetElapsedTimef()); | |
for (const auto& mesh : meshes) { | |
mesh->draw(); | |
} | |
shader.end(); | |
} | |
void ofApp::generateMeshes() { | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
private: | |
size_t elementsCount; | |
size_t verticesPerElement; | |
ofShader shader; | |
vector<shared_ptr<ofVboMesh>> meshes; | |
void generateMeshes(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 150 | |
out vec4 outputColor; | |
void main() | |
{ | |
outputColor = vec4(1.0, 1.0, 1.0, 1.0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 150 | |
uniform mat4 modelViewProjectionMatrix; | |
uniform float elapsedTime; | |
in vec4 position; | |
void main(){ | |
gl_Position = modelViewProjectionMatrix * vec4(position.x + sin(elapsedTime) * 10, position.y + cos(elapsedTime) * 10, position.z, position.w); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment