Пример #1
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));
}
Пример #2
0
//----------------------------------------------------------
void ofTexture::loadData(const ofFloatPixels & pix){
	if(!isAllocated()){
		allocate(pix);
	}else{
		ofSetPixelStoreiAlignment(GL_UNPACK_ALIGNMENT,pix.getBytesStride());
		loadData(pix.getData(), pix.getWidth(), pix.getHeight(), ofGetGlFormat(pix), ofGetGlType(pix));
	}
}
Пример #3
0
void ofTexture::readToPixels(ofFloatPixels & pixels) const {
#ifndef TARGET_OPENGLES
	pixels.allocate(texData.width,texData.height,ofGetImageTypeFromGLType(texData.glInternalFormat));
	ofSetPixelStoreiAlignment(GL_PACK_ALIGNMENT,pixels.getWidth(),pixels.getBytesPerChannel(),pixels.getNumChannels());
	glBindTexture(texData.textureTarget,texData.textureID);
	glGetTexImage(texData.textureTarget,0,ofGetGlFormat(pixels),GL_FLOAT,pixels.getData());
	glBindTexture(texData.textureTarget,0);
#endif
}
Пример #4
0
//----------------------------------------------------------
void ofFbo::readToPixels(ofFloatPixels & pixels, int attachmentPoint) const{
	if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
	getTexture(attachmentPoint).readToPixels(pixels);
#else
	pixels.allocate(settings.width,settings.height,ofGetImageTypeFromGLType(settings.internalformat));
	bind();
	int format = ofGetGLFormatFromInternal(settings.internalformat);
	glReadPixels(0,0,settings.width, settings.height, format, GL_FLOAT, pixels.getData());
	unbind();
#endif
}
Пример #5
0
    void update() {
#ifdef USE_AUDIO
        //Speaker sampling code
        speakerFbo.begin();
        renderScene(shader, speakerXyzMap, speakerConfidenceMap);
        speakerFbo.end();
        
        //Read back the fbo, and average it on the CPU
        speakerFbo.readToPixels(speakerPixels);
        speakerPixels.setImageType(OF_IMAGE_GRAYSCALE);
        
        ofxOscMessage brightnessMsg;
        brightnessMsg.setAddress("/audio/brightness");
        float* pix = speakerPixels.getData();
        for(int i = 0; i < n_speakers; i++){
            float avg = 0;
            for(int j = 0; j < n_samples; j++){
                avg += *pix++;
            }
            avg /= n_samples;
            brightnessMsg.addFloatArg(avg);
        }
        oscSender.sendMessage(brightnessMsg);
        
        float elapsedTime = ofGetElapsedTimef();
        // copied from shader --- 8< ---
        float t = elapsedTime / 30.; // duration of each stage
        float stage = floor(t); // index of current stage
        float i = t - stage; // progress in current stage
        // copied from shader --- 8< ---
        
        if(stage != previousStage) {
            ofxOscMessage msg;
            msg.setAddress("/audio/scene_change_event");
            msg.addIntArg(stage == 0 ? 0 : 2);
            oscSender.sendMessage(msg);
        }
        previousStage = stage;
        
        if(stage == 0) {
            float lighthouseAngle = ofGetElapsedTimef() / TWO_PI;
            lighthouseAngle += 0; // set offset here
            ofxOscMessage msg;
            msg.setAddress("/audio/lighthouse_angle");
            msg.addFloatArg(fmodf(lighthouseAngle, 1));
            oscSender.sendMessage(msg);
        }
        
#endif
    }
Пример #6
0
		// get float pixels from a fbo or texture
	void ftUtil::toPixels(ofTexture& _tex, ofFloatPixels& _pixels) {
		ofTextureData& texData = _tex.getTextureData();
		int format = texData.glInternalFormat;
		int readFormat, numChannels;
		
		switch(format){
			case GL_R32F: 		readFormat = GL_RED, 	numChannels = 1; break; // or is it GL_R
			case GL_RG32F: 		readFormat = GL_RG, 	numChannels = 2; break;
			case GL_RGB32F: 	readFormat = GL_RGB, 	numChannels = 3; break;
			case GL_RGBA32F:	readFormat = GL_RGBA,	numChannels = 4; break;
			default:
				ofLogWarning("ftUtil") << "toPixels: " << "can only read float textures to ofFloatPixels";
				return;
		}
		if (_pixels.getWidth() != texData.width || _pixels.getHeight() != texData.height || _pixels.getNumChannels() != numChannels) {
			_pixels.allocate(texData.width, texData.height, numChannels);
		}
		ofSetPixelStoreiAlignment(GL_PACK_ALIGNMENT, texData.width, 4, numChannels);
		glBindTexture(texData.textureTarget, texData.textureID);
		glGetTexImage(texData.textureTarget, 0, readFormat, GL_FLOAT, _pixels.getData());
		glBindTexture(texData.textureTarget, 0);
	}
Пример #7
0
void ofxTexture3d::loadData(ofFloatPixels & pix, int d, int xOffset, int yOffset, int zOffset)
{
    loadData(pix.getData(), pix.getWidth(), pix.getHeight(), d, xOffset, yOffset, zOffset, ofGetGlFormat(pix));
}
Пример #8
0
//----------------------------------------------------------
void ofTexture::loadData(const ofFloatPixels & pix, int glFormat){
	ofSetPixelStoreiAlignment(GL_UNPACK_ALIGNMENT,pix.getWidth(),pix.getBytesPerChannel(),ofGetNumChannelsFromGLFormat(glFormat));
	loadData(pix.getData(), pix.getWidth(), pix.getHeight(), glFormat, ofGetGlType(pix));
}