Created
October 10, 2014 00:43
-
-
Save trentbrooks/fed01ddaa48591dbd50d to your computer and use it in GitHub Desktop.
midmapped fbo
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" | |
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