示例#1
0
void Fluid2DTextureApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );

	// Update the positions and tex coords
	Rectf drawRect = getWindowBounds();
	int limX = mFluid2D.resX() - 1;
	int limY = mFluid2D.resY() - 1;
	float dx = drawRect.getWidth()/(float)limX;
	float dy = drawRect.getHeight()/(float)limY;
	
	for( int j = 0; j < mFluid2D.resY(); ++j ) {
		for( int i = 0; i < mFluid2D.resX(); ++i ) {
			vec2 P = vec2( i*dx, j*dy );
			vec2 uv = mFluid2D.texCoordAt( i, j );

			int idx = j*mFluid2D.resX() + i;
			mTriMesh->getPositions<2>()[idx] = P;
			mTriMesh->getTexCoords0<2>()[idx] = uv;
			
		}
	}

	mTex->bind();
	gl::bindStockShader( gl::ShaderDef().color().texture() );
	gl::draw( gl::VboMesh::create(*mTriMesh) );
	mTex->unbind();
	
	mParams.draw();	
}
示例#2
0
void srvlib::renderer::DrawTexture(ci::gl::Texture2dRef image, const glm::ivec2 &eye_size, const glm::ivec2 &draw_size, ci::gl::GlslProgRef shader){

  ci::gl::disableDepthRead();
  ci::gl::disableDepthWrite();

  ci::gl::pushMatrices();

  auto vp = ci::gl::getViewport();

  ci::CameraOrtho o;
  o.setOrtho(0.0f, (float)eye_size[0], 0.0f, (float)eye_size[1], (float)0, (float)1);

  ci::gl::setProjectionMatrix(o.getProjectionMatrix());

  ci::gl::setModelMatrix(glm::mat4());
  ci::gl::setViewMatrix(glm::mat4());

  image->bind();

  if (shader){
    shader->bind();
    shader->uniform("tex0", 0);
  }
  else{
    auto default_shader = ci::gl::getStockShader(ci::gl::ShaderDef().color().lambert());
    default_shader->bind();
  }

  ci::Rectf bounds(0, 0, draw_size[0], draw_size[1]);
  ci::gl::viewport(draw_size);
  ci::gl::drawSolidRect(bounds);// , glm::vec2(0, 0), glm::vec2(1, 1));
  ci::gl::viewport(vp);
  
  image->unbind();

  ci::gl::popMatrices();

  ci::gl::enableDepthRead();
  ci::gl::enableDepthWrite();
}