void ofMaterial::end() { #ifndef TARGET_PROGRAMMABLE_GL if(!ofIsGLProgrammableRenderer()){ #ifndef TARGET_OPENGLES // Set previous material colors and properties glMaterialfv(GL_FRONT, GL_DIFFUSE, &prev_data.diffuse.r); glMaterialfv(GL_FRONT, GL_SPECULAR, &prev_data.specular.r); glMaterialfv(GL_FRONT, GL_AMBIENT, &prev_data.ambient.r); glMaterialfv(GL_FRONT, GL_EMISSION, &prev_data.emissive.r); glMaterialfv(GL_FRONT, GL_SHININESS, &prev_data.shininess); glMaterialfv(GL_BACK, GL_DIFFUSE, &prev_data_back.diffuse.r); glMaterialfv(GL_BACK, GL_SPECULAR, &prev_data_back.specular.r); glMaterialfv(GL_BACK, GL_AMBIENT, &prev_data_back.ambient.r); glMaterialfv(GL_BACK, GL_EMISSION, &prev_data_back.emissive.r); glMaterialfv(GL_BACK, GL_SHININESS, &prev_data_back.shininess); #else // opengl es 1.1 implementation must use GL_FRONT_AND_BACK. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &prev_data.diffuse.r); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &prev_data.specular.r); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &prev_data.ambient.r); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &prev_data.emissive.r); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &prev_data.shininess); #endif } #endif if(ofIsGLProgrammableRenderer()){ ofGetGLProgrammableRenderer()->setCurrentMaterial(NULL); if(currentShader) currentShader->end(); currentShader = NULL; } }
//-------------------------------------------------------------- void ofVbo::setAttributeData(int location, const float * attrib0x, int numCoords, int total, int usage, int stride){ if(location==ofShader::POSITION_ATTRIBUTE){ #if defined(TARGET_ANDROID) || defined(TARGET_OF_IOS) registerVbo(this); #endif if(ofIsGLProgrammableRenderer()){ totalVerts = total; #ifdef TARGET_OPENGLES glGenVertexArrays = (glGenVertexArraysType)dlsym(RTLD_DEFAULT, "glGenVertexArrays"); glDeleteVertexArrays = (glDeleteVertexArraysType)dlsym(RTLD_DEFAULT, "glDeleteVertexArrays"); glBindVertexArray = (glBindVertexArrayType)dlsym(RTLD_DEFAULT, "glBindVertexArrayArrays"); #endif } } bool normalize = false; if(!hasAttribute(location)){ vaoChanged = true; if (ofIsGLProgrammableRenderer()) { bUsingVerts |= (location == ofShader::POSITION_ATTRIBUTE); bUsingColors |= (location == ofShader::COLOR_ATTRIBUTE); bUsingNormals |= (location == ofShader::NORMAL_ATTRIBUTE); bUsingTexCoords |= (location == ofShader::TEXCOORD_ATTRIBUTE); } } getOrCreateAttr(location).setData(attrib0x,numCoords,total,usage,stride,normalize); }
//--------------------------------- int ofGetGlInternalFormat(const ofFloatPixels& pix) { #ifndef TARGET_OPENGLES switch(pix.getNumChannels()) { case 3: return GL_RGB32F; case 4: return GL_RGBA32F; case 2: if(ofIsGLProgrammableRenderer()){ return GL_RG32F; }else{ return GL_LUMINANCE_ALPHA32F_ARB; } default: if(ofIsGLProgrammableRenderer()){ return GL_R32F; }else{ return GL_LUMINANCE32F_ARB; } } #else ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): float textures not supported in OpenGL ES"; switch(pix.getNumChannels()) { case 3: return GL_RGB; case 4: return GL_RGBA; case 2: return GL_LUMINANCE_ALPHA; default: return GL_LUMINANCE; } #endif }
//--------------------------------- int ofGetGlInternalFormat(const ofShortPixels& pix) { #ifndef TARGET_OPENGLES switch(pix.getNumChannels()) { case 3: return GL_RGB16; case 4: return GL_RGBA16; case 2: if(ofIsGLProgrammableRenderer()){ return GL_RG16; }else{ return GL_LUMINANCE16_ALPHA16; } default: if(ofIsGLProgrammableRenderer()){ return GL_R16; }else{ return GL_LUMINANCE16; } } #else ofLogWarning("ofGLUtils") << "ofGetGlInternalFormat(): 16bit textures are not supported in OpenGL ES"; switch(pix.getNumChannels()) { case 3: return GL_RGB; case 4: return GL_RGBA; case 2: return GL_LUMINANCE_ALPHA; default: return GL_LUMINANCE; } #endif }
//-------------------------------------------------------------- bool ofFbo::checkGLSupport() { #ifndef TARGET_OPENGLES if (!ofIsGLProgrammableRenderer()){ if(ofGLCheckExtension("GL_EXT_framebuffer_object")){ ofLogVerbose("ofFbo") << "GL frame buffer object supported"; }else{ ofLogError("ofFbo") << "GL frame buffer object not supported by this graphics card"; return false; } } glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &_maxColorAttachments); glGetIntegerv(GL_MAX_DRAW_BUFFERS, &_maxDrawBuffers); glGetIntegerv(GL_MAX_SAMPLES, &_maxSamples); ofLogVerbose("ofFbo") << "checkGLSupport(): " << "maxColorAttachments: " << _maxColorAttachments << ", " << "maxDrawBuffers: " << _maxDrawBuffers << ", " << "maxSamples: " << _maxSamples; #else if(ofIsGLProgrammableRenderer() || ofGLCheckExtension("GL_OES_framebuffer_object")){ ofLogVerbose("ofFbo") << "GL frame buffer object supported"; }else{ ofLogError("ofFbo") << "GL frame buffer object not supported by this graphics card"; return false; } #endif return true; }
//--------------------------------- int ofGetGlInternalFormat(const ofPixels& pix) { #ifndef TARGET_OPENGLES switch(pix.getNumChannels()) { case 3: return GL_RGB8; case 4: return GL_RGBA8; case 2: if(ofIsGLProgrammableRenderer()){ return GL_RG8; }else{ return GL_LUMINANCE_ALPHA; } default: if(ofIsGLProgrammableRenderer()){ return GL_R8; }else{ return GL_LUMINANCE8; } } #else switch(pix.getNumChannels()) { case 3: return GL_RGB; case 4: return GL_RGBA; case 2: return GL_LUMINANCE_ALPHA; default: return GL_LUMINANCE; } #endif }
//---------------------------------------------------------- void ofFbo::updateTexture(int attachmentPoint) { if(!bIsAllocated) return; #ifndef TARGET_OPENGLES if(fbo != fboTextures && dirty[attachmentPoint]) { // if fbo != fboTextures, we are dealing with an MSAA enabled FBO. // and we need to blit one fbo into another to see get the texture // content if (!ofIsGLProgrammableRenderer()){ // save current drawbuffer glPushAttrib(GL_COLOR_BUFFER_BIT); } auto renderer = settings.renderer.lock(); if(renderer){ renderer->bindForBlitting(*this,*this,attachmentPoint); glBlitFramebuffer(0, 0, settings.width, settings.height, 0, 0, settings.width, settings.height, GL_COLOR_BUFFER_BIT, GL_NEAREST); renderer->unbind(*this); glReadBuffer(GL_BACK); } if(!ofIsGLProgrammableRenderer()){ // restore current drawbuffer glPopAttrib(); } dirty[attachmentPoint] = false; } #endif }
int ofGetGLInternalFormatFromPixelFormat(ofPixelFormat pixelFormat){ switch(pixelFormat){ case OF_PIXELS_BGRA: case OF_PIXELS_RGBA: #ifndef TARGET_OPENGLES return GL_RGBA8; #else return GL_RGBA; #endif case OF_PIXELS_RGB: case OF_PIXELS_BGR: #ifndef TARGET_OPENGLES return GL_RGB8; #else return GL_RGB; #endif case OF_PIXELS_RGB565: #if defined(TARGET_ANDROID) || defined(TARGET_RASPBERRY_PI) return GL_RGB565_OES; #elif defined(GL_RGB565) return GL_RGB565; #else return GL_RGB; #endif case OF_PIXELS_GRAY: case OF_PIXELS_NV12: case OF_PIXELS_NV21: case OF_PIXELS_YV12: case OF_PIXELS_I420: case OF_PIXELS_Y: case OF_PIXELS_U: case OF_PIXELS_V: #ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_R8; }else{ #endif return GL_LUMINANCE; #ifndef TARGET_OPENGLES } #endif case OF_PIXELS_GRAY_ALPHA: case OF_PIXELS_YUY2: case OF_PIXELS_UV: case OF_PIXELS_VU: #ifndef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()){ return GL_RG8; }else{ #endif return GL_LUMINANCE_ALPHA; #ifndef TARGET_OPENGLES } #endif default: ofLogError("ofGLUtils") << "ofGetGLInternalFormatFromPixelFormat(): unknown OF pixel format" << pixelFormat << ", returning GL_RGBA"; return GL_RGBA; } }
void ofxBlur::setup(int width, int height, int radius, float shape, int passes, float downsample) { string blurSource = generateBlurSource(radius, shape); if(ofGetLogLevel() == OF_LOG_VERBOSE) { cout << "ofxBlur is loading blur shader:" << endl << blurSource << endl; } if( ofIsGLProgrammableRenderer() ){ blurShader.setupShaderFromSource(GL_VERTEX_SHADER, getProgrammableRendererVertexSource()); } blurShader.setupShaderFromSource(GL_FRAGMENT_SHADER, blurSource); blurShader.linkProgram(); if(passes > 1) { string combineSource = generateCombineSource(passes, downsample); if(ofGetLogLevel() == OF_LOG_VERBOSE) { cout << "ofxBlur is loading combine shader:" << endl << combineSource << endl; } if( ofIsGLProgrammableRenderer() ){ combineShader.setupShaderFromSource(GL_VERTEX_SHADER, getProgrammableRendererVertexSource()); } combineShader.setupShaderFromSource(GL_FRAGMENT_SHADER, combineSource); combineShader.linkProgram(); } base.allocate(width, height); base.begin(); ofClear(0); base.end(); ofFbo::Settings settings; settings.useDepth = false; settings.useStencil = false; settings.numSamples = 0; settings.textureTarget = GL_TEXTURE_RECTANGLE_ARB; ping.resize(passes); pong.resize(passes); for(int i = 0; i < passes; i++) { ofLogVerbose() << "building ping/pong " << width << "x" << height; settings.width = width; settings.height = height; ping[i].allocate(settings); ping[i].begin(); ofClear(0,0,0,0); ping[i].end(); pong[i].allocate(settings); pong[i].begin(); ofClear(0,0,0,0); pong[i].end(); // ping[i].setDefaultTextureIndex(i); // pong[i].setDefaultTextureIndex(i); width *= downsample; height *= downsample; } }
//-------------------------------------------------------------- void ofVbo::unbind() const{ if(supportVAOs){ glBindVertexArray(0); if(!ofIsGLProgrammableRenderer()){ glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if(bUsingColors){ #ifndef TARGET_PROGRAMMABLE_GL glDisableClientState(GL_COLOR_ARRAY); #endif } if(bUsingNormals){ #ifndef TARGET_PROGRAMMABLE_GL glDisableClientState(GL_NORMAL_ARRAY); #endif } if(bUsingTexCoords){ #ifndef TARGET_PROGRAMMABLE_GL glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif } } }else{ glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if(ofIsGLProgrammableRenderer()){ if(bUsingColors){ glDisableVertexAttribArray(ofShader::COLOR_ATTRIBUTE); } if(bUsingNormals){ glDisableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE); } if(bUsingTexCoords){ glDisableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE); } }else{ #ifndef TARGET_PROGRAMMABLE_GL if(bUsingColors){ glDisableClientState(GL_COLOR_ARRAY); } if(bUsingNormals){ glDisableClientState(GL_NORMAL_ARRAY); } if(bUsingTexCoords){ glDisableClientState(GL_TEXTURE_COORD_ARRAY); } #endif } } bBound = false; }
void ofMaterial::begin() { #ifndef TARGET_PROGRAMMABLE_GL if(!ofIsGLProgrammableRenderer()){ #ifndef TARGET_OPENGLES // save previous values, opengl es cannot use push/pop attrib glGetMaterialfv(GL_FRONT,GL_DIFFUSE,&prev_data.diffuse.r); glGetMaterialfv(GL_FRONT,GL_SPECULAR,&prev_data.specular.r); glGetMaterialfv(GL_FRONT,GL_AMBIENT,&prev_data.ambient.r); glGetMaterialfv(GL_FRONT,GL_EMISSION,&prev_data.emissive.r); glGetMaterialfv(GL_FRONT, GL_SHININESS, &prev_data.shininess); glGetMaterialfv(GL_BACK,GL_DIFFUSE,&prev_data_back.diffuse.r); glGetMaterialfv(GL_BACK,GL_SPECULAR,&prev_data_back.specular.r); glGetMaterialfv(GL_BACK,GL_AMBIENT,&prev_data_back.ambient.r); glGetMaterialfv(GL_BACK,GL_EMISSION,&prev_data_back.emissive.r); glGetMaterialfv(GL_BACK, GL_SHININESS, &prev_data_back.shininess); // Material colors and properties glMaterialfv(GL_FRONT, GL_DIFFUSE, &data.diffuse.r); glMaterialfv(GL_FRONT, GL_SPECULAR, &data.specular.r); glMaterialfv(GL_FRONT, GL_AMBIENT, &data.ambient.r); glMaterialfv(GL_FRONT, GL_EMISSION, &data.emissive.r); glMaterialfv(GL_FRONT, GL_SHININESS, &data.shininess); glMaterialfv(GL_BACK, GL_DIFFUSE, &data.diffuse.r); glMaterialfv(GL_BACK, GL_SPECULAR, &data.specular.r); glMaterialfv(GL_BACK, GL_AMBIENT, &data.ambient.r); glMaterialfv(GL_BACK, GL_EMISSION, &data.emissive.r); glMaterialfv(GL_BACK, GL_SHININESS, &data.shininess); #elif !defined(TARGET_PROGRAMMABLE_GL) // opengl es 1.1 implementation must use GL_FRONT_AND_BACK. glGetMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &prev_data.diffuse.r); glGetMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &prev_data.specular.r); glGetMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &prev_data.ambient.r); glGetMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &prev_data.emissive.r); glGetMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &prev_data.shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &data.diffuse.r); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &data.specular.r); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &data.ambient.r); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &data.emissive.r); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &data.shininess); #endif } #endif if(ofIsGLProgrammableRenderer()){ ofGetGLProgrammableRenderer()->setCurrentMaterial(this); } }
//-------------------------------------------------------------- void testApp::drawScene() { ofPushMatrix(); ofRotate(90, 0, 0, -1); ofSetColor(30); ofDrawGridPlane(12.0f, 8.0f, false ); ofPopMatrix(); if(ofIsGLProgrammableRenderer()) bshader.begin(); ofLogo.getTextureReference().bind(); for(int i = 0; i < demos.size(); i++){ ofPushMatrix(); ofTranslate(demos[i].floatPos); ofFloatColor col; if (demos[i].bMouseOver) col = ofColor::white; else col = demos[i].color; if(ofIsGLProgrammableRenderer()) { bshader.setUniform3f("color", col.r, col.g, col.b); } else { ofSetColor(col); } demos[i].box.draw(); ofPopMatrix(); } ofLogo.getTextureReference().unbind(); if(ofIsGLProgrammableRenderer()) bshader.end(); //billboard and draw the mouse if(oculusRift.isSetup()){ ofPushMatrix(); oculusRift.multBillboardMatrix(); ofSetColor(255, 0, 0); ofCircle(0,0,.5); ofPopMatrix(); } }
bool videoEffect::initialise(){ bool success = basicEffect::initialise(); if(success){ effectMutex.lock(); isLoading = true; // load movie hasError = stream.load("vendome_daan_v1.0/Montage_Export_v1_SD.mov"); stream.play(); //cachedImage.allocate(1,1, GL_RGB); // setup shader if(ofIsGLProgrammableRenderer()) hasError *= imageShader.load("effects/imageEffect/imageShaderGL3"); else hasError *= imageShader.load("effects/imageEffect/imageShader"); if(hasError) isInitialised=false; isLoading = false; effectMutex.unlock(); } return isInitialised; }
void ofVbo::clearAttribute(int attributePos_){ if (!hasAttribute(attributePos_)) return; if (ofIsGLProgrammableRenderer()) { if(attributePos_>3){ customAttributes.erase(attributePos_); }else{ switch (attributePos_){ case ofShader::POSITION_ATTRIBUTE: clearVertices(); break; case ofShader::COLOR_ATTRIBUTE: clearColors(); break; case ofShader::NORMAL_ATTRIBUTE: clearNormals(); break; case ofShader::TEXCOORD_ATTRIBUTE: clearTexCoords(); break; default: break; } } }else{ customAttributes.erase(attributePos_); } }
ofVbo & ofVbo::operator=(const ofVbo& mom){ if(&mom==this) return *this; clear(); bUsingVerts = mom.bUsingVerts; bUsingTexCoords = mom.bUsingTexCoords; bUsingColors = mom.bUsingColors; bUsingNormals = mom.bUsingNormals; bUsingIndices = mom.bUsingIndices; positionAttribute = mom.positionAttribute; colorAttribute = mom.colorAttribute; texCoordAttribute = mom.texCoordAttribute; normalAttribute = mom.normalAttribute; customAttributes = mom.customAttributes; totalVerts = mom.totalVerts; totalIndices = mom.totalIndices; indexAttribute = mom.indexAttribute; vaoChanged = mom.vaoChanged; vaoID = mom.vaoID; if(ofIsGLProgrammableRenderer()){ retainVAO(vaoID); } return *this; }
//-------------------------------------------------------------- ofVbo::VertexAttribute & ofVbo::getOrCreateAttr(int location){ VertexAttribute * attr = nullptr; if (ofIsGLProgrammableRenderer()) { switch (location){ case ofShader::POSITION_ATTRIBUTE: attr = &positionAttribute; break; case ofShader::COLOR_ATTRIBUTE: attr = &colorAttribute; break; case ofShader::NORMAL_ATTRIBUTE: attr = &normalAttribute; break; case ofShader::TEXCOORD_ATTRIBUTE: attr = &texCoordAttribute; break; default: customAttributes[location].location = location; attr = &customAttributes[location]; vaoChanged = true; break; } }else{ customAttributes[location].location = location; attr = &customAttributes[location]; vaoChanged = true; } return *attr; }
void ofVbo::updateAttributeData(int location, const float * attr0x, int total){ VertexAttribute * attr = nullptr; if (ofIsGLProgrammableRenderer()) { switch (location){ case ofShader::POSITION_ATTRIBUTE: attr = &positionAttribute; break; case ofShader::COLOR_ATTRIBUTE: attr = &colorAttribute; break; case ofShader::NORMAL_ATTRIBUTE: attr = &normalAttribute; break; case ofShader::TEXCOORD_ATTRIBUTE: attr = &texCoordAttribute; break; default: if(customAttributes.find(location)!=customAttributes.end()) { attr = &customAttributes[location]; } break; } } else { if(customAttributes.find(location)!=customAttributes.end()) { attr = &customAttributes[location]; } } if (attr !=nullptr && attr->isAllocated()) { attr->updateData(0, total*attr->stride, attr0x); } }
//-------------------------------------------------------------------- void ofVideoPlayer::update(){ if( player ){ player->update(); if( bUseTexture && player->isFrameNew() ) { playerTex = player->getTexturePtr(); if(playerTex == NULL){ if(int(tex.size())!=player->getPixels().getNumPlanes()){ tex.resize(max(player->getPixels().getNumPlanes(),1)); } if(player->getWidth() != 0 && player->getHeight() != 0) { for(int i=0;i<player->getPixels().getNumPlanes();i++){ ofPixels plane = player->getPixels().getPlane(i); bool bDiffPixFormat = ( tex[i].isAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) ); if(bDiffPixFormat || !tex[i].isAllocated() || tex[i].getWidth() != plane.getWidth() || tex[i].getHeight() != plane.getHeight()){ tex[i].allocate(plane); if(ofIsGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){ tex[i].setRGToRGBASwizzles(true); } } tex[i].loadData(plane); } } } } } }
//-------------------------------------------------------------- void ofApp::setup(){ #ifdef TARGET_OPENGLES shader.load("shadersES2/shader"); #else if(ofIsGLProgrammableRenderer()){ shader.load("shadersGL3/shader"); }else{ shader.load("shadersGL2/shader"); } #endif int camWidth = 320; int camHeight = 240; camera.setVerbose(false); camera.initGrabber(camWidth, camHeight); movie.loadMovie("movie.mov"); movie.play(); image.loadImage("img.jpg"); imageMask.loadImage("mask.jpg"); fbo.allocate(camWidth, camHeight); maskFbo.allocate(camWidth, camHeight); }
//--------------------------------------------------------------------------- bool ofVideoPlayer::load(string name){ if( !player ){ setPlayer( shared_ptr<OF_VID_PLAYER_TYPE>(new OF_VID_PLAYER_TYPE) ); player->setPixelFormat(internalPixelFormat); } bool bOk = player->load(name); if( bOk){ moviePath = name; if(bUseTexture){ if(player->getTexturePtr()==NULL){ if(tex.empty()) { tex.resize(max(player->getPixels().getNumPlanes(),1)); for(int i=0;i<player->getPixels().getNumPlanes();i++){ ofPixels plane = player->getPixels().getPlane(i); tex[i].allocate(plane); if(ofIsGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){ tex[i].setRGToRGBASwizzles(true); } } } }else{ playerTex = player->getTexturePtr(); } } } return bOk; }
void ofxFXObject::selectShaderSource(){ if (fragmentShader.empty()){ #ifdef TARGET_OPENGLES fragmentShader = glESFragmentShader; #else if (ofIsGLProgrammableRenderer()){ fragmentShader = gl3FragmentShader; } else { fragmentShader = gl2FragmentShader; } } #endif if (vertexShader.empty()){ #ifdef TARGET_OPENGLES vertexShader = glESVertexShader; #else if (ofIsGLProgrammableRenderer()){ vertexShader = gl3VertexShader; // If the vertex shader for GL3 isn't specified, we fill // in a simple pass-through shader. This way, users can // give only fragment shaders, just like for GL2/ES. This // is necessary because having a vertex shader is mandatory // in GL3. if (vertexShader.empty()){ vertexShader = "#version 150\n"; vertexShader += STRINGIFY( uniform mat4 modelViewProjectionMatrix; in vec4 position; void main(){ gl_Position = modelViewProjectionMatrix * position; });
MaskTool::MaskTool(): _bEnabled(true), _bBrushDown(false), _maxNumUndos(20), _curUndoFrame(1), _width(0), _height(0) { ofRegisterMouseEvents(this); // NOTE: GL3 shaders ONLY supported as of 12/1/14 #ifdef TARGET_OPENGLES _maskShader.load("shadersES2/mask"); _frameCombineShader.load("shadersES2/frame_combine"); #else if(ofIsGLProgrammableRenderer()){ _maskShader.load("shadersGL3/mask"); _frameCombineShader.load("shadersGL3/frame_combine"); }else{ _maskShader.load("shadersGL2/mask"); _frameCombineShader.load("shadersGL2/frame_combine"); } #endif _brushImg.loadImage("brush.png"); }
//-------------------------------------------------------------- void ofApp::setup(){ #ifdef TARGET_OPENGLES shaderBlurX.load("shadersES2/shaderBlurX"); shaderBlurY.load("shadersES2/shaderBlurY"); #else if(ofIsGLProgrammableRenderer()){ std::cout << "load GL3\n" << "\n"; shaderBlurX.load("shadersGL3/shaderBlurX"); shaderBlurY.load("shadersGL3/shaderBlurY"); }else{ std::cout << "load GL2\n" << "\n"; shaderBlurX.load("shadersGL2/shaderBlurX"); shaderBlurY.load("shadersGL2/shaderBlurY"); } #endif ofLoadImage(image, "img.jpg"); fboBlurOnePass.allocate(image.getWidth(), image.getHeight()); fboBlurTwoPass.allocate(image.getWidth(), image.getHeight()); // fboBlurOnePass.allocate(ofGetWidth(), ofGetHeight()); // fboBlurTwoPass.allocate(ofGetWidth(), ofGetHeight()); }
//-------------------------------------- void ofSetupOpenGL(ofPtr<ofAppBaseWindow> windowPtr, int w, int h, int screenMode){ if(!ofGetCurrentRenderer()) { #ifdef USE_PROGRAMMABLE_GL ofPtr<ofBaseRenderer> renderer(new ofGLProgrammableRenderer(false)); #else ofPtr<ofBaseRenderer> renderer(new ofGLRenderer(false)); #endif ofSetCurrentRenderer(renderer,false); } window = windowPtr; if(ofIsGLProgrammableRenderer()){ #if defined(TARGET_RASPBERRY_PI) static_cast<ofAppEGLWindow*>(window.get())->setGLESVersion(2); #elif defined(TARGET_LINUX_ARM) static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(2,0); #elif !defined(TARGET_OPENGLES) static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(3,2); #endif }else{ #if defined(TARGET_LINUX_ARM) && !defined(TARGET_RASPBERRY_PI) static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(1,0); #endif } window->setupOpenGL(w, h, screenMode); }
ofxWMFVideoPlayer::ofxWMFVideoPlayer() : _player(NULL) { if (_instanceCount == 0) { if (!ofIsGLProgrammableRenderer()) { if (wglewIsSupported("WGL_NV_DX_interop")) { ofLogVerbose("ofxWMFVideoPlayer") << "WGL_NV_DX_interop supported"; } else { ofLogError("ofxWMFVideoPlayer") << "WGL_NV_DX_interop not supported. Upgrade your graphc drivers and try again."; return; } } HRESULT hr = MFStartup(MF_VERSION); if (!SUCCEEDED(hr)) { ofLog(OF_LOG_ERROR, "ofxWMFVideoPlayer: Error while loading MF"); } } _id = _instanceCount; _instanceCount++; this->InitInstance(); _waitingForLoad = false; _waitForLoadedToPlay = false; _sharedTextureCreated = false; _wantToSetVolume = false; _currentVolume = 1.0; _frameRate = 0.0f; }
void DisplaceMapShader::begin() { MappingShader::begin(); m_shader.setUniform1f("maxHeight", m_maxHeight); if (ofIsGLProgrammableRenderer()) { m_shader.setUniformMatrix4f("normalMatrix", m_normalMatrix); } }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetVerticalSync(true); ofSetFrameRate(60); ofEnableSmoothing(); ofSetCircleResolution(60); ofSetFullscreen(true); /* --shaders*/ #ifdef TARGET_OPENGLES shader.load("shadersES2/shader"); #else if(ofIsGLProgrammableRenderer()){ shader.load("shadersGL3/shader"); }else{ shader.load("shadersGL2/shader"); } #endif /*-----------------Vars setup --------------------------*/ currentMode = SNOW; force.set(0, 0.2, 0); noiseMagnitude = 0.8; timeFrequency = 0.5; /*---------------- initialize origin---------------- */ system.setup(ofVec3f(0, 0, 300), 10000); /* --------------- Intializa GUI --------------------*/ createGui(); }
//-------------------------------------------------------------- void EngineGLFW::invalidateDeviceObjects() { if (ofIsGLProgrammableRenderer()) { if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle); if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle); g_VaoHandle = g_VboHandle = g_ElementsHandle = 0; glDetachShader(g_ShaderHandle, g_VertHandle); glDeleteShader(g_VertHandle); g_VertHandle = 0; glDetachShader(g_ShaderHandle, g_FragHandle); glDeleteShader(g_FragHandle); g_FragHandle = 0; glDeleteProgram(g_ShaderHandle); g_ShaderHandle = 0; } if (g_FontTexture) { glDeleteTextures(1, &g_FontTexture); ImGui::GetIO().Fonts->TexID = 0; g_FontTexture = 0; } }
//-------------------------------------------------------------- void testApp::setup() { ofSetLogLevel(OF_LOG_VERBOSE); ofEnableDepthTest(); ofSetVerticalSync(false); showOverlay = false; oculusRift.baseCamera = &cam; oculusRift.setup(); for (int i = 0; i < 80; i++) { DemoBox d; demos.push_back(d); } setupBoxes(); if (ofIsGLProgrammableRenderer()) bshader.load("Shaders_GL3/simple.vert", "Shaders_GL3/simple.frag"); // ofBox uses texture coordinates from 0-1, so you can load whatever // sized images you want and still use them to texture your box // but we have to explicitly normalize our tex coords here ofEnableNormalizedTexCoords(); // loads the OF logo from disk ofLogo.loadImage("of.png"); //enable mouse; cam.setAutoDistance(false); cam.begin(); cam.end(); // set camera y to user eye height cam.setGlobalPosition(0, oculusRift.getUserEyeHeight(), 3); }
//-------------------------------------------------------------- void ofApp::setup(){ #ifdef TARGET_OPENGLES shader.load("shadersES2/shader"); #else if(ofIsGLProgrammableRenderer()){ shader.load("shadersGL3/shader"); }else{ shader.load("shadersGL2/shader"); } #endif backgroundImage.loadImage("A.jpg"); foregroundImage.loadImage("B.jpg"); brushImage.loadImage("brush.png"); int width = backgroundImage.getWidth(); int height = backgroundImage.getHeight(); maskFbo.allocate(width, height); fbo.allocate(width, height); // Clear the FBO's // otherwise it will bring some junk with it from the memory maskFbo.begin(); ofClear(0,0,0,255); maskFbo.end(); fbo.begin(); ofClear(0,0,0,255); fbo.end(); bBrushDown = false; }