Skip to content

Instantly share code, notes, and snippets.

@trentbrooks
Created October 10, 2014 00:43
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 trentbrooks/fed01ddaa48591dbd50d to your computer and use it in GitHub Desktop.
Save trentbrooks/fed01ddaa48591dbd50d to your computer and use it in GitHub Desktop.
midmapped fbo
#include "ofMain.h"
void enableMidmap(ofTexture& texture) {
texture.bind();
int textureTarget = texture.getTextureData().textureTarget;
glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D); // automatically creates midmaps for textures
texture.unbind();
}
class ofApp : public ofBaseApp{
public:
ofVideoGrabber cam;
ofFbo fbo;
void setup() {
ofDisableArbTex();
cam.initGrabber(1920, 1080);
fbo.allocate(1920, 1080);
}
void update() {
cam.update();
if(cam.isFrameNew()) {
enableMidmap(cam.getTextureReference());
}
}
void draw() {
fbo.begin();
cam.draw(0, 0);
fbo.end();
enableMidmap(fbo.getTextureReference());
ofPushMatrix();
ofPushStyle();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
float s = ofMap(ofGetMouseX(), 0, ofGetWidth(), 0, 2);
ofScale(s,s);
ofTexture & t = fbo.getTextureReference();
t.draw(-t.getWidth()/2, -t.getHeight()/2);
ofPopStyle();
ofPopMatrix();
}
};
//========================================================================
int main( ){
ofSetupOpenGL(1024,768, OF_WINDOW);
ofRunApp( new ofApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment