Created
January 5, 2017 01:04
-
-
Save johnmarinelli/0e78327846d24fda37cbdcd33110a0a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
GLfloat cube_vertices[] = { | |
// front | |
-1.0, -1.0, 1.0, | |
1.0, -1.0, 1.0, | |
1.0, 1.0, 1.0, | |
-1.0, 1.0, 1.0, | |
// back | |
-1.0, -1.0, -1.0, | |
1.0, -1.0, -1.0, | |
1.0, 1.0, -1.0, | |
-1.0, 1.0, -1.0, | |
}; | |
GLfloat cube_colors[] = { | |
// front colors | |
1.0, 0.0, 0.0, | |
0.0, 1.0, 0.0, | |
0.0, 0.0, 1.0, | |
1.0, 1.0, 1.0, | |
// back colors | |
1.0, 0.0, 0.0, | |
0.0, 1.0, 0.0, | |
0.0, 0.0, 1.0, | |
1.0, 1.0, 1.0, | |
}; | |
GLushort cube_elements[] = { | |
// front | |
0, 1, 2, | |
2, 3, 0, | |
// top | |
1, 5, 6, | |
6, 2, 1, | |
// back | |
7, 6, 5, | |
5, 4, 7, | |
// bottom | |
4, 0, 3, | |
3, 7, 4, | |
// left | |
4, 5, 1, | |
1, 0, 4, | |
// right | |
3, 2, 6, | |
6, 7, 3, | |
}; | |
class ShadedCubesApp : public App { | |
public: | |
void setup() override; | |
void mouseDown( MouseEvent event ) override; | |
void update() override; | |
void draw() override; | |
gl::GlslProgRef mGlsl; | |
GLuint mCubeVertices, mCubeColors, mCubeIBO; | |
CameraPersp mCamera; | |
}; | |
void ShadedCubesApp::setup() | |
{ | |
mCamera.setPerspective(60.f, getWindowAspectRatio(), 0.1f, 1000.f); | |
glGenBuffers(1, &mCubeVertices); | |
glBindBuffer(GL_ARRAY_BUFFER, mCubeVertices); | |
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW); | |
glGenBuffers(1, &mCubeColors); | |
glBindBuffer(GL_ARRAY_BUFFER, mCubeColors); | |
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_colors), cube_colors, GL_STATIC_DRAW); | |
glGenBuffers(1, &mCubeIBO); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mCubeIBO); | |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_elements), cube_elements, GL_STATIC_DRAW); | |
mGlsl = gl::GlslProg::create(loadResource("shadedcubes.vert"), loadResource("shadedcubes.frag")); | |
glEnable(GL_CULL_FACE); | |
glEnable(GL_DEPTH); | |
} | |
void ShadedCubesApp::mouseDown( MouseEvent event ) | |
{ | |
} | |
void ShadedCubesApp::update() | |
{ | |
} | |
void ShadedCubesApp::draw() | |
{ | |
gl::clear( Color( 0, 0, 0 ) ); | |
} | |
CINDER_APP( ShadedCubesApp, RendererGl ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment