Exemplo n.º 1
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
}
Exemplo n.º 2
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
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
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);
	}