Created
June 24, 2016 00:39
-
-
Save axjxwright/520a65f88ebec736b061f297ea14da88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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