Exemple #1
0
void testApp::process(ofFbo & fbo, ofImage & image, string name){
	fbo.begin();
	ofClear(0);
	shader.begin();
	shader.setUniformTexture("tex", cam.getTextureReference(), 0 );
	shader.setUniform2f("texSize", cam.getWidth(), cam.getHeight());
	shader.setUniform2f("size", fbo.getWidth(), fbo.getHeight());
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex3f(0, 0, 0);
	glTexCoord2f(fbo.getWidth(), 0);
	glVertex3f(fbo.getWidth(), 0, 0);
	glTexCoord2f(fbo.getWidth(), fbo.getHeight());
	glVertex3f(fbo.getWidth(), fbo.getHeight(), 0);
	glTexCoord2f(0,fbo.getHeight()); 
	glVertex3f(0,fbo.getHeight(), 0);
	glEnd();
	shader.end();
	
	fbo.end();
	
	TIME_SAMPLE_START(name);
	fbo.readToPixels(image.getPixelsRef());
	//image.update();
	TIME_SAMPLE_STOP(name);
	
	//image.draw(0, 0);
}
Exemple #2
0
//--------------------------------------------------------------
void testApp::update()
{
	int c = ofRandom(255);
	
	fbo.begin();
	ofClear(c, c, c);
	fbo.end();
	
	TIME_SAMPLE_START("PBO");	
	if (mode == 0)
	{
		reader.readToPixels(fbo, pix);
	}
	TIME_SAMPLE_STOP("PBO");
	
	TIME_SAMPLE_START("readToPixels");
	if (mode == 1)
	{
		fbo.readToPixels(pix);
	}
	TIME_SAMPLE_STOP("readToPixels");
}
Exemple #3
0
//--------------------------------------------------------------
void testApp::update(){

	OFX_REMOTEUI_SERVER_UPDATE(0.01666);
	//t.update()

	mMatMainMaterial.setAmbientColor( matAmbient);
	mMatMainMaterial.setDiffuseColor(matDiffuse);
	mMatMainMaterial.setSpecularColor(matSpecular);
	mMatMainMaterial.setShininess(25.0f);

	light.setAmbientColor(lightAmbient);
	light.setDiffuseColor(lightDiffuse);
	light.setSpecularColor(lightSpecular);


	TIME_SAMPLE_START("updateFlock");
	if (run){
		flock->update( 0.016666666f);
		for(int i = 0 ; i < NUM_FISH_PER_FLOCK; i++){
			t[i].update( flock->getMember(i)->pos);
		}			
	}
	TIME_SAMPLE_STOP("updateFlock");

	TIME_SAMPLE_START("generateMesh");
	for(int i = 0 ; i < NUM_FISH_PER_FLOCK; i++){
		t[i].generateMesh();
	}
	TIME_SAMPLE_STOP("generateMesh");

	if(animateLight || ofGetFrameNum() < 2){
		float r = lightDist;
		lightPos = ofVec3f(r * sin(lightSpeed * ofGetElapsedTimef()),
						   250,
						   r * cos(lightSpeed * ofGetElapsedTimef()) );
	}
	light.setGlobalPosition(lightPos);

}
Exemple #4
0
//--------------------------------------------------------------
void testApp::update(){
	cam.update();
	
	fbo.begin();
	ofClear(255, 0, 0);
	ofSetColor(255);
	cam.draw(0, 0);	
	ofRect(0, 0, 100, 100);
	fbo.end();
	
	ofClear(255, 0, 0);
	ofSetColor(255);
	fbo.draw(0, ofGetHeight()-HEIGHT);
	
	// increment current index first then get the next index
    // "index" is used to read pixels from a framebuffer to a PBO
    // "nextIndex" is used to process pixels in the other PBO
    index = (index + 1) % 2;
    nextIndex = (index + 1) % 2;
	
	//ofSleepMillis(50);
	
		
	// copy pixels from framebuffer to PBO
	// Use offset instead of ponter.
	// OpenGL should perform asynch DMA transfer, so glReadPixels() will return immediately.
	glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
	
	// Bind FBO
	//fbo.bind();
	TIME_SAMPLE_START("FBO to PBO");
	glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	TIME_SAMPLE_STOP("FBO to PBO");		
	// Unbind FBO
	//fbo.unbind();
	
	ofSleepMillis(15);
	
	
	// map the PBO that contain framebuffer pixels before processing it
	glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
	TIME_SAMPLE_START("PBO to CPU");
	GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
	TIME_SAMPLE_STOP("PBO to CPU");
	if(src){
		TIME_SAMPLE_START("MEMCPY");
		// copy the data to the image
		memcpy(image.getPixels(), src, WIDTH * HEIGHT * 4 * sizeof(unsigned char));
		TIME_SAMPLE_STOP("MEMCPY");
		
		TIME_SAMPLE_START("IMAGE UPDATE");
		image.update();
		TIME_SAMPLE_STOP("IMAGE UPDATE");
		
		// release pointer to the mapped buffer
		glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
	}
	// unbind PBO
	glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
	
}
Exemple #5
0
//--------------------------------------------------------------
void testApp::draw(){

	ofSetLineWidth(lineW);
	glPointSize(lineW);

	//glEnable(GL_NORMALIZE);

	gpuBlur.beginDrawScene();
		ofClear(0, 0, 0, 0);

		cam.begin();

			light.enable();

			glEnable(GL_DEPTH_TEST);
			//glShadeModel(GL_FLAT);

			ofSetColor(255);
			light.draw();

			ofEnableLighting();
			ofSetSphereResolution(4);

			flock->draw();

			glDisable(GL_COLOR_MATERIAL);
			TIME_SAMPLE_START("drawWorms");
			ofEnableBlendMode(OF_BLENDMODE_ADD);
			ofEnableBlendMode(OF_BLENDMODE_ALPHA);

			mMatMainMaterial.begin();
			if(doShader){
				shader->begin();
				shader->setUniform1f("shaderVal1", 1);
				shader->setUniform1f("shaderVal2", 1);
				shader->setUniform1f("shaderVal3", 1);
				shader->setUniform1f("time", ofGetElapsedTimef() );
				shader->setUniform1f("specularGain", specularGain);
				shader->setUniform1f("specularClamp", specularClamp);
				shader->setUniform1f("specularPow", specularPow);
				shader->setUniform1f("eyeSpecularGain", eyeSpecularGain);
				shader->setUniform1f("eyeSpecularClamp", eyeSpecularClamp);
				shader->setUniform1f("eyeSpecularPow", eyeSpecularPow);
				shader->setUniform1f("showInShader", showInShader);
			}

			if(drawTeapot) glutSolidTeapot(80);

			if(drawTrails){
				for(int i = 0; i < NUM_FISH_PER_FLOCK; i++){
					t[i].draw();
				}
			}
			if(doShader){
				shader->end();
			}
			mMatMainMaterial.end();

			ofDisableLighting();
			TIME_SAMPLE_STOP("drawWorms");

			ofDrawAxis(10);
			ofSetColor(255);
			
			glDisable(GL_DEPTH_TEST);
		
		cam.end();

	gpuBlur.endDrawScene();

	ofSetColor(255);
	ofEnableBlendMode(OF_BLENDMODE_ALPHA);
	gpuBlur.performBlur();

	//draw clean scene
	ofSetColor(255);
	ofBackgroundGradient(ofColor::fromHsb(160, 255, 60), ofColor::fromHsb(0, 0, 0));

	ofEnableBlendMode(OF_BLENDMODE_ALPHA);
	gpuBlur.drawSceneFBO();
	ofEnableBlendMode(OF_BLENDMODE_ADD);

	//overlay the blur
	gpuBlur.drawBlurFbo();

	ofSetColor(255);

}
Exemple #6
0
//--------------------------------------------------------------
void testApp::draw(){


	float lineHeight = ofMap(mouseY, 0, ofGetHeight(), 0, 2, true);
	unicodeFont.setLineHeight(lineHeight);

	float x = 30;
	float y = 40;
	
	string demoText = "This is my text in BitStream Vera font.";
	float fontSize = 28;

	// simple demo //////////////////////////////////////////////////////////
	
	drawPoint(x, y);		//draw insertion point	
	
	ofSetColor(255);
	TIME_SAMPLE_START("simple draw");
	font.draw(
				  demoText,	//text to draw
				  fontSize,	//font size
				  x,		//x coord where to draw
				  y			//y coord where to draw
			  );
	TIME_SAMPLE_STOP("simple draw");
	
	// bounding box demo ///////////////////////////////////////////////////
	
	ofSetColor(255, 0, 0, 32);
	TIME_SAMPLE_START("bbox");
	ofRectangle bbox = font.getBBox( demoText, fontSize, x, y);
	TIME_SAMPLE_STOP("bbox");
	ofRect( bbox );
		
	
	// draw multiline text /////////////////////////////////////////////////
	
	y += 25 + bbox.height;
	drawPoint(x, y); //draw insertion point	
	
	ofSetColor(255);
	string s = (string)"ofxFontStash can draw multiline text" + "\n" +
	"It also supports unicode strings: " + "\n" +
	"槊監しゅ祟䤂לרפובליקה. אם מיזם 銆銌 憉 圩芰敔 तकनिकल कार्यलय";

	TIME_SAMPLE_START("drawMultiLine");
	unicodeFont.drawMultiLine( s,  fontSize, x, y);
	TIME_SAMPLE_STOP("drawMultiLine");
	
	// multiline bbox /////////////////////////////////////////////////////

	ofSetColor(0, 255, 0, 32);
	TIME_SAMPLE_START("getBoundingBoxSize");
	ofRectangle bboxMultiline = unicodeFont.getBBox( s, fontSize, x, y);
	TIME_SAMPLE_STOP("getBoundingBoxSize");
	ofRect( bboxMultiline );


	// draw multiline column with a fixed width ///////////////////////////

	y += 25 + bboxMultiline.height;
	drawPoint(x, y); //draw insertion point

	ofSetColor(255);
	s = "And you can wrap text to a certain (mouseX) width:\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.";

	TIME_SAMPLE_START("drawMultiLineColumn");
	ofRectangle column = unicodeFont.drawMultiLineColumn( s,  fontSize, x, y, MAX( 200 ,mouseX - x) );
	TIME_SAMPLE_STOP("drawMultiLineColumn");
	ofSetColor(255,32);
	ofRect(column);


	// batch drawing, optimized for multiple drawing calls /////////////////

	y += column.height + 25;
	drawPoint(x, y); //draw insertion point

	ofSetColor(255);
	TIME_SAMPLE_START("drawBatch");
	font.beginBatch();	//call "begin" before drawing fonts
	for (int i = 0; i < 5; i++){
		font.drawBatch("batch mode #" + ofToString(i+1), fontSize, x, y + i * fontSize );
	}
	font.endBatch();		//call "end" once finished
	TIME_SAMPLE_STOP("drawBatch");

	// rotating text ///////////////////////////////////////////////////////
	
	ofPushMatrix();
		ofTranslate(x + 400, y + 50);
		ofRotate( -200 * ofGetElapsedTimef(), 0, 0, 1);
		ofSetColor(ofRandom(255), ofRandom(255), ofRandom(255));
		font.draw("surrealismoooo!", fontSize, 0, 0 );
		drawPoint(0,0);
	ofPopMatrix();

	ofSetColor(255);
	TIME_SAMPLE_DRAW_BOTTOM_RIGHT();
}
Exemple #7
0
//--------------------------------------------------------------
void ofApp::draw(){

	float lineHeight = ofMap(mouseY, 0, ofGetHeight(), 0, 2, true);
	unicodeFont.setLineHeight(lineHeight);

	float x = 30;
	float y = 40;
	
	string demoText = "This is my text in BitStream Vera font.";
	float fontSize = 28;

	// simple demo //////////////////////////////////////////////////////////
	
	drawPoint(x, y);		//draw insertion point	

	ofSetColor(255);
	TIME_SAMPLE_START("simple draw");
	font.draw(
				  demoText,	//text to draw
				  fontSize,	//font size
				  x,		//x coord where to draw
				  y			//y coord where to draw
			  );
	TIME_SAMPLE_STOP("simple draw");

	// bounding box demo ///////////////////////////////////////////////////
	ofRectangle bbox;
	ofRectangle bboxMultiline;

	ofSetColor(255, 0, 0, 32);
	TIME_SAMPLE_START("bbox");
	bbox = font.getBBox( demoText, fontSize, x, y);
	TIME_SAMPLE_STOP("bbox");
	ofRect( bbox );

	// draw multiline text /////////////////////////////////////////////////
	
	y += 25 + bbox.height;
	drawPoint(x, y); //draw insertion point	
	
	ofSetColor(255);
	string s = (string)"ofxFontStash can draw multiline text" + "\n" +
	"It also supports unicode strings: " + "\n" +
	"槊監しゅ祟䤂לרפובליקה. אם מיזם 銆銌 憉 圩芰敔 तकनिकल कार्यलय";

	TIME_SAMPLE_START("drawMultiLine");
	unicodeFont.drawMultiLine( s,  fontSize, x, y);
	TIME_SAMPLE_STOP("drawMultiLine");
	
	// multiline bbox /////////////////////////////////////////////////////

	ofSetColor(0, 255, 0, 32);
	TIME_SAMPLE_START("getBoundingBoxSize");
	bboxMultiline = unicodeFont.getBBox( s, fontSize, x, y);
	TIME_SAMPLE_STOP("getBoundingBoxSize");
	ofRect( bboxMultiline );


	// draw multiline column with a fixed width ///////////////////////////

	y += 25 + bboxMultiline.height;
	drawPoint(x, y); //draw insertion point

	ofSetColor(255);
	s = "And you can wrap text to a certain (mouseX) width:\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.";
	//s = "international bananas";

	int numLines = 0;
	bool wordsWereCropped;
	ofRectangle column;
	TIME_SAMPLE_START("drawMultiLineColumn");
	column = font.drawMultiLineColumn(	s,			/*string*/
										fontSize,	/*size*/
										x, y,		/*where*/
										MAX( 10 ,mouseX - x), /*column width*/
										numLines,	/*get back the number of lines*/
										false,		/* if true, we wont draw (just get bbox back) */
										5,			/* max number of lines to draw, crop after that */
										true,		/*get the final text formatting (by adding \n's) in the supplied string;
													 BE ARWARE that using TRUE in here will modify your supplied string! */
										&wordsWereCropped /* this bool will b set to true if the box was to small to fit all text*/
									 );
	TIME_SAMPLE_STOP("drawMultiLineColumn");


	//report if some words had to be cropped to fit in the column when using drawMultiLineColumn()
	if(!wordsWereCropped) ofSetColor(255,32);
	else (ofGetFrameNum()%6 <= 2) ? ofSetColor(255,32):ofSetColor(255,0,0,32); //flash if cropped
	ofRect(column);


	// batch drawing, optimized for multiple drawing calls /////////////////

	y += column.height + 25;
	drawPoint(x, y); //draw insertion point

	ofSetColor(255);
	TIME_SAMPLE_START("drawBatch");
	font.beginBatch();	//call "begin" before drawing fonts
	for (int i = 0; i < 5; i++){
		font.drawBatch("batch mode #" + ofToString(i+1), fontSize, x, y + i * fontSize );
	}
	font.endBatch();		//call "end" once finished
	TIME_SAMPLE_STOP("drawBatch");

	// formatted text //////////////////////////////////////////////////////

	string formattedText = "the #0xff0000 @1 %2.0 red %1.0 #0xffffff @0 apple is on the big %4.0 #0x00ff00 tree.";

	ofPushMatrix();
	ofTranslate(20,500);
	ofSetColor(255);
	ofVec2f size = font.drawMultiColumnFormatted(formattedText, 22, mouseX);
	ofSetColor(255,10);
	ofRect(0, 0, size.x, size.y);
	ofPopMatrix();


	// rotating text ///////////////////////////////////////////////////////
	
	ofPushMatrix();
		ofTranslate(x + 400, y + 50);
		ofRotate( -200 * ofGetElapsedTimef(), 0, 0, 1);
		ofSetColor(ofRandom(255), ofRandom(255), ofRandom(255));
		font.draw("surrealismoooo!", fontSize, 0, 0 );
		drawPoint(0,0);
	ofPopMatrix();

	// scaling text with mipmaps ///////////////////////////////////////////

	ofPushMatrix();
	ofTranslate(600, 40);
	float scale = mouseY /(float) ofGetHeight();
	ofPushMatrix();
	ofScale(scale, scale);
	ofSetColor(255);
	unicodeFont.draw("MIPMAPS :)", fontSize * 2, 0, 0 );
	drawPoint(0,0);
	ofPopMatrix();

	ofTranslate(0, 30);
	ofScale(scale, scale);
	font.draw("NO MIPMAPS :(", fontSize * 2, 0, 0 );
	drawPoint(0,0);
	ofPopMatrix();


}