Пример #1
0
//--------------------------------------------------------------
void ofApp::draw(){
  ofEnableAlphaBlending();
  ofBlendMode(OF_BLENDMODE_ADD);

  //ofBackground(0);
  for (int n=0; n<width*height; n++){
      if (points[n] > 0) {
          //pixels.setColor(n*4, ofColor(255,255,255, (int)(ofRandom(0,255))));
          float c = 255*log(points[n])/log(np);
          pixels.setColor(n*4, ofColor(c,c,c));

    }
  }

  tex.loadData(pixels);
  tex.draw(0,0);
}
Пример #2
0
//--------------------------------------------------------------
void gFrameApp::update()
{
    ///experimental
    vidGrabber.update();
    if(vidGrabber.isFrameNew()){
        ofPixels & pixels = vidGrabber.getPixels();
        for(int i = 0; i < pixels.size(); i += pixels.getNumChannels()){
            int r = pixels[i];
            int g = pixels[i+1];
            int b = pixels[i+2];
            
            if ((r+g+b) / 3 > 128) {
                videoInverted[i] = 255;
                videoInverted[i+1] = 255;
                videoInverted[i+2] = 255;
            } else {
                videoInverted[i] = 0;
                videoInverted[i+1] = 0;
                videoInverted[i+2] = 0;
            }
        }
        videoTexture.loadData(videoInverted);
    }
    ///experimental
    
    stroke_list.update();
    
    oscUpdate();
    
    tuioClient.getMessage();
    
    simple_flow.update();
    simple_flow_2.update();
    simple_flow.color = fluidColor;
    
    // DMX UPDATE
    if (ledFrame.getEnabled()) {
        ledFrame.updateLevel();
        ledFrame.setColor(localBrushColor);
        ledFrame.update();
    }
    
    canvasFBO.begin();
    ofBackground(0);
    
    //generate obstacle on the fly
    //the stroke is drawn to an extra fbo
    //a simple shader converts the drawing into a black/white image which is then
    //feed into the obstacle buffers of the two fluids or only one fluid
    
    if (stroke_to_obstacle)
    {
//        obstacleFBO.begin();
//        
//        convert2GrayShader.begin();
//        
//        ofClear(0);
//        for(vector<GPoint> stroke : *stroke_list.getAllStrokes()){
//            caligraphyStyle.render(stroke, (int)outputRect.width, (int)outputRect.height);
//        }
//        convert2GrayShader.end();
//        
//        obstacleFBO.end();
//
//        simple_flow.addObstacle(obstacleFBO.getTexture());
//        //simple_flow_2.addObstacle(obstacleFBO.getTextureReference());
        
        //video to obstacle
        obstacleFBO.begin();
        //obstacle_video.draw(0,0, outputRect.width, outputRect.height);
        
        videoTexture.draw(0,0, outputRect.width, outputRect.height);
        
        obstacleFBO.end();
        simple_flow.addObstacle(obstacleFBO.getTexture());
        
    }
    
    //the white background fluid
    simple_flow_2.draw();
    
    if (stroke_first)
    {
        ofBlendMode(OF_BLENDMODE_SCREEN);
        //the colored foreground fluid
        simple_flow.draw();
    }
    
    if (render_stroke) {
        for(vector<GPoint> stroke : *stroke_list.getAllStrokes())
        {
            //always use claigraphy style
            caligraphyStyle.render(stroke, (int)outputRect.width, (int)outputRect.height);
        }
    }

    if (!stroke_first)
    {
        //the colored foreground fluid
        simple_flow.draw();
    }
    
    if(draw_finger_positions){
        drawFingerPositions((int)outputRect.width, (int)outputRect.height);
    }

    if (render_mapping_aid)
    {
        ofPushStyle();
        ofSetColor(255,255);
        mapping_aid.draw(0,0,outputRect.width, outputRect.height);
        ofPopStyle();
    }

    canvasFBO.end();
    
    // lifetime
    stroke_list.setLifetime(point_lifetime * 1000);
}
void CloudsVisualSystemFireworks::selfDraw()
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	ofPushStyle();
	
	ofEnableDepthTest();
    glEnable(GL_NORMALIZE);
	
	ofEnableAlphaBlending();
	ofBlendMode( OF_BLENDMODE_ADD );
	ofEnablePointSprites();
	
	vector<ofFloatColor> fireworkColorArray;
	for (map<string, ofColor>::iterator it=fwColors.begin(); it!=fwColors.end(); it++)
	{
		fireworkColorArray.push_back( ofFloatColor(it->second) );
	}
	vector<ofFloatColor> fireworkDeathColorArray;
	for (map<string, ofColor>::iterator it=fwDeathColors.begin(); it!=fwDeathColors.end(); it++)
	{
		fireworkDeathColorArray.push_back( ofFloatColor(it->second) );
	}
	
	shader.begin();
	shader.setUniform4fv("fwColors", &fireworkColorArray[0].r, fireworkColorArray.size() );
	shader.setUniform4fv("fwDeathColors", &fireworkDeathColorArray[0].r, fireworkDeathColorArray.size() );
	shader.setUniform1f( "time", ofGetElapsedTimef() );
	shader.setUniform1f( "nearClip", getCameraRef().getNearClip() );
	shader.setUniform1f( "farClip", getCameraRef().getFarClip() );
	shader.setUniform1f( "speed", speed);
	shader.setUniform1f( "particleSize", particleSize);
	
	shader.setUniform3f("cameraPosition", camPos.x, camPos.y, camPos.z );
	
	ofFloatColor c0 = startColor;
	c0.setSaturation( startColorSaturation * 255 );
	
	ofFloatColor c1 = endColor;
	c1.setSaturation( endColorSaturation * 255 );
	shader.setUniform4f("startColor", c0.r, c0.g, c0.b, c0.a );
	shader.setUniform4f("endColor", c1.r, c1.g, c1.b, c1.a );
	
	shader.setUniform3f( "gravity", gravity.x, gravity.y, gravity.z );
	
	shader.setUniformTexture("dotMap", dotImage.getTextureReference(), 4 );
	shader.setUniformTexture("triangleMap", triangleImage.getTextureReference(), 3 );
	shader.setUniformTexture("squareMap", squareImage.getTextureReference(), 2 );
	shader.setUniformTexture("circleMap", circleImage.getTextureReference(), 1 );
	
	shader.setUniform1f( "useCircleMap", bUseCircle );
	shader.setUniform1f( "useSquareMap", bUseSquare );
	shader.setUniform1f( "useTriangleMap", bUseTriangle );
	shader.setUniform1f( "useDotMap", bUseDot );
	
	ofVec3f camPos = getCameraRef().getPosition();
	shader.setUniform3f("camearPosition", camPos.x, camPos.y, camPos.z);
	shader.setUniform1f("fogDistance", fogDistance);
	shader.setUniform1f("fogAttenuation", fogAttenuation);
	ofFloatColor fc = fogColor;
	fc.setSaturation(fogSaturation);
	shader.setUniform4f("fogColor", fc.r, fc.g, fc.b, fc.a );
	
	vbo.drawElements( GL_POINTS, indexCount );
	
	shader.end();
	
	glPopAttrib();
	ofPopStyle();
}
//--------------------------------------------------------------
void testApp::setup(){
		
    radius = 400;
    max = 60;
    
    glEnable(GL_DEPTH_TEST); //make sure we test depth for 3d
    
		ofSetVerticalSync(true);
    ofEnableLighting();
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofEnableBlendMode(ofBlendMode(OF_BLENDMODE_ALPHA));
    
    mesh.addVertex(ofPoint(0,0,0)); // add center vertex
    mesh.addColor(ofColor(137,137,140,255)); // center is same as bg
    mesh.addNormal(ofVec3f(0,0,1)); // center normal points up
    
    zfreq = 3.;
    zamt = .3;
    
    //loop around and make verts in a circle, with a bit of a z-wave
    for (int i = 0; i < max; i++){
        float step = 2*PI/max; // step size around circle
        float theta = ofMap(i, 0, max-1, 0, 2*PI - step); //map i as circle divisions to actual radian values around the circle (note we don't go quite all the way around by one step, because it will be the same as where we started, so we'll just index that starting vertex when we make faces)
 
        float prevTheta = theta - step; //one step back
        float nextTheta = theta + step; // one step forward
        
        // create vertices in polar coordinates, plus a sine wave for z
        ofVec3f p(radius*cos(theta),radius*sin(theta), radius*zamt*sin(zfreq*theta) );
        // add this vertex
        mesh.addVertex(p);
        
        // we need these for calculating normals
        ofVec3f prev(radius*cos(prevTheta),radius*sin(prevTheta),radius*zamt*sin(zfreq*prevTheta) );        
        ofVec3f next(radius*cos(nextTheta),radius*sin(nextTheta),radius*zamt*sin(zfreq*nextTheta) );
        
        // our normals for each triangle face is the cross product of the two vectors making up that sliver 
        ofVec3f previousFaceNormal = prev.crossed(p);
        ofVec3f nextFaceNormal = p.crossed(next);
        
        /* notice here we go in the same direction: previous->current,current->next;
           we could similarly go next->current,current-prev, which would flip all of our normals;
           this might not be the best idea, but its certainly better than going previous->current,next->current, which would end up being quite awful.
           This is the concept of an "orientable mesh" or "face winding order", to be googled for more information.
         */
        
        // since we want smooth normals, we'll sum the two adjacent face normals, then normalize (since usually, only the direction and not the magnitude of the normal is what matters)
        mesh.addNormal((previousFaceNormal + nextFaceNormal).normalize());
        
        //add a color too
        ofColor c;
        c.setHsb(40 + 30*sin(2*theta+PI),255,255,255);        
        mesh.addColor(c);
    }
    
    //index our verts/normals/colors as a triangle fan
    for (int i=0, j = max-1; i < max; j=i++){
        mesh.addIndex(0);
        mesh.addIndex(i+1);
        mesh.addIndex(j+1);
    }
    
    // light the scene to show off why normals are important
    light.enable();
    light.setPointLight();
    light.setPosition(0,0,300);
		
}
// or you can use selfDrawBackground to do 2D drawings that don't use the 3D camera
void CloudsVisualSystemFireworks::selfDrawBackground()
{
	glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
	//    mat->begin();
	
	ofPushStyle();
	
	ofEnableAlphaBlending();
	ofBlendMode( OF_BLENDMODE_ADD );
	ofEnablePointSprites();
	
	glowFbo0.begin();
	ofClear(0,0,0,255);
	
	camera.begin();
	
//	glDisable( GL_DEPTH_TEST );
//	ofSetColor(225, 235, 255, 30 );
//	for (int i=0; i<rockets.size(); i++) {
//		rockets[i].draw();
//	}
	
	shader.begin();
	shader.setUniform1f( "time", ofGetElapsedTimef() );
	shader.setUniform1f( "nearClip", camera.getNearClip() );
	shader.setUniform1f( "farClip", camera.getFarClip() );
	shader.setUniform3f("cameraPosition", camPos.x, camPos.y, camPos.z );
	shader.setUniform4f("startColor", startColor.x, startColor.y, startColor.z, startColor.w );
	shader.setUniform4f("endColor", endColor.x, endColor.y, endColor.z, endColor.w );
	
	shader.setUniform3f( "gravity", particleGravity.x, particleGravity.y, particleGravity.z );
	
	shader.setUniformTexture("triangleMap", triangleImage.getTextureReference(), 2 );
	shader.setUniformTexture("squareMap", squareImage.getTextureReference(), 1 );
	shader.setUniformTexture("circleMap", circleImage.getTextureReference(), 0 );
	
	vbo.drawElements( GL_POINTS, numSprites );
	
	shader.end();
	
//	ofSetColor(255,0,0);
//	for (int i=0; i<emitterCount; i++) {
//		ofPushMatrix();
//		ofTranslate( emitters[i].pos );
//		
//		ofRect(-5, -5, 10, 10);
//		
//		ofPopMatrix();
//	}
	
	camera.end();
	
	glowFbo0.end();
	
	ofPopStyle();
	
	ofSetColor(255);
	int alpha = 255;
	
	glowFbo1.begin();
	ofClear(0,0,0,alpha);
	glowFbo0.draw(0, 0, glowFbo1.getWidth(), glowFbo1.getHeight() );
	glowFbo1.end();
	
	glowFbo2.begin();
	ofClear(0,0,0, alpha);
	glowFbo1.draw(0, 0, glowFbo2.getWidth(), glowFbo2.getHeight() );
	glowFbo2.end();
	
	glowFbo3.begin();
	ofClear(0,0,0, alpha);
	glowFbo2.draw(0, 0, glowFbo3.getWidth(), glowFbo3.getHeight() );
	glowFbo3.end();
	
	glowFbo4.begin();
	ofClear(0,0,0, alpha);
	glowFbo3.draw(0, 0, glowFbo4.getWidth(), glowFbo4.getHeight() );
	glowFbo4.end();
	
	glowFbo5.begin();
	ofClear(0,0,0, alpha);
	glowFbo4.draw(0, 0, glowFbo5.getWidth(), glowFbo5.getHeight() );
	glowFbo5.end();
	
	glowFbo6.begin();
	ofClear(0,0,0, alpha);
	glowFbo5.draw(0, 0, glowFbo6.getWidth(), glowFbo6.getHeight() );
	glowFbo6.end();
	
	glowShader.begin();
	glowShader.setUniformTexture( "fbo", glowFbo0.getTextureReference(), 0);
	
	glowShader.setUniformTexture( "mm1", glowFbo1.getTextureReference(), 1);
	glowShader.setUniformTexture( "mm2", glowFbo2.getTextureReference(), 2);
	glowShader.setUniformTexture( "mm3", glowFbo3.getTextureReference(), 4);
	glowShader.setUniformTexture( "mm4", glowFbo4.getTextureReference(), 5);
	glowShader.setUniformTexture( "mm5", glowFbo5.getTextureReference(), 6);
	glowShader.setUniformTexture( "mm6", glowFbo6.getTextureReference(), 7);
	glowFbo0.draw(0, 0, ofGetWidth(), ofGetHeight() );
	
	glowShader.end();
	
	ofDisablePointSprites();
}
Пример #6
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    ofBlendMode(ADD);
    
    morph_focus = ofLerp(focus,next_focus,percent);
    morph_calm = ofLerp(calm,next_calm,percent);
    morph_posture = ofLerp(posture,next_posture,percent);
    percent += 0.02;
    
    float background = 0;
    float basecolor = 100;
    float basealph = 50;
    float baser = 3;
    float margin = 100;
    step += 0.5;
    
    
    //string NAME
    ofSetColor(255);
    ofDrawBitmapString(memes[2].user_id, ofGetWidth()/2-25, ofGetHeight()/2);
    
    //string DATE
    ofSetColor(background);
    ofDrawCircle(50, step, 200);
    ofSetColor(255);
    ofDrawBitmapString(memes[index].zone_date, 10, step);
    
    //strinf focus//
    ofSetColor(background,50);
    ofDrawCircle(ofGetWidth()/2, step + 100,50);
    ofSetColor(morph_focus,basecolor,basecolor);
    ofDrawBitmapString(morph_focus, ofGetWidth()/2-20, step+100);
    
    //strinf calm//
    ofSetColor(background,50);
    ofDrawCircle(ofGetWidth()/2-margin, step + 100,50);
    ofSetColor(basecolor,morph_calm,basecolor);
    ofDrawBitmapString(morph_calm, ofGetWidth()/2-margin-20, step+100);
    
    //strinf posture//
    ofSetColor(background,50);
    ofDrawCircle(ofGetWidth()/2+margin, step + 100,50);
    ofSetColor(basecolor,basecolor,morph_posture);
    ofDrawBitmapString(morph_posture, ofGetWidth()/2+margin-20, step+100);
    
    
    
    //focus//
    ofSetColor(morph_focus,basecolor,basecolor,morph_focus + basealph);
    ofDrawCircle(ofGetWidth()/2,step,morph_focus/baser);
    
    //calm//
    ofSetColor(basecolor,morph_calm,basecolor, morph_calm + basealph);
    ofDrawCircle(ofGetWidth()/2-margin,step,morph_calm/baser);
    
    //posture//
    ofSetColor(basecolor,basecolor,morph_posture, morph_posture + basealph);
    ofDrawCircle(ofGetWidth()/2+margin,step,morph_posture/baser);
    
    
    
    //モーフィングの割合が1になった時の処理
    if (percent >=1.0) {
        //noLoop();
        //表示するデータのインデックスを進める
        index += 1;
        
        //配列の最後に到達したら停止
        if (index == memes.size() - 1) {
            //
        } else {
            //表示するデータと、次に表示するデータを更新
            focus = memes[index].zone_focus;
            next_focus = memes[index+1].zone_focus;
            
            calm = memes[index].zone_calm;
            next_calm = memes[index+1].zone_calm;
            
            posture = memes[index].zone_posture;
            next_posture = memes[index+1].zone_posture;
        }
        
        //モーフィングの割合を初期化
        percent = 0;
    }
}
void CloudsVisualSystem3DModelLoader::drawSceneGeometry( ofCamera* cam)
{
	
	//rotation velocity
	float t = ofGetElapsedTimef();
	accumulatedRotation += globalRotationVelocity * 1. / ofGetFrameRate();
	
	//draw infinite grid by positioning it infront of the camera
	if(bDrawGrid)
	{
		//	ofVec3f camPos;
		//	camPos = cam->getPosition();
		//	camPos += cam->getUpDir().cross(cam->getSideDir()).normalize() * gridDim * gridScale * .5;
		
		ofSetColor(255,255, 255, 150 );// make this an adjustable color in th GUI
		
		gridShader.begin();
		gridShader.setUniform1f("halfGridDim", gridDim * .5 );
		gridShader.setUniform1f("falloffDist", fogFalloffDistance );
		gridShader.setUniform1f("falloffExpo", fogFalloffExpo );
		gridShader.setUniform1f("falloffScl", fogFalloffScale );
		gridShader.setUniform1f("alphaScale", gridAlphaScale );
		
		//draw  minor grid
		ofPushMatrix();
		ofScale( gridScale, gridScale, gridScale );
		
		ofSetLineWidth( gridLineWidth );
		ofSetColor( gridColor.r*gridBrightness, gridColor.g*gridBrightness, gridColor.b*gridBrightness, gridAlpha );
		grid.draw(GL_LINES, 0, numGridVertices );
		
		ofPopMatrix();
		
		//draw  major grid
		ofPushMatrix();
		int gms = gridMajorScale;
		ofTranslate( getCameraRef().getLookAtDir() * -gridLineWidth / gridScale );
		ofScale( gridScale * gms,gridScale * gms, gridScale * gms );
		
		ofSetLineWidth( majorGridLineWidth );
		ofSetColor( gridMajorColor.r*gridMajorBrightness, gridMajorColor.g*gridMajorBrightness, gridMajorColor.b*gridMajorBrightness, gridMajorAlpha );
		grid.draw(GL_LINES, 0, numGridVertices );
		
		ofPopMatrix();
		
		gridShader.end();
	}
	
	//draw wireframe view cameras to the scene
	if(bDrawCameras)
	{
		drawMultipleViewCameras( cameraLineScale, cam );
	}
	
	if(bDrawArrows)
	{
		//draw arrows at model's min bound
		ofPushMatrix();
		ofTranslate( minBound * modelTransform.getGlobalTransformMatrix() );
		ofMultMatrix( modelTransform.getGlobalOrientation() );
		
		ofSetColor(0, 255, 0);
		ofPushMatrix();
		ofScale( arrowScale.x, arrowScale.y, arrowScale.z );
		arrowMesh.draw();
		ofPopMatrix();
		
		ofSetColor(255, 0, 0);
		ofPushMatrix();
		ofRotate(90, 1, 0, 0);
		ofScale( arrowScale.x, arrowScale.y, arrowScale.z );
		arrowMesh.draw();
		ofPopMatrix();
		
		ofSetColor(0, 0, 255);
		ofPushMatrix();
		ofRotate(90, 1, 0, 0);
		ofRotate(90, 0, 0, -1);
		ofScale( arrowScale.x, arrowScale.y, arrowScale.z );
		arrowMesh.draw();
		ofPopMatrix();
		
		ofPopMatrix();
	}
	
	
	//draw our model
	ofPushMatrix();
	
//	ofTranslate(-boundCenter);
	
	ofMultMatrix( modelTransform.getGlobalTransformMatrix() );
	
	if(currentSingleCam != &pathCamera)
	{
		ofTranslate( positionOffset - boundCenter );
		ofRotateX( globalRotation.x + accumulatedRotation.x );
		ofRotateY( globalRotation.y + accumulatedRotation.y );
		ofRotateZ( globalRotation.z + accumulatedRotation.z );
	}
	
	//draw bounding box
	if(bDrawBoundingBox)
	{
		ofSetColor(255, 255, 255, 255);
		drawBoundingBox();
	}
	
	if(bDrawCameraPath)
	{
		ofSetLineWidth(majorGridLineWidth);
		simpleShader.begin();
		pathCamera.drawPaths();
		simpleShader.end();
	}
	
	ofSetColor(modelColor);
	if(activeShader != NULL )
	{
		
		activeShader->begin();
		activeShader->setUniform1f( "discardThreshold", discardThreshold );
		activeShader->setUniform1f( "specularExpo", specularExpo );
		activeShader->setUniform1f( "specularScale", specularScale );
		activeShader->setUniform1f("falloffDist", fogFalloffDistance );
		activeShader->setUniform1f("falloffExpo", fogFalloffExpo );
		activeShader->setUniform1f("falloffScl", fogFalloffScale );
		
		if(activeShader == &XRayShader){
			/*
			 sfactor
			 Specifies how the red, green, blue, and alpha source blending factors are computed. The following symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE. The initial value is GL_ONE.
			 
			 dfactor
			 Specifies how the red, green, blue, and alpha destination blending factors are computed. The following symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA. GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA. The initial value is GL_ZERO.
			 */
			
			//GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
			glDisable( GL_DEPTH_TEST );
			glBlendFunc(GL_ONE, GL_ONE);
			
//			modelMesh.draw();
			bWireframe?	modelMesh.drawWireframe() : modelMesh.draw();
			
			ofBlendMode( OF_BLENDMODE_ADD );
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		}
		else{
			if(bWireframe)	ofSetLineWidth( wireframeLinewidth );
			bWireframe?	modelMesh.drawWireframe() : modelMesh.draw();
		}
		
		activeShader->end();
	}
	
	ofPopMatrix();
}