Created
December 2, 2022 17:04
-
-
Save danzeeeman/0ca224c19c7ef162792b99b87735d0df to your computer and use it in GitHub Desktop.
write an openframeworks application that has a slider controlling a shader and an osc sender that sends out current time
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 "ofxOsc.h" | |
// application settings | |
const int APP_WIDTH = 1280; | |
const int APP_HEIGHT = 720; | |
const string OSC_HOST = "localhost"; | |
const int OSC_PORT = 8888; | |
// osc sender | |
ofxOscSender oscSender; | |
// shader | |
ofShader shader; | |
// time | |
float time = 0; | |
class ofApp : public ofBaseApp { | |
public: | |
// setup | |
void setup() { | |
// setup window | |
ofSetWindowShape(APP_WIDTH, APP_HEIGHT); | |
ofSetFrameRate(60); | |
// setup osc sender | |
oscSender.setup(OSC_HOST, OSC_PORT); | |
// setup shader | |
shader.load("shader"); | |
} | |
// update | |
void update() { | |
// update time | |
time += ofGetLastFrameTime(); | |
} | |
// draw | |
void draw() { | |
// bind shader | |
shader.begin(); | |
// set time uniform | |
shader.setUniform1f("time", time); | |
// draw quad | |
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); | |
// unbind shader | |
shader.end(); | |
// send osc message | |
ofxOscMessage message; | |
message.setAddress("/time"); | |
message.addFloatArg(time); | |
oscSender.sendMessage(message); | |
} | |
// mouse moved | |
void mouseMoved(int x, int y) { | |
// set mouse position uniform | |
shader.setUniform2f("mouse", x, y); | |
} | |
// mouse dragged | |
void mouseDragged(int x, int y, int button) { | |
// set mouse position uniform | |
shader.setUniform2f("mouse", x, y); | |
} | |
}; | |
int main() { | |
ofSetupOpenGL(APP_WIDTH, APP_HEIGHT, OF_WINDOW); | |
ofRunApp(new ofApp()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment