forked from simongeilfus/Cinder-Experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWireframeGeometryShaderApp.cpp
More file actions
49 lines (38 loc) · 1.41 KB
/
WireframeGeometryShaderApp.cpp
File metadata and controls
49 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#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 WireframeGeometryShaderApp : public App {
public:
WireframeGeometryShaderApp();
void draw() override;
gl::BatchRef mBatch;
};
WireframeGeometryShaderApp::WireframeGeometryShaderApp()
{
// load the shader and create a batch
gl::GlslProg::Format format;
format.vertex( loadAsset( "shader.vert" ) )
.fragment( loadAsset( "shader.frag" ) )
.geometry( loadAsset( "shader.geom" ) );
auto shader = gl::GlslProg::create( format );
mBatch = gl::Batch::create(geom::TorusKnot() >> geom::ColorFromAttrib(geom::NORMAL, (const std::function<Colorf(vec3)> &) [](vec3 n) {
return Colorf( n.x, n.y, n.z ); } ), shader );
// enable depth testing
gl::enableDepthWrite();
gl::enableDepthRead();
}
void WireframeGeometryShaderApp::draw()
{
gl::clear( Color::gray( 0.0f ) );
// setup a basic camera
gl::setMatrices( CameraPersp( getWindowWidth(), getWindowHeight(), 60, 1, 1000 ).calcFraming( Sphere( vec3( 0.0f ), 2.0f ) ) );
gl::viewport( getWindowSize() );
// render the batch with a small rotation
gl::rotate( 0.15f * getElapsedSeconds(), vec3( 0.123, 0.456, 0.789 ) );
mBatch->draw();
getWindow()->setTitle( "Framerate: " + to_string( (int) getAverageFps() ) );
}
CINDER_APP( WireframeGeometryShaderApp, RendererGl( RendererGl::Options().msaa( 8 ) ) )