Example #1
0
ofFbo& ofx2DPro::getRenderTarget(int _viewNumber){
    if (_viewNumber>=renderTargets.size()) {
        setupNumViewports(_viewNumber+1);
    }
    
    ofFbo *renderTarget = &renderTargets[_viewNumber];
    int width = ofGetWidth();// / renderTargets.size();
    int height = ofGetHeight();
    if(!renderTarget->isAllocated() || renderTarget->getWidth() != width || renderTarget->getHeight() != height){
        ofFbo::Settings settings;
        settings.width = width;
        settings.height = height;
        settings.internalformat = GL_RGB;
        settings.numSamples = 0;
        settings.useDepth = true;
        settings.useStencil = true;
        settings.depthStencilAsTexture = true;
#ifdef TARGET_OPENGLES
        settings.textureTarget = GL_TEXTURE_2D;
#else
        settings.textureTarget = ofGetUsingArbTex() ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D;
        renderTarget->allocate(settings);
#endif
		renderTarget->begin();
        ofClear(0, 0,0,0);
        renderTarget->end();
    } 
    
    return *(renderTarget);
}
Example #2
0
//----------------------------------------------------------
void ofTexture::loadData(const ofFloatPixels & pix, int glFormat){
	if(!isAllocated()){
		allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), ofGetUsingArbTex(), glFormat, ofGetGlType(pix));
	}
	ofSetPixelStoreiAlignment(GL_UNPACK_ALIGNMENT,pix.getWidth(),pix.getBytesPerChannel(),ofGetNumChannelsFromGLFormat(glFormat));
	loadData(pix.getData(), pix.getWidth(), pix.getHeight(), glFormat, ofGetGlType(pix));
}
Example #3
0
//----------------------------------------------------------
void ofTexture::allocate(const ofFloatPixels& pix){
	allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), ofGetUsingArbTex(), ofGetGlFormat(pix), ofGetGlType(pix));
	if((pix.getPixelFormat()==OF_PIXELS_GRAY || pix.getPixelFormat()==OF_PIXELS_GRAY_ALPHA) && ofIsGLProgrammableRenderer()){
		setRGToRGBASwizzles(true);
	}
	loadData(pix);
}
Example #4
0
//-------------------------------------------------------------------------------------
ofFbo::Settings::Settings(std::shared_ptr<ofBaseGLRenderer> renderer) {
	width					= 0;
	height					= 0;
	numColorbuffers			= 1;
	useDepth				= false;
	useStencil				= false;
	depthStencilAsTexture	= false;
#ifndef TARGET_OPENGLES
	textureTarget			= ofGetUsingArbTex() ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D;
#else
	textureTarget			= GL_TEXTURE_2D;
#endif
	internalformat			= GL_RGBA;
	depthStencilInternalFormat		= GL_DEPTH_COMPONENT24;
	wrapModeHorizontal		= GL_CLAMP_TO_EDGE;
	wrapModeVertical		= GL_CLAMP_TO_EDGE;
	minFilter				= GL_LINEAR;
	maxFilter				= GL_LINEAR;
	numSamples				= 0;
	if(renderer){
		this->renderer = renderer;
	}else{
		this->renderer = ofGetGLRenderer();
	}
}
Example #5
0
//----------------------------------------------------------
void ofSetTextureWrap(GLfloat wrapS, GLfloat wrapT){
	bUseCustomTextureWrap = true;
	GLenum textureTarget = GL_TEXTURE_2D;
#ifndef TARGET_OPENGLES
	if (ofGetUsingArbTex() && GL_ARB_texture_rectangle){
		textureTarget = GL_TEXTURE_RECTANGLE_ARB;
	};
#endif
	glTexParameterf(textureTarget, GL_TEXTURE_WRAP_S, wrapS);
	glTexParameterf(textureTarget, GL_TEXTURE_WRAP_T, wrapT);
}
Example #6
0
//----------------------------------------------------------
void ofSetMinMagFilters(GLfloat minFilter, GLfloat magFilter){
	bUseCustomMinMagFilters = true;
	GLenum textureTarget = GL_TEXTURE_2D;
#ifndef TARGET_OPENGLES
	if (ofGetUsingArbTex() && GL_ARB_texture_rectangle){
		textureTarget = GL_TEXTURE_RECTANGLE_ARB;
	};
#endif
	glTexParameterf(textureTarget, GL_TEXTURE_MIN_FILTER, minFilter);
	glTexParameterf(textureTarget, GL_TEXTURE_MAG_FILTER, magFilter);
}
Example #7
0
GLuint ofxImGui::loadTexture(ofTexture& texture, string imagePath)
{
    bool isUsingArb = ofGetUsingArbTex();
    if (isUsingArb)
    {
        ofDisableArbTex();

    }
    ofLoadImage(texture, imagePath);
    if (isUsingArb)
    {
        ofEnableArbTex();
    }
    return texture.getTextureData().textureID;
}
Example #8
0
void ofFbo::allocate(int width, int height, int internalformat, int numSamples) {

	settings.width			= width;
	settings.height			= height;
	settings.internalformat	= internalformat;
	settings.numSamples		= numSamples;
    
#ifdef TARGET_OPENGLES
	settings.useDepth		= false;
	settings.useStencil		= false;
	//we do this as the fbo and the settings object it contains could be created before the user had the chance to disable or enable arb rect.
    settings.textureTarget	= GL_TEXTURE_2D;
#else    
	settings.useDepth		= true;
	settings.useStencil		= true;
	//we do this as the fbo and the settings object it contains could be created before the user had the chance to disable or enable arb rect. 	
    settings.textureTarget	= ofGetUsingArbTex() ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D;    
#endif 
    
	allocate(settings);
}
Example #9
0
void faceColorToTexture(ofMesh& mesh, ofImage& image)
{
	vector<ofFloatColor> &color = mesh.getColors();
	int num_face = color.size() / 3;
	
	int tex_size = ofNextPow2(ceil(sqrt(num_face)));
	
	bool arb = ofGetUsingArbTex();
	ofDisableArbTex();
	image.allocate(tex_size, tex_size, OF_IMAGE_COLOR);
	if (arb) ofEnableArbTex();
	
	mesh.clearTexCoords();
	
	image.getPixelsRef().set(0);
	
	float texel_size = (1. / image.getWidth()) * 0.5;
	
	for (int i = 0; i < num_face; i++)
	{
		int u = (i % tex_size);
		int v = (i / tex_size);
		
		ofColor c = color[i * 3];
		
		image.setColor(u, v, c);
		
		float uu = (float)u / image.getWidth() + texel_size;
		float vv = (float)v / image.getHeight() + texel_size;
		
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
		mesh.addTexCoord(ofVec2f(uu, vv));
	}
	
	image.update();
	mesh.clearColors();
}
Example #10
0
void ofxSSAO::setup( int w, int h, int format){
    width = w;
    height = h;
    
    //deferred
    ofFbo::Settings deferredBuffersSettings;
    deferredBuffersSettings.width = w;
    deferredBuffersSettings.height = h;
    deferredBuffersSettings.internalformat = format;
    deferredBuffersSettings.numColorbuffers = 2;
    deferredBuffersSettings.useDepth = true;
    deferredBuffersSettings.useStencil = true;
    deferredBuffersSettings.depthStencilAsTexture = true;
    deferredBuffersSettings.textureTarget = ofGetUsingArbTex() ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D;
    
    deferredPass.allocate(deferredBuffersSettings);
    //deferredPass.allocate(w, h, format, 0);//msaa gives us weird edges...
    makeDeferredShader();
    
    // depth blur
    fbo1.allocate(w, h, GL_RGB, 0);
    makeDaoShader();
}
Example #11
0
//----------------------------------------------------------
void ofTexture::allocate(int w, int h, int glInternalFormat, int glFormat, int pixelType){
	allocate(w, h, glInternalFormat, ofGetUsingArbTex(), glFormat, pixelType);
}
void CollageTexture::allocate(int w, int h, int internalGlDataType, int internalGLScaleMode){
	allocate(w, h, internalGlDataType, internalGLScaleMode, ofGetUsingArbTex());
}
Example #13
0
//----------------------------------------------------------
void ofTexture::allocate(const ofPixels& pix){
	allocate(pix.getWidth(), pix.getHeight(), ofGetGlFormat(pix), ofGetUsingArbTex());
}
// --------------------------------------------------
void ofxProjectorBlend::setup(int resolutionWidth,
							  int resolutionHeight,
							  int _numProjectors,
							  int _pixelOverlap,
							  ofxProjectorBlendLayout _layout,
							  ofxProjectorBlendRotation _rotation)
{

	string l = "horizontal";
	if(layout==ofxProjectorBlend_Vertical) l = "vertical";

	string r = "normal";
	if(rotation==ofxProjectorBlend_RotatedLeft) r = "rotated left";
	else if(rotation==ofxProjectorBlend_RotatedRight) r = "rotated right";

	ofLog(OF_LOG_NOTICE, "ofxProjectorBlend: res: %d x %d * %d, overlap: %d pixels, layout: %s, rotation: %s\n", resolutionWidth, resolutionHeight, _numProjectors, _pixelOverlap, l.c_str(), r.c_str());
	numProjectors = _numProjectors;
	layout = _layout;
	rotation = _rotation;

	if(numProjectors <= 0){
		ofLog(OF_LOG_ERROR, "Cannot initialize with " + ofToString(this->numProjectors) + " projectors.");
		return;
	}

	//allow editing projector heights
	for(int i = 0; i < numProjectors; i++){
		projectorHeightOffset.push_back( 0 );
	}

	pixelOverlap = _pixelOverlap;

	if(rotation == ofxProjectorBlend_NoRotation) {
		singleChannelWidth = resolutionWidth;
		singleChannelHeight = resolutionHeight;
	}
	else {
		singleChannelWidth = resolutionHeight;
		singleChannelHeight = resolutionWidth;
	}

	if(layout == ofxProjectorBlend_Vertical) {
		fullTextureWidth = singleChannelWidth;
		fullTextureHeight = singleChannelHeight*numProjectors - pixelOverlap*(numProjectors-1);
	}
	else if(layout == ofxProjectorBlend_Horizontal) {
		fullTextureWidth = singleChannelWidth*numProjectors - pixelOverlap*(numProjectors-1);
		fullTextureHeight = singleChannelHeight;
	} else {
		ofLog(OF_LOG_ERROR, "ofxProjectorBlend: You have used an invalid ofxProjectorBlendLayout in ofxProjectorBlend::setup()");
		return;
	}

	quadMesh.clear();
	quadMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);

	quadMesh.addVertex(ofVec2f(0, 0));
	quadMesh.addVertex(ofVec2f(singleChannelWidth, 0));
	quadMesh.addVertex(ofVec2f(0, singleChannelHeight));
	quadMesh.addVertex(ofVec2f(singleChannelWidth, singleChannelHeight));

	if (ofGetUsingArbTex()) {
		quadMesh.addTexCoord(ofVec2f(0, 0));
		quadMesh.addTexCoord(ofVec2f(singleChannelWidth, 0));
		quadMesh.addTexCoord(ofVec2f(0, singleChannelHeight));
		quadMesh.addTexCoord(ofVec2f(singleChannelWidth, singleChannelHeight));
	}
	else {
		float u = singleChannelWidth / fullTextureWidth;
		float v = singleChannelHeight / fullTextureHeight;
		quadMesh.addTexCoord(ofVec2f(0, 0));
		quadMesh.addTexCoord(ofVec2f(u, 0));
		quadMesh.addTexCoord(ofVec2f(0, v));
		quadMesh.addTexCoord(ofVec2f(u, v));
	}

	displayWidth = resolutionWidth * numProjectors;
	displayHeight = resolutionHeight;

	fullTexture.allocate(fullTextureWidth, fullTextureHeight, GL_RGB, 4);

	blendShader.unload();
	blendShader.setupShaderFromSource(GL_VERTEX_SHADER, ofxProjectorBlendShader::GetVertexShader());
	blendShader.setupShaderFromSource(GL_FRAGMENT_SHADER, ofxProjectorBlendShader::GetFragmentShader());
	if (ofIsGLProgrammableRenderer()) {
		blendShader.bindDefaults();
	}
	blendShader.linkProgram();

	gamma.resize(numProjectors - 1, 0.5);
	blendPower.resize(numProjectors - 1, 1);
	luminance.resize(numProjectors - 1, 0);
}
Example #15
0
//----------------------------------------------------------
void ofTexture::allocate(int w, int h, int internalGlDataType){
	allocate(w, h, internalGlDataType, ofGetUsingArbTex(), ofGetGLFormatFromInternal(internalGlDataType), ofGetGlTypeFromInternal(internalGlDataType));
}
Example #16
0
//----------------------------------------------------------
void ofTexture::allocate(const ofFloatPixels& pix){
	allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), ofGetUsingArbTex(), ofGetGlFormat(pix), ofGetGlType(pix));
}
void PixelTexture::allocate(int w, int h, int internalGlDataType){
	allocate(w, h, internalGlDataType, ofGetUsingArbTex());
}
Example #18
0
//----------------------------------------------------------
void ofTexture::allocate(int w, int h, int glInternalFormat){
	allocate(w, h, glInternalFormat, ofGetUsingArbTex(), ofGetGLFormatFromInternal(glInternalFormat), ofGetGlTypeFromInternal(glInternalFormat));
}
Example #19
0
//--------------------------------------------------------------
void testApp::setup(){
    
    ofBackground(0);
    ofSetFrameRate(30);
    ofEnableAlphaBlending();
    //    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //    glEnable(GL_DEPTH_TEST);
    glPointSize(1.0);
    drawFBO = false;
    autoRotate = true;
    drawEQ = false;
    
    //not really needed
    //    glEnable(GL_ALPHA_TEST);
    //    glAlphaFunc(GL_GREATER, 0.10f);
    
    //generate the mesh points
    buildSphereMesh(rad, res, vm);
    cout << "nverts: " << vm.getNumVertices() << endl;
    cout << "arb: " << ofGetUsingArbTex() << ", norm: " << ofGetUsingNormalizedTexCoords() << endl;
    
    //load the texture shader
    shader.load("tex.vert", "tex.frag");
    
    //fft init
    fftSmoothed = new float[8192];
    memset(fftSmoothed, 0x00, sizeof(float) * 8192);
    
    //map the frequencies to bark bands
    float freq_spc = FREQ_MAX / (float)SPECTRAL_BANDS;
    
	for (int i = 0; i < SPECTRAL_BANDS; i++) {
        int bidx = bark(i * freq_spc);
        barkmap[i] = bidx;
    }
    
    //load the position updating frag shader
    pos_shader.load("", "position.frag");
    
    //for the sphere we set this to the resolution which = #of verts along each axis
    fbo_res = res;
    
    //init the fbo's with blank data
    vector<ofVec3f> fbo_init_data;
    fbo_init_data.assign(fbo_res * fbo_res, ofVec3f(0.0, 0.0, 0.0));
    
    posbuf.allocate(fbo_res, fbo_res, GL_RGB32F);
    posbuf.src->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB);
    posbuf.dst->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB);
    
    //reuse fbo_init_data for no real reason, it just needs to be blank
    eq_tex.allocate(fbo_res, 1, GL_RGB32F_ARB);
    eq_tex.loadData((float *)&fbo_init_data[0], fbo_res, 1, GL_RGB);
    
    axis_loc = fbo_res;
    angincr = 180.0/(float)fbo_res;

    player.loadSound("jhfd.mp3");
    
    player.play(); //go
}