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(); }
void Fluid2DParticlesApp::draw() { // clear out the window with black gl::clear( Color( 0, 0, 0 ) ); gl::color( ColorAf( 1.0f, 1.0f, 1.0f, 0.999f ) ); float* data = const_cast<float*>( (float*)mFluid2D.rgb().data() ); Surface32f surf( data, mFluid2D.resX(), mFluid2D.resY(), mFluid2D.resX()*sizeof(Colorf), SurfaceChannelOrder::RGB ); if ( ! mTex ) { mTex = gl::Texture::create( surf ); } else { mTex->update( surf ); } gl::draw( mTex, getWindowBounds() ); mTex->unbind(); mParticles.draw(); mParams.draw(); }
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(); }