コード例 #1
0
// --------------------------------------------------
void ofxProjectorBlend::draw(float x, float y) {
	ofSetHexColor(0xFFFFFF);
	ofPushMatrix();
	ofTranslate(x, y, 0);
	if(showBlend) {
		blendShader.begin();
		blendShader.setUniform2f("uDimensions", singleChannelWidth, singleChannelHeight);
		blendShader.setUniform2f("uCanvas", getCanvasWidth(), getCanvasHeight());

		updateShaderUniforms();

		if(layout == ofxProjectorBlend_Horizontal) {
			blendShader.setUniform1f("uOverlap.right", pixelOverlap);
		}
		else {
			blendShader.setUniform1f("uOverlap.top", pixelOverlap);
		}

		blendShader.setUniformTexture("uImage", fullTexture, 0);


		ofVec2f offset(0,0);
		ofPushMatrix();

		// loop through each projector and translate to its position and draw.
		for(int i = 0; i < numProjectors; i++) {
			blendShader.setUniform2f("uOffset", offset.x, offset.y);

			if(i==1) {
				// set the first edge
				if(layout == ofxProjectorBlend_Horizontal) {
					blendShader.setUniform1f("uOverlap.left", pixelOverlap);
				}
				else {
					blendShader.setUniform1f("uOverlap.bottom", pixelOverlap);
				}

			}
			// if we're at the end of the list of projectors, turn off the second edge's blend

			if(i+1 == numProjectors) {
				if(layout == ofxProjectorBlend_Horizontal) {
					blendShader.setUniform1f("uOverlap.right", 0);
				}
				else {
					blendShader.setUniform1f("uOverlap.top", 0);
				}
			}

			ofPushMatrix(); {
				if(rotation == ofxProjectorBlend_RotatedRight) {
					ofRotate(90, 0, 0, 1);
					ofTranslate(0, -singleChannelHeight, 0);
				}
				else if(rotation == ofxProjectorBlend_RotatedLeft) {
					ofRotate(-90, 0, 0, 1);
					ofTranslate(-singleChannelWidth, 0, 0);
				}

				ofTranslate(0, (float)projectorHeightOffset[i], 0);

				quadMesh.draw();
			}
			ofPopMatrix();

			// move the texture offset and where we're drawing to.
			if(layout == ofxProjectorBlend_Horizontal) {
				offset.x += singleChannelWidth - pixelOverlap;
			}
			else {
				offset.y += singleChannelHeight - pixelOverlap;

			}

			if(rotation == ofxProjectorBlend_RotatedLeft || rotation == ofxProjectorBlend_RotatedRight) {
				ofTranslate(singleChannelHeight, 0, 0);
			}
			else {
				ofTranslate(singleChannelWidth, 0, 0);
			}

		}
		ofPopMatrix();

		blendShader.end();
	} else {
		fullTexture.draw(x, y);
	}
	ofPopMatrix();
}
コード例 #2
0
void ofxProjectorBlend::draw(float x, float y) {
	ofSetHexColor(0xFFFFFF);
	glPushMatrix();
	glTranslatef(x, y, 0);
	if(showBlend) {
		blendShader.begin();
		blendShader.setUniform1f("width", singleChannelWidth);
		blendShader.setUniform1f("height", singleChannelHeight);
		
		updateShaderUniforms();
		
		if(layout == ofxProjectorBlend_Horizontal) {
			blendShader.setUniform1f("OverlapRight", pixelOverlap);	
		}
		else {
			blendShader.setUniform1f("OverlapTop", pixelOverlap);
		}
		
		blendShader.setUniformTexture("Tex0", fullTexture.getTextureReference(), 0);
		
		
		ofVec2f offset(0,0);
		glPushMatrix();
		
		// loop through each projector and glTranslatef() to its position and draw.
		for(int i = 0; i < numProjectors; i++) {
			blendShader.setUniform2f("texCoordOffset", offset.x, offset.y);
			
			if(i==1) {
				// set the first edge
				if(layout == ofxProjectorBlend_Horizontal) {
					blendShader.setUniform1f("OverlapLeft", pixelOverlap);	
				}
				else {
					blendShader.setUniform1f("OverlapBottom", pixelOverlap);
				}
				
			}
			// if we're at the end of the list of projectors, turn off the second edge's blend
			
			if(i+1 == numProjectors) {
				if(layout == ofxProjectorBlend_Horizontal) {
					blendShader.setUniform1f("OverlapRight", 0);	
				}
				else {
					blendShader.setUniform1f("OverlapTop", 0);
				}
			}
			
			glPushMatrix(); {
				if(rotation == ofxProjectorBlend_RotatedRight) {
					glRotatef(90, 0, 0, 1);
					glTranslatef(0, -singleChannelHeight, 0);
				}
				else if(rotation == ofxProjectorBlend_RotatedLeft) {
					glRotatef(-90, 0, 0, 1);
					glTranslatef(-singleChannelWidth, 0, 0);
				}
				
				glTranslatef(0, (float)projectorHeightOffset[i], 0);
				
				glBegin(GL_QUADS);
				
				glTexCoord2f(0, 0);
				glVertex2f(0, 0);
				
				glTexCoord2f(singleChannelWidth, 0);
				glVertex2f(singleChannelWidth, 0);
				
				glTexCoord2f(singleChannelWidth, singleChannelHeight);
				glVertex2f(singleChannelWidth, singleChannelHeight);
				
				glTexCoord2f(0, singleChannelHeight);
				glVertex2f(0, singleChannelHeight);
				
				glEnd();
			}
			glPopMatrix();
			
			// move the texture offset and where we're drawing to.
			if(layout == ofxProjectorBlend_Horizontal) {
				offset.x += singleChannelWidth - pixelOverlap;
			}
			else {
				offset.y += singleChannelHeight - pixelOverlap;
				
			}
			
			
			if(rotation == ofxProjectorBlend_RotatedLeft || rotation == ofxProjectorBlend_RotatedRight) {
				glTranslatef(singleChannelHeight, 0, 0);
			}
			else {
				glTranslatef(singleChannelWidth, 0, 0);
			}
			
		}
		glPopMatrix();
	
		blendShader.end();
	} else {
		fullTexture.draw(x, y);
	}
	glPopMatrix();
}