Skip to content

Instantly share code, notes, and snippets.

@danzeeeman
Created December 2, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danzeeeman/0ca224c19c7ef162792b99b87735d0df to your computer and use it in GitHub Desktop.
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
#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