Skip to content

Instantly share code, notes, and snippets.

@axjxwright
Created June 24, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axjxwright/520a65f88ebec736b061f297ea14da88 to your computer and use it in GitHub Desktop.
Save axjxwright/520a65f88ebec736b061f297ea14da88 to your computer and use it in GitHub Desktop.
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class MeshCombineApp : public App
{
public:
void setup ( ) override;
void draw ( ) override;
gl::BatchRef _batch;
};
void MeshCombineApp::setup()
{
Rectf r ( -vec2(100), vec2(100) );
r.scaleCentered(0.5f);
ColorAf b(0, 0, 0, 1);
ColorAf w(1, 1, 1, 1);
TriMesh outline = geom::Rect().colors().rect(r).colors(b, b, b, b);
TriMesh fill = geom::Rect().colors().rect(r.scaledCentered(0.8)).colors(w, w, w, w);
auto shader = gl::GlslProg::create( CI_GLSL(150,
uniform mat4 ciModelViewProjection;
in vec4 ciPosition;
in vec4 ciColor;
out vec4 Color;
void main ( )
{
gl_Position = ciModelViewProjection * ciPosition;
Color = ciColor;
}
),
CI_GLSL(150,
uniform vec4 uFillColor = vec4(1);
in vec4 Color;
out vec4 FinalColor;
void main ( )
{
FinalColor = Color * uFillColor;
}
) );
_batch = gl::Batch::create ( ( outline & fill ), shader );
}
void MeshCombineApp::draw()
{
gl::setMatricesWindow ( getWindowSize() );
gl::clear ( Colorf::white() );
{
gl::translate( ( getWindowCenter() ) );
gl::rotate ( getElapsedSeconds() * 0.5f );
gl::scale ( vec2 ( 2.0f + std::sin ( getElapsedSeconds() ) * 0.5f ) );
_batch->getGlslProg()->uniform ( "uFillColor", ColorAf ( 0.5f + std::sin ( getElapsedSeconds() ) * 0.5, 0.5, 0, 1 ) );
_batch->draw();
}
}
CINDER_APP( MeshCombineApp, RendererGl ( RendererGl::Options().msaa(8) ), [] ( App::Settings * settings ) { settings->setWindowSize(1280, 720); } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment