void ofxPanel::render(){ border.draw(); headerBg.draw(); ofBlendMode blendMode = ofGetStyle().blendingMode; if(blendMode!=OF_BLENDMODE_ALPHA){ ofEnableAlphaBlending(); } ofColor c = ofGetStyle().color; ofSetColor(thisTextColor); bindFontTexture(); textMesh.draw(); unbindFontTexture(); bool texHackEnabled = ofIsTextureEdgeHackEnabled(); ofDisableTextureEdgeHack(); loadIcon.draw(loadBox); saveIcon.draw(saveBox); if(texHackEnabled){ ofEnableTextureEdgeHack(); } for(int i = 0; i < (int)collection.size(); i++){ collection[i]->draw(); } ofSetColor(c); if(blendMode!=OF_BLENDMODE_ALPHA){ ofEnableBlendMode(blendMode); } }
void ofxPanel::render(){ border.draw(); headerBg.draw(); ofBlendMode blendMode = ofGetStyle().blendingMode; if(blendMode!=OF_BLENDMODE_ALPHA){ ofEnableAlphaBlending(); } ofColor c = ofGetStyle().color; ofSetColor(thisTextColor); bindFontTexture(); textMesh.draw(); unbindFontTexture(); bool texHackEnabled = ofIsTextureEdgeHackEnabled(); ofDisableTextureEdgeHack(); // loadIcon.draw(loadBox); // saveIcon.draw(saveBox); if(isDynamic){ ofSetColor(255,0,0); if(*isActive){ ofFill(); } else ofNoFill(); ofRect(activeBox); ofSetColor(0,255,0); if(*isPiping){ ofFill(); } else ofNoFill(); ofRect(pipeBox); } if(texHackEnabled){ ofEnableTextureEdgeHack(); } for(int i = 0; i < (int)collection.size(); i++){ collection[i]->draw(); } ofSetColor(c); if(blendMode!=OF_BLENDMODE_ALPHA){ ofEnableBlendMode(blendMode); } }
void ofxPanel::render(){ this->prerender(); ofColor c; ofBlendMode blendMode; bool performDraw = !useFbo || requiresRerender; if( performDraw ){ border.draw(); headerBg.draw(); blendMode = ofGetStyle().blendingMode; if(blendMode!=OF_BLENDMODE_ALPHA){ ofEnableAlphaBlending(); } c = ofGetStyle().color; ofSetColor(thisTextColor); bindFontTexture(); textMesh.draw(); unbindFontTexture(); bool texHackEnabled = ofIsTextureEdgeHackEnabled(); ofDisableTextureEdgeHack(); loadIcon.draw(loadBox); saveIcon.draw(saveBox); if(texHackEnabled){ ofEnableTextureEdgeHack(); } } int len = (int)collection.size(); for(int i = 0; i < len; i++){ collection[i]->draw(useFbo); } if( performDraw ){ ofSetColor(c); if(blendMode!=OF_BLENDMODE_ALPHA){ ofEnableBlendMode(blendMode); } requiresRerender = false; } this->postrender(); }
void mui::Helpers::drawImage( string name, float x, float y, float w, float h ){ // we have a retina version? const ofRectangle * rect = &mui::TextureAtlas::NOT_FOUND; if( mui::MuiConfig::useRetinaAssets ){ rect = &atlas.getRectRef(name + "@2x.png"); } if( rect == &mui::TextureAtlas::NOT_FOUND ){ rect = &atlas.getRectRef(name+".png"); } if( rect == &mui::TextureAtlas::NOT_FOUND ){ cerr << "Image: " << name << " not available. this is bad!" << endl; } else{ ofEnableTextureEdgeHack(); atlas.addDraw(x, y, w, h, *rect); } }
//----------------------------------------------------------------------------------------- // void ofApp::setup() { fontSmall.loadFont("Fonts/DIN.otf", 8 ); // Give us a starting point for the camera camera.setNearClip(0.01f); camera.setPosition( 0, 4, 10 ); camera.setMovementMaxSpeed( 0.1f ); int textureSize = 128; int numParticles = textureSize * textureSize; // Allocate buffers ofFbo::Settings fboSettings; fboSettings.width = textureSize; fboSettings.height = textureSize; // We can create several color buffers for one FBO if we want to store velocity for instance, // then write to them simultaneously from a shader using gl_FragData[0], gl_FragData[1], etc. fboSettings.numColorbuffers = 1; fboSettings.useDepth = false; fboSettings.internalformat = GL_RGBA32F; // Gotta store the data as floats, they won't be clamped to 0..1 fboSettings.textureTarget = GL_TEXTURE_2D; fboSettings.wrapModeHorizontal = GL_CLAMP_TO_EDGE; fboSettings.wrapModeVertical = GL_CLAMP_TO_EDGE; fboSettings.minFilter = GL_NEAREST; // No interpolation, that would mess up data reads later! fboSettings.maxFilter = GL_NEAREST; ofDisableTextureEdgeHack(); particleData.allocate( fboSettings ); ofEnableTextureEdgeHack(); particleMaxAge = 4.0; }
//----------------------------------------------------------------------------------------- // void ParticleSystemInstancedGeometryGPU::init( int _texSize ) { string xmlSettingsPath = "Settings/Particles.xml"; gui.setup( "Particles", xmlSettingsPath ); gui.add( particleMaxAge.set("Particle Max Age", 10.0f, 0.0f, 20.0f) ); gui.add( noiseMagnitude.set("Noise Magnitude", 0.075, 0.01f, 1.0f) ); gui.add( noisePositionScale.set("Noise Position Scale", 1.5f, 0.01f, 5.0f) ); gui.add( noiseTimeScale.set("Noise Time Scale", 1.0 / 4000.0, 0.001f, 1.0f) ); gui.add( noisePersistence.set("Noise Persistence", 0.2, 0.001f, 1.0f) ); gui.add( baseSpeed.set("Wind", ofVec3f(0.5,0,0), ofVec3f(-2,-2,-2), ofVec3f(2,2,2)) ); gui.add( startColor.set("Start Color", ofColor::white, ofColor(0,0,0,0), ofColor(255,255,255,255)) ); gui.add( endColor.set("End Color", ofColor(0,0,0,0), ofColor(0,0,0,0), ofColor(255,255,255,255)) ); //gui.add( twistNoiseTimeScale.set("Twist Noise Time Scale", 0.01, 0.0f, 0.5f) ); //gui.add( twistNoisePosScale.set("Twist Noise Pos Scale", 0.25, 0.0f, 2.0f) ); //gui.add( twistMinAng.set("Twist Min Ang", -1, -5, 5) ); //gui.add( twistMaxAng.set("Twist Max Ang", 2.5, -5, 5) ); gui.add( materialShininess.set("Material Shininess", 20, 0, 127) ); gui.add( materialAmbient.set("Material Ambient", ofColor(50,50,50), ofColor(0,0,0,0), ofColor(255,255,255,255)) ); gui.add( materialSpecular.set("Material Specular", ofColor(255,255,255), ofColor(0,0,0,0), ofColor(255,255,255,255)) ); gui.add( materialEmissive.set("Material Emmissive", ofColor(0,0,0), ofColor(0,0,0,0), ofColor(255,255,255,255)) ); gui.loadFromFile( xmlSettingsPath ); gui.minimizeAll(); gui.setPosition( ofGetWidth() - gui.getWidth() - 10, 10 ); // Load shaders particleUpdate.load("Shaders/Particles/GL2/Update"); particleDraw.load("Shaders/Particles/GL2/DrawInstancedGeometry"); // Set how many particles we are going to have, this is based on data texture size textureSize = 128; numParticles = textureSize * textureSize; // Allocate buffers ofFbo::Settings fboSettings; fboSettings.width = textureSize; fboSettings.height = textureSize; // We can create several color buffers for one FBO if we want to store velocity for instance, // then draw to them simultaneously from a shader using gl_FragData[0], gl_FragData[1], etc. fboSettings.numColorbuffers = 2; fboSettings.useDepth = false; fboSettings.internalformat = GL_RGBA32F; // Gotta store the data as floats, they won't be clamped to 0..1 fboSettings.textureTarget = GL_TEXTURE_2D; fboSettings.wrapModeHorizontal = GL_CLAMP_TO_EDGE; fboSettings.wrapModeVertical = GL_CLAMP_TO_EDGE; fboSettings.minFilter = GL_NEAREST; // No interpolation, that would mess up data reads later! fboSettings.maxFilter = GL_NEAREST; ofDisableTextureEdgeHack(); particleDataFbo.allocate( fboSettings ); ofEnableTextureEdgeHack(); // We are going to encode our data into the FBOs like this // // Buffer 1: XYZ pos, W age // Buffer 2: XYZ vel, W not used // // Initialise the starting and static data ofVec4f* startPositionsAndAge = new ofVec4f[numParticles]; int tmpIndex = 0; for( int y = 0; y < textureSize; y++ ) { for( int x = 0; x < textureSize; x++ ) { ofVec3f pos(0,0,0); //ofVec3f pos (MathUtils::randomPointOnSphere() * 0.1); //pos.set( ofRandom(-1,1), ofRandom(0,2), ofRandom(-1,1) ); float startAge = ofRandom( particleMaxAge ); // position is not very important, but age is, by setting the lifetime randomly somewhere in the middle we can get a steady stream emitting startPositionsAndAge[tmpIndex] = ofVec4f( pos.x, pos.y, pos.z, startAge ); tmpIndex++; } } // Upload it to the source texture particleDataFbo.source()->getTextureReference(0).loadData( (float*)&startPositionsAndAge[0].x, textureSize, textureSize, GL_RGBA ); ofPrimitiveMode primitiveMode = OF_PRIMITIVE_TRIANGLES; // as we'll be drawing ths mesh instanced many times, we need to have many triangles as opposed to one long triangle strip ofMesh tmpMesh; ofConePrimitive cone( 0.1, 0.1, 5, 2, primitiveMode ); //tmpMesh = cone.getMesh(); ofBoxPrimitive box( 0.0015, 0.0015, 0.01 ); // we gotta face in the -Z direction tmpMesh = box.getMesh(); singleParticleMesh.append( tmpMesh ); singleParticleMesh.setMode( primitiveMode ); }
//-------------------------------------------------------------- void testApp::setup() { int tabBarWidth = 80; // --- guiTabBar = new ofxUITabBar(); guiTabBar->setWidth(tabBarWidth); guiTabBar->setColorFill(ofxUIColor(200)); guiTabBar->setColorFillHighlight(ofxUIColor(255)); guiTabBar->setColorBack(ofxUIColor(255, 20, 20, 150)); // --- ofEnableTextureEdgeHack(); middle.loadImage("slidertrack.png"); middle.getTextureReference().setTextureWrap(GL_REPEAT, GL_REPEAT); middle.update(); ofEnableSmoothing(); ofSetCircleResolution(60); red = 100; blue = 100; green = 100; float dim = 24; float xInit = OFX_UI_GLOBAL_WIDGET_SPACING; float length = 320-xInit; drawPadding = false; // --- ofxUICanvas* guiA = new ofxUICanvas(tabBarWidth, 0, length+xInit, 100); guiA->setName("Main"); guiA->setPosition(tabBarWidth, 0); guiA->setColorFill(ofxUIColor(200)); guiA->setColorFillHighlight(ofxUIColor(255)); guiA->setColorBack(ofxUIColor(20, 20, 20, 150)); { guiA->addLabel("Tab Bar"); guiA->addSpacer(); guiA->addButton("SAVE", false); guiA->addButton("LOAD", false); } ofAddListener(guiA->newGUIEvent,this,&testApp::guiEvent); guiTabBar->addCanvas(guiA); // --- guiB = new ofxUICanvas(tabBarWidth, 0, length+xInit, ofGetHeight()); guiB->setName("Tab 2"); guiB->addWidgetDown(new ofxUILabel("SLIDER WIDGETS", OFX_UI_FONT_LARGE)); guiB->addSpacer(length-xInit, 1); guiB->addFPSSlider("FPS SLIDER", length-xInit, dim*.25, 1000); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("NORMAL SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addSlider("RED", 0.0, 255.0, red, length-xInit,dim); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("MINIMAL SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUIMinimalSlider(length-xInit, 0.0, 255.0, green, "GREEN", OFX_UI_FONT_MEDIUM)); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("BILABEL SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUIBiLabelSlider(length-xInit, 0.0, 255.0, blue, "BLUE", "LESS BLUE", "MORE BLUE", OFX_UI_FONT_MEDIUM)); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("VERTICAL SLIDERS", OFX_UI_FONT_MEDIUM)); guiB->addSlider("1", 0.0, 255.0, 100.0, dim,80); guiB->setWidgetPosition(OFX_UI_WIDGET_POSITION_RIGHT); guiB->addSlider("2", 0.0, 255.0, 150.0, dim, 80); guiB->addSlider("3", 0.0, 255.0, 200.0, dim, 80); guiB->addSlider("4", 0.0, 255.0, 250.0, dim, 80); guiB->setWidgetPosition(OFX_UI_WIDGET_POSITION_DOWN); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("RANGE SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUIRangeSlider(length-xInit,dim, 0.0, 255.0, 50.0, 100.0, "RSLIDER")); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("ROTARY SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUIRotarySlider(dim*2.0, 0.0, 100.0, 25.0, "CSLIDER 2")); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("2D PAD", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUI2DPad(length-xInit,80, ofPoint((length-xInit)*.5,80*.5), "PAD")); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("CIRCLE SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUICircleSlider(dim*2, 0.0, 255.0, green, "GREEN", OFX_UI_FONT_MEDIUM)); guiB->addSpacer(length-xInit, 1); guiB->addWidgetDown(new ofxUILabel("IMAGE SLIDER", OFX_UI_FONT_MEDIUM)); guiB->addWidgetDown(new ofxUIImageSlider(length-xInit, 42, 0.0, 255.0, red, "slider.png", "IMAGE SLIDER")); guiB->setColorBack(ofColor(255,100)); ofAddListener(guiB->newGUIEvent,this,&testApp::guiEvent); guiTabBar->addCanvas(guiB); ofBackground(red, green, blue); guiTabBar->loadSettings("settings/", "ui-"); }