コード例 #1
0
ファイル: ofTexture.cpp プロジェクト: jvcleave/compare
//----------------------------------------------------------
void ofTexture::allocate(const ofFloatPixels& pix, bool bUseARBExtention){
	allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), bUseARBExtention, ofGetGlFormat(pix), ofGetGlType(pix));
	if((pix.getPixelFormat()==OF_PIXELS_GRAY || pix.getPixelFormat()==OF_PIXELS_GRAY_ALPHA) && ofIsGLProgrammableRenderer()){
		setRGToRGBASwizzles(true);
	}
	loadData(pix);
}
コード例 #2
0
ファイル: ofGLUtils.cpp プロジェクト: 4ker/openFrameworks
//---------------------------------
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
}
コード例 #3
0
//----------------------------------------------------------
void ofTexture::readToPixels(ofFloatPixels & pixels){
#ifndef TARGET_OPENGLES
	pixels.allocate(texData.width,texData.height,ofGetImageTypeFromGLType(texData.glTypeInternal));
	bind();
	glGetTexImage(texData.textureTarget,0,ofGetGlFormat(pixels),GL_FLOAT,pixels.getPixels());
	unbind();
#endif
}
コード例 #4
0
ファイル: ofTexture.cpp プロジェクト: jvcleave/compare
//----------------------------------------------------------
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));
	}
}
コード例 #5
0
ファイル: ofTexture.cpp プロジェクト: jvcleave/compare
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
}
コード例 #6
0
FREE_IMAGE_TYPE getFreeImageType(ofFloatPixels& pix) {
	switch(pix.getNumChannels()) {
		case 1: return FIT_FLOAT;
		case 3: return FIT_RGBF;
		case 4: return FIT_RGBAF;
		default:
			ofLogError() << "Unkown freeimage type for" << pix.getNumChannels() << "channels";
			return FIT_UNKNOWN;
	}
}
コード例 #7
0
ファイル: ofFbo.cpp プロジェクト: jvcleave/compare
//----------------------------------------------------------
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
}
コード例 #8
0
ファイル: main.cpp プロジェクト: kylemcdonald/LightLeaks
    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
    }
コード例 #9
0
ファイル: ofTexture.cpp プロジェクト: 3snail/openFrameworks
//---------------------------------
int ofGetGlInternalFormat(const ofFloatPixels& pix) {
#ifndef TARGET_OPENGLES
	switch(pix.getNumChannels()) {
		case 3: return GL_RGB32F_ARB;
		case 4: return GL_RGBA32F_ARB;
		default: return GL_LUMINANCE32F_ARB;
	}
#else
	ofLogWarning()<< "float textures not supported in GLES";
	switch(pix.getNumChannels()) {
		case 3: return GL_RGB;
		case 4: return GL_RGBA;
		default: return GL_LUMINANCE;
	}
#endif
}
コード例 #10
0
ファイル: ofTexture.cpp プロジェクト: jvcleave/compare
//----------------------------------------------------------
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));
}
コード例 #11
0
FREE_IMAGE_TYPE getFreeImageType(const ofFloatPixels& pix) {
	switch(pix.getNumChannels()) {
		case 1: return FIT_FLOAT;
		case 3: return FIT_RGBF;
		case 4: return FIT_RGBAF;
		default:
			ofLogError("ofImage") << "getFreeImageType(): unknown FreeImage type for number of channels:" << pix.getNumChannels();
			return FIT_UNKNOWN;
	}
}
コード例 #12
0
void ofFbo::readToPixels(ofFloatPixels & pixels, int attachmentPoint){
#ifndef TARGET_OPENGLES
	getTextureReference(attachmentPoint).readToPixels(pixels);
#else
	bind();
	int format,type;
	ofGetGlFormatAndType(settings.internalformat,format,type);
	glReadPixels(0,0,settings.width, settings.height, format, GL_FLOAT, pixels.getPixels());
	unbind();
#endif
}
コード例 #13
0
ファイル: ftUtil.cpp プロジェクト: bossacorp/ofxFlowTools
		// 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);
	}
コード例 #14
0
ファイル: main.cpp プロジェクト: kylemcdonald/LightLeaks
 void setupSpeakers() {
     ofVec3f speakers[n_speakers];
     // maybe need to swap dimensions here?
     // possibly change scale too
     float eps = 0.001; // needed to avoid "== 0" check in shader
     speakers[0] = ofVec3f(0,0,0)+eps; // front left
     speakers[1] = ofVec3f(0,1,0)+eps; // front right
     speakers[2] = ofVec3f(1,1,0)+eps; // rear right
     speakers[3] = ofVec3f(1,0,0)+eps; // rear left
     
     float speakerAreaSize = 0.02;
     speakerXyzMap.allocate(n_samples, n_speakers, OF_IMAGE_COLOR_ALPHA);
     speakerConfidenceMap.allocate(n_samples, n_speakers, OF_IMAGE_COLOR_ALPHA);
     
     float* xyzPixels = speakerXyzMap.getPixels().getData();
     float* confidencePixels = speakerConfidenceMap.getPixels().getData();
     for(int i = 0; i < n_speakers; i++){
         for(int j = 0; j < n_samples; j++){
             // sample a spiral
             float angle = j * TWO_PI / 20; // 20 samples per full rotation
             float radius = ((float) j / n_samples) * speakerAreaSize; // 0 to speakerAreaSize
             // might need to swap axes here too
             xyzPixels[0] = speakers[i].x + sin(angle) * radius;
             xyzPixels[1] = speakers[i].y + cos(angle) * radius;
             xyzPixels[2] = speakers[i].z;
             xyzPixels[3] = 1;
             xyzPixels += 4;
             
             confidencePixels[0] = 1;
             confidencePixels[1] = 1;
             confidencePixels[2] = 1;
             confidencePixels[3] = 1;
             confidencePixels += 4;
         }
     }
     speakerXyzMap.update();
     speakerConfidenceMap.update();
     
     speakerFbo.allocate(n_samples, n_speakers);
     speakerPixels.allocate(n_samples, n_speakers, OF_IMAGE_COLOR_ALPHA);
 }
コード例 #15
0
ファイル: ofTexture.cpp プロジェクト: 3snail/openFrameworks
//----------------------------------------------------------
void ofTexture::loadData(const ofFloatPixels & pix){
	loadData(pix.getPixels(), pix.getWidth(), pix.getHeight(), ofGetGlFormat(pix));
}
コード例 #16
0
//----------------------------------------------------------
void ofTexture::allocate(const ofFloatPixels& pix){
	allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), ofGetUsingArbTex(), ofGetGlFormat(pix), ofGetGlType(pix));
}
コード例 #17
0
//----------------------------------------------------------
void ofTexture::loadData(const ofFloatPixels & pix, int glFormat){
	ofSetPixelStorei(pix.getWidth(),pix.getBytesPerChannel(),ofGetNumChannelsFromGLFormat(glFormat));
	loadData(pix.getPixels(), pix.getWidth(), pix.getHeight(), glFormat, ofGetGlType(pix));
}
コード例 #18
0
//----------------------------------------------------------
void ofTexture::loadData(const ofFloatPixels & pix){
	ofSetPixelStorei(pix.getBytesStride());
	loadData(pix.getPixels(), pix.getWidth(), pix.getHeight(), ofGetGlFormat(pix), ofGetGlType(pix));
}
コード例 #19
0
//----------------------------------------------------------
void ofTexture::allocate(const ofFloatPixels& pix, bool bUseARBExtention){
	allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), bUseARBExtention, ofGetGlFormat(pix), ofGetGlType(pix));
}
コード例 #20
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));
}
コード例 #21
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));
}