├── .gitignore ├── CiOpenGl-Tutorial.sln ├── Lesson01 ├── assets │ ├── simple_frag.glsl │ └── simple_vert.glsl ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── Lesson01App.cpp └── vc2013 │ ├── Lesson01.sln │ ├── Lesson01.vcxproj │ ├── Lesson01.vcxproj.filters │ ├── Lesson01.vcxproj.user │ └── Resources.rc ├── Lesson02 ├── assets │ ├── simple_frag.glsl │ └── simple_vert.glsl ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── Lesson02App.cpp └── vc2013 │ ├── Lesson02.sln │ ├── Lesson02.vcxproj │ ├── Lesson02.vcxproj.filters │ └── Resources.rc ├── Lesson03 ├── assets │ ├── simple_frag.glsl │ └── simple_vert.glsl ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── Lesson03App.cpp └── vc2013 │ ├── Lesson03.sln │ ├── Lesson03.vcxproj │ ├── Lesson03.vcxproj.filters │ └── Resources.rc ├── Lesson04 ├── assets │ ├── simple_frag.glsl │ ├── simple_vert.glsl │ └── texture.png ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── Lesson04App.cpp └── vc2013 │ ├── Lesson04.sln │ ├── Lesson04.vcxproj │ ├── Lesson04.vcxproj.filters │ ├── Lesson04.vcxproj.user │ └── Resources.rc ├── Lesson04b ├── assets │ ├── simple_frag.glsl │ ├── simple_vert.glsl │ └── texture.png ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── Lesson04bApp.cpp └── vc2013 │ ├── Lesson04b.sln │ ├── Lesson04b.vcxproj │ ├── Lesson04b.vcxproj.filters │ └── Resources.rc ├── Lesson05 ├── assets │ ├── simple_frag.glsl │ ├── simple_vert.glsl │ └── texture.png ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── Lesson05App.cpp └── vc2013 │ ├── Lesson05.sln │ ├── Lesson05.vcxproj │ ├── Lesson05.vcxproj.filters │ └── Resources.rc ├── LessonBillboards ├── assets │ ├── billboard_frag.glsl │ ├── billboard_vert.glsl │ └── tex_petal.png ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonBillboardsApp.cpp └── vc2013 │ ├── LessonBillboards.sln │ ├── LessonBillboards.vcxproj │ ├── LessonBillboards.vcxproj.filters │ ├── LessonBillboards.vcxproj.user │ └── Resources.rc ├── LessonIndexedVBO ├── assets │ ├── index_vbo_frag.glsl │ └── index_vbo_vert.glsl ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonIndexedVBOApp.cpp └── vc2013 │ ├── LessonIndexedVBO.sln │ ├── LessonIndexedVBO.vcxproj │ ├── LessonIndexedVBO.vcxproj.filters │ └── Resources.rc ├── LessonIndexedVBODynamic ├── assets │ ├── dyn_vbo_frag.glsl │ └── dyn_vbo_vert.glsl ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonIndexedVBODynamicApp.cpp └── vc2013 │ ├── LessonIndexedVBODynamic.sln │ ├── LessonIndexedVBODynamic.vcxproj │ ├── LessonIndexedVBODynamic.vcxproj.filters │ └── Resources.rc ├── LessonInstancing ├── assets │ ├── inst_frag.glsl │ ├── inst_vert.glsl │ └── texture.png ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonInstancingApp.cpp └── vc2013 │ ├── LessonInstancing.sln │ ├── LessonInstancing.vcxproj │ ├── LessonInstancing.vcxproj.filters │ ├── LessonInstancing.vcxproj.user │ └── Resources.rc ├── LessonInstancingAdvanced ├── assets │ ├── frag.glsl │ └── vert.glsl ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonInstancingAdvancedApp.cpp └── vc2013 │ ├── LessonInstancingAdvanced.sln │ ├── LessonInstancingAdvanced.vcxproj │ ├── LessonInstancingAdvanced.vcxproj.filters │ └── Resources.rc ├── LessonLightingBasics1 ├── assets │ ├── basic_lighting_light.frag │ ├── basic_lighting_light.vert │ ├── basic_lighting_plane.frag │ ├── basic_lighting_plane.vert │ ├── basic_lighting_torus.frag │ └── basic_lighting_torus.vert ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonLightingBasics1App.cpp └── vc2013 │ ├── LessonLightingBasics1.sln │ ├── LessonLightingBasics1.vcxproj │ ├── LessonLightingBasics1.vcxproj.filters │ ├── LessonLightingBasics1.vcxproj.user │ └── Resources.rc ├── LessonLightingBasics2 ├── assets │ ├── basic_lighting_light.frag │ ├── basic_lighting_light.vert │ ├── basic_lighting_plane.frag │ ├── basic_lighting_plane.vert │ ├── basic_lighting_torus.frag │ ├── basic_lighting_torus.vert │ └── normal_4.png ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonLightingBasics2App.cpp └── vc2013 │ ├── LessonLightingBasics2.sln │ ├── LessonLightingBasics2.vcxproj │ ├── LessonLightingBasics2.vcxproj.filters │ └── Resources.rc ├── LessonRTT1 ├── assets │ ├── basic_lighting_light.frag │ ├── basic_lighting_light.vert │ ├── basic_lighting_plane.frag │ ├── basic_lighting_plane.vert │ ├── basic_lighting_torus.frag │ └── basic_lighting_torus.vert ├── include │ └── Resources.h ├── resources │ └── cinder_app_icon.ico ├── src │ └── LessonRTT1App.cpp └── vc2013 │ ├── LessonRTT1.sln │ ├── LessonRTT1.vcxproj │ ├── LessonRTT1.vcxproj.filters │ └── Resources.rc ├── README.md └── REVISIONS.md /.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | *.opensdf 3 | *.sdf 4 | *.suo 5 | Release 6 | -------------------------------------------------------------------------------- /Lesson01/assets/simple_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | out vec4 oColor; 4 | 5 | void main() 6 | { 7 | oColor = vec4(1.0,0.0,0.0,1.0); 8 | } -------------------------------------------------------------------------------- /Lesson01/assets/simple_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; 6 | 7 | 8 | void main( void ) 9 | { 10 | gl_Position = ciModelViewProjection * ciPosition; 11 | } -------------------------------------------------------------------------------- /Lesson01/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson01/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson01/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /Lesson01/src/Lesson01App.cpp: -------------------------------------------------------------------------------- 1 | /* Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 2 | 3 | Lesson 01: The first triangle 4 | Original Tutorial: 5 | http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/ 6 | */ 7 | 8 | #include "cinder/app/App.h" 9 | #include "cinder/app/RendererGl.h" 10 | #include "cinder/gl/Batch.h" 11 | #include "cinder/gl/GlslProg.h" 12 | 13 | using namespace ci; 14 | using namespace ci::app; 15 | using namespace std; 16 | 17 | class Lesson01App : public App 18 | { 19 | public: 20 | void setup() override; 21 | void update() override; 22 | void draw() override; 23 | 24 | gl::GlslProgRef mGlsl; 25 | gl::VboRef mShapeVbo; 26 | geom::BufferLayout mShapeLayout; 27 | gl::VboMeshRef mShapeMesh; 28 | gl::BatchRef mBatch; 29 | }; 30 | 31 | void Lesson01App::setup() 32 | { 33 | auto ad = getAssetPath("simple_vert.glsl"); 34 | 35 | getWindow()->setSize(1024, 768); 36 | 37 | // Load our shaders first. In this tutorial series, everything uses shaders 38 | // A. So we can practice writing shaders 39 | // B. So we get comfortable with cinder's new shader API 40 | // We'll skip over cinder's stock shader functionality because it probably 41 | // shouldn't be used for production, and again, we should get comfortable 42 | // with the idea that all of our content needs shaders and at the very least 43 | // we should write our own library of stock shaders 44 | try 45 | { 46 | mGlsl = gl::GlslProg::create(loadAsset("simple_vert.glsl"), loadAsset("simple_frag.glsl")); 47 | } 48 | 49 | // cinder defines a few different glsl exceptions that derive from the base GlslProgExc class 50 | // so we'll catch them all here. Might seem a bit heavy handed, but e.what() will actually 51 | // provide all the info you should need for simple debugging. 52 | catch (const gl::GlslProgExc &e) 53 | { 54 | console() << "Error loading shaders:" << endl; 55 | console() << e.what() << endl; 56 | quit(); 57 | } 58 | 59 | // First we'll set up our buffer data. This is analogous-ish to: 60 | // static const GLfloat g_vertex_buffer_data[] = { 61 | // -1.0f, -1.0f, 0.0f, 62 | // 1.0f, -1.0f, 0.0f, 63 | // 0.0f, 1.0f, 0.0f, 64 | // }; 65 | // GLuint vertexbuffer; 66 | // glGenBuffers(1, &vertexbuffer); 67 | // glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); 68 | // glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); 69 | float cWidth = (float)getWindowWidth(); 70 | float cHeight = (float)getWindowHeight(); 71 | vector cVertices = { vec3(0.0, cHeight, 0.0), 72 | vec3(cWidth, cHeight, 0.0), 73 | vec3(cWidth / 2, 0.0, 0.0) }; 74 | mShapeVbo = gl::Vbo::create(GL_ARRAY_BUFFER, cVertices, GL_STATIC_DRAW); 75 | 76 | // Now we'll set add attributes and set up our draw object. This is analogous-ish to: 77 | // glEnableVertexAttribArray(0); 78 | // glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); 79 | // glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,(void*)0); 80 | // 81 | // Note how appending to a Vbo::Layout maps-ish to a glVertexAttribPointerCall: 82 | // glVertexAttribPointer( index, size, datatype, normalize, stride, offset) 83 | // mShapeLayout.append( attribute, datatype, size, stride, offset) 84 | mShapeLayout.append(geom::Attrib::POSITION, geom::DataType::FLOAT, 3, sizeof(vec3), 0); 85 | 86 | // Lastly, set up our draw objects. Under the hood, we're actually "drawing" the vbomesh 87 | // (See Batch.cpp for details), the Batch manages all the other things like vertex array objects, 88 | // attribute mapping, etc. If you're famililar with pre 0.9.0/glNext Cinder, Batch is where 89 | // shader binding and other drawing related ops take place (did you notice that we don't call 90 | // mGlsl->bind() directly?) 91 | mShapeMesh = gl::VboMesh::create(3, GL_TRIANGLES, { { mShapeLayout, mShapeVbo } }); 92 | mBatch = gl::Batch::create(mShapeMesh, mGlsl); 93 | } 94 | 95 | void Lesson01App::update() 96 | { 97 | } 98 | 99 | void Lesson01App::draw() 100 | { 101 | gl::clear(Color(0, 0, 0.15f)); 102 | gl::setMatricesWindowPersp(getWindowSize()); 103 | 104 | // Finally, draw our triangle! This is where we call glDrawArrays or 105 | // glDrawElements, depending on how our batch is set up initially. In this case, 106 | // we glDrawArrays(). 107 | mBatch->draw(); 108 | } 109 | 110 | CINDER_APP( Lesson01App, RendererGl ) -------------------------------------------------------------------------------- /Lesson01/vc2013/Lesson01.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lesson01", "Lesson01.vcxproj", "{0180951B-35C7-4488-8F54-0CEE3F9F3D00}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0180951B-35C7-4488-8F54-0CEE3F9F3D00}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {0180951B-35C7-4488-8F54-0CEE3F9F3D00}.Debug|Win32.Build.0 = Debug|Win32 14 | {0180951B-35C7-4488-8F54-0CEE3F9F3D00}.Release|Win32.ActiveCfg = Release|Win32 15 | {0180951B-35C7-4488-8F54-0CEE3F9F3D00}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Lesson01/vc2013/Lesson01.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {0180951B-35C7-4488-8F54-0CEE3F9F3D00} 15 | Lesson01 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Lesson01/vc2013/Lesson01.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {40151f60-8551-4e56-96ce-7f391f60e858} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /Lesson01/vc2013/Lesson01.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Lesson01/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /Lesson02/assets/simple_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | out vec4 oColor; 4 | 5 | void main() 6 | { 7 | oColor = vec4(1.0,0.0,0.0,1.0); 8 | } -------------------------------------------------------------------------------- /Lesson02/assets/simple_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; 6 | 7 | void main( void ) 8 | { 9 | gl_Position = ciModelViewProjection * ciPosition; 10 | } -------------------------------------------------------------------------------- /Lesson02/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson02/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson02/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /Lesson02/src/Lesson02App.cpp: -------------------------------------------------------------------------------- 1 | /* Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 2 | 3 | Lesson 02: Camera 4 | Original Tutorial: 5 | http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ 6 | 7 | We're deviating a bit from the original tutorial here as we won't implement all 8 | the matrix math ourselves, instead we'll learn how to work with Cinder's CameraPersp. 9 | I recommend reading the original tutorial as it'll give you a good understanding of what 10 | CameraPersp is probably doing under the hood. 11 | */ 12 | 13 | #include "cinder/app/App.h" 14 | #include "cinder/app/RendererGl.h" 15 | #include "cinder/Camera.h" 16 | #include "cinder/gl/Batch.h" 17 | #include "cinder/gl/GlslProg.h" 18 | 19 | using namespace ci; 20 | using namespace ci::app; 21 | using namespace std; 22 | 23 | class Lesson02App : public App { 24 | public: 25 | void setup() override; 26 | void update() override; 27 | void draw() override; 28 | 29 | gl::GlslProgRef mGlsl; 30 | gl::VboRef mShapeVbo; 31 | geom::BufferLayout mShapeLayout; 32 | gl::VboMeshRef mShapeMesh; 33 | gl::BatchRef mBatch; 34 | 35 | CameraPersp mCamera; 36 | }; 37 | 38 | void Lesson02App::setup() 39 | { 40 | getWindow()->setSize(1024, 768); 41 | try 42 | { 43 | mGlsl = gl::GlslProg::create(loadAsset("simple_vert.glsl"), loadAsset("simple_frag.glsl")); 44 | } 45 | catch (const gl::GlslProgExc &e) 46 | { 47 | console() << "Error loading shaders:" << endl; 48 | console() << e.what() << endl; 49 | quit(); 50 | } 51 | 52 | // Let's set up our camera now. All sorts of matrix magic happens here, and you'll notice that 53 | // the commands and parameters map 1-to-1. 54 | // So, perspective matrix first. Note how CameraPersp::setPerspective() maps to 55 | // glm::perspective(): 56 | //glm::mat4 perspective(float fovy, float aspect, float zNear, float zFar); 57 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 58 | 59 | // Now the view matrix. Once again, note the mapping: 60 | // glm::mat4 glm::lookAt(glm::vec3 const & eye, glm::vec3 const & center, glm::vec3 const & up); 61 | mCamera.lookAt(vec3(4, 3, 3), vec3(0), vec3(0, 1, 0)); 62 | 63 | // Since we're in 3d space now, we'll change our vertex coords to properly reflect 64 | // our new camera based viewport. Everything else pretty much stays the same. 65 | vector cVertices = { vec3(-1.0, -1.0, 0.0), 66 | vec3(1.0, -1.0, 0.0), 67 | vec3(0.0, 1.0, 0.0) }; 68 | 69 | mShapeVbo = gl::Vbo::create(GL_ARRAY_BUFFER, cVertices, GL_STATIC_DRAW); 70 | mShapeLayout.append(geom::Attrib::POSITION, geom::DataType::FLOAT, 3, sizeof(vec3), 0); 71 | mShapeMesh = gl::VboMesh::create(3, GL_TRIANGLES, { { mShapeLayout, mShapeVbo } }); 72 | mBatch = gl::Batch::create(mShapeMesh, mGlsl); 73 | } 74 | 75 | void Lesson02App::update() 76 | { 77 | } 78 | 79 | void Lesson02App::draw() 80 | { 81 | gl::clear(Color(0, 0, 0.15f)); 82 | 83 | // Now we set our modelviewprojection matrix, based on the camera we set up earlier. 84 | // Everything will be drawn relative to the camera until we specify new matrices. 85 | gl::setMatrices(mCamera); 86 | mBatch->draw(); 87 | } 88 | CINDER_APP( Lesson02App, RendererGl ) 89 | -------------------------------------------------------------------------------- /Lesson02/vc2013/Lesson02.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lesson02", "Lesson02.vcxproj", "{39CE1ADD-AE4D-4169-9AD8-A18C38E218E1}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {39CE1ADD-AE4D-4169-9AD8-A18C38E218E1}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {39CE1ADD-AE4D-4169-9AD8-A18C38E218E1}.Debug|Win32.Build.0 = Debug|Win32 14 | {39CE1ADD-AE4D-4169-9AD8-A18C38E218E1}.Release|Win32.ActiveCfg = Release|Win32 15 | {39CE1ADD-AE4D-4169-9AD8-A18C38E218E1}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Lesson02/vc2013/Lesson02.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {39CE1ADD-AE4D-4169-9AD8-A18C38E218E1} 15 | Lesson02 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Lesson02/vc2013/Lesson02.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {b8b623a0-00d8-4693-b778-27fe0978227a} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /Lesson02/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /Lesson03/assets/simple_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 Color; 4 | 5 | out vec4 oColor; 6 | 7 | 8 | void main() 9 | { 10 | oColor = Color; 11 | } -------------------------------------------------------------------------------- /Lesson03/assets/simple_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; 6 | in vec4 ciColor; 7 | 8 | out lowp vec4 Color; 9 | 10 | void main( void ) 11 | { 12 | gl_Position = ciModelViewProjection * ciPosition; 13 | Color = ciColor; 14 | } -------------------------------------------------------------------------------- /Lesson03/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson03/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson03/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /Lesson03/src/Lesson03App.cpp: -------------------------------------------------------------------------------- 1 | /* Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 2 | 3 | Lesson 03: Colored cube 4 | Original Tutorial: 5 | http://www.opengl-tutorial.org/beginners-tutorials/tutorial-4-a-colored-cube/ 6 | 7 | In this tutorial, we'll draw an actual 3d primitive and practice setting up more attributes. 8 | */ 9 | 10 | #include "cinder/app/App.h" 11 | #include "cinder/app/RendererGl.h" 12 | #include "cinder/Camera.h" 13 | #include "cinder/gl/Batch.h" 14 | #include "cinder/gl/GlslProg.h" 15 | 16 | using namespace ci; 17 | using namespace ci::app; 18 | using namespace std; 19 | 20 | class Lesson03App : public App { 21 | public: 22 | void setup() override; 23 | void update() override; 24 | void draw() override; 25 | 26 | 27 | gl::GlslProgRef mGlsl; 28 | gl::VboRef mPositionData, mColorData; 29 | geom::BufferLayout mPositionLayout, mColorLayout; 30 | gl::VboMeshRef mCubeMesh; 31 | gl::BatchRef mBatch; 32 | 33 | CameraPersp mCamera; 34 | }; 35 | 36 | void Lesson03App::setup() 37 | { 38 | getWindow()->setSize(1024, 768); 39 | try 40 | { 41 | mGlsl = gl::GlslProg::create(loadAsset("simple_vert.glsl"), loadAsset("simple_frag.glsl")); 42 | } 43 | catch (const gl::GlslProgExc &e) 44 | { 45 | console() << "Error loading shaders:" << endl; 46 | console() << e.what() << endl; 47 | quit(); 48 | } 49 | 50 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 51 | mCamera.lookAt(vec3(3, 3, 3), vec3(0), vec3(0, 1, 0)); 52 | 53 | // Since we're creating a cube, that means many more verts! 54 | // If you're already familiar with OpenGL, yes, this is the brute force way of doing this and 55 | // we should be using indices, we'll get to that in a later lesson. 56 | // If you're not familiar with opengl and 3d primitives, just know for now that we need 57 | // one vert per triangle point and two triangles per cube face, so 3 * 2 * 6 = 36 58 | vector cVertices = 59 | { 60 | vec3(-1.0f, -1.0f, -1.0f), vec3(-1.0f, -1.0f, 1.0f), vec3(-1.0f, 1.0f, 1.0f), 61 | vec3(-1.0f, -1.0f, -1.0f), vec3(-1.0f, 1.0f, 1.0f), vec3(-1.0f, 1.0f, -1.0f), 62 | vec3(1.0f, 1.0f, 1.0f), vec3(1.0f, 1.0f, -1.0f), vec3(-1.0f, 1.0f, -1.0f), 63 | vec3(1.0f, 1.0f, 1.0f), vec3(-1.0f, 1.0f, -1.0f), vec3(-1.0f, 1.0f, 1.0f), 64 | vec3(1.0f, -1.0f, -1.0f), vec3(1.0f, -1.0f, 1.0f), vec3(1.0f, 1.0f, 1.0f), 65 | vec3(1.0f, -1.0f, -1.0f), vec3(1.0f, 1.0f, 1.0f), vec3(1.0f, 1.0f, -1.0f), 66 | vec3(1.0f, -1.0f, 1.0f), vec3(-1.0f, -1.0f, -1.0f), vec3(1.0f, -1.0f, -1.0f), 67 | vec3(1.0f, -1.0f, 1.0f), vec3(-1.0f, -1.0f, 1.0f), vec3(-1.0f, -1.0f, -1.0f), 68 | vec3(1.0f, 1.0f, -1.0f), vec3(-1.0f, -1.0f, -1.0f), vec3(-1.0f, 1.0f, -1.0f), 69 | vec3(1.0f, 1.0f, -1.0f), vec3(1.0f, -1.0f, -1.0f), vec3(-1.0f, -1.0f, -1.0f), 70 | vec3(-1.0f, 1.0f, 1.0f), vec3(-1.0f, -1.0f, 1.0f), vec3(1.0f, -1.0f, 1.0f), 71 | vec3(1.0f, 1.0f, 1.0f), vec3(-1.0f, 1.0f, 1.0f), vec3(1.0f, -1.0f, 1.0f) 72 | }; 73 | 74 | // We also need one color per vertex 75 | vector cColors = 76 | { 77 | vec4(0.583f, 0.771f, 0.014f, 1.0f), vec4(0.609f, 0.115f, 0.436f, 1.0f), vec4(0.327f, 0.483f, 0.844f, 1.0f), 78 | vec4(0.822f, 0.569f, 0.201f, 1.0f), vec4(0.435f, 0.602f, 0.223f, 1.0f), vec4(0.310f, 0.747f, 0.185f, 1.0f), 79 | vec4(0.597f, 0.770f, 0.761f, 1.0f), vec4(0.559f, 0.436f, 0.730f, 1.0f), vec4(0.359f, 0.583f, 0.152f, 1.0f), 80 | vec4(0.483f, 0.596f, 0.789f, 1.0f), vec4(0.559f, 0.861f, 0.639f, 1.0f), vec4(0.195f, 0.548f, 0.859f, 1.0f), 81 | vec4(0.014f, 0.184f, 0.576f, 1.0f), vec4(0.771f, 0.328f, 0.970f, 1.0f), vec4(0.406f, 0.615f, 0.116f, 1.0f), 82 | vec4(0.676f, 0.977f, 0.133f, 1.0f), vec4(0.971f, 0.572f, 0.833f, 1.0f), vec4(0.140f, 0.616f, 0.489f, 1.0f), 83 | vec4(0.997f, 0.513f, 0.064f, 1.0f), vec4(0.945f, 0.719f, 0.592f, 1.0f), vec4(0.543f, 0.021f, 0.978f, 1.0f), 84 | vec4(0.279f, 0.317f, 0.505f, 1.0f), vec4(0.167f, 0.620f, 0.077f, 1.0f), vec4(0.347f, 0.857f, 0.137f, 1.0f), 85 | vec4(0.055f, 0.953f, 0.042f, 1.0f), vec4(0.714f, 0.505f, 0.345f, 1.0f), vec4(0.783f, 0.290f, 0.734f, 1.0f), 86 | vec4(0.722f, 0.645f, 0.174f, 1.0f), vec4(0.302f, 0.455f, 0.848f, 1.0f), vec4(0.225f, 0.587f, 0.040f, 1.0f), 87 | vec4(0.517f, 0.713f, 0.338f, 1.0f), vec4(0.053f, 0.959f, 0.120f, 1.0f), vec4(0.393f, 0.621f, 0.362f, 1.0f), 88 | vec4(0.673f, 0.211f, 0.457f, 1.0f), vec4(0.820f, 0.883f, 0.371f, 1.0f), vec4(0.982f, 0.099f, 0.879, 1.0f) 89 | }; 90 | 91 | mPositionData = gl::Vbo::create(GL_ARRAY_BUFFER, cVertices, GL_STATIC_DRAW); 92 | mPositionLayout.append(geom::Attrib::POSITION, geom::DataType::FLOAT, 3, sizeof(vec3), 0); 93 | 94 | mColorData = gl::Vbo::create(GL_ARRAY_BUFFER, cColors, GL_STATIC_DRAW); 95 | mColorLayout.append(geom::Attrib::COLOR, geom::DataType::FLOAT, 4, sizeof(vec4), 0); 96 | 97 | mCubeMesh = gl::VboMesh::create(6*6, GL_TRIANGLES, { { mPositionLayout, mPositionData }, { mColorLayout, mColorData } }); 98 | mBatch = gl::Batch::create(mCubeMesh, mGlsl); 99 | } 100 | 101 | void Lesson03App::update() 102 | { 103 | } 104 | 105 | void Lesson03App::draw() 106 | { 107 | gl::clear(Color(0, 0, 0.15f)); 108 | gl::setMatrices(mCamera); 109 | mBatch->draw(); 110 | } 111 | 112 | CINDER_APP( Lesson03App, RendererGl ) 113 | -------------------------------------------------------------------------------- /Lesson03/vc2013/Lesson03.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lesson03", "Lesson03.vcxproj", "{6E2BFFFA-126D-4434-86A8-CF5BD39B3022}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {6E2BFFFA-126D-4434-86A8-CF5BD39B3022}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {6E2BFFFA-126D-4434-86A8-CF5BD39B3022}.Debug|Win32.Build.0 = Debug|Win32 14 | {6E2BFFFA-126D-4434-86A8-CF5BD39B3022}.Release|Win32.ActiveCfg = Release|Win32 15 | {6E2BFFFA-126D-4434-86A8-CF5BD39B3022}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Lesson03/vc2013/Lesson03.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {6E2BFFFA-126D-4434-86A8-CF5BD39B3022} 15 | Lesson03 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Lesson03/vc2013/Lesson03.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {0bc6df72-4e06-4433-8311-a79d2dce7e92} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /Lesson03/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /Lesson04/assets/simple_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | uniform sampler2D texRgb; 3 | 4 | in vec4 Color; 5 | in vec2 TexCoord; 6 | 7 | out vec4 oColor; 8 | 9 | 10 | void main() 11 | { 12 | oColor = texture2D(texRgb, TexCoord); 13 | oColor *= Color; 14 | } -------------------------------------------------------------------------------- /Lesson04/assets/simple_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; 6 | in vec2 ciTexCoord0; 7 | in vec4 ciColor; 8 | 9 | out highp vec2 TexCoord; 10 | out lowp vec4 Color; 11 | 12 | void main( void ) 13 | { 14 | gl_Position = ciModelViewProjection * ciPosition; 15 | Color = ciColor; 16 | TexCoord = ciTexCoord0; 17 | } -------------------------------------------------------------------------------- /Lesson04/assets/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson04/assets/texture.png -------------------------------------------------------------------------------- /Lesson04/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson04/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson04/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /Lesson04/src/Lesson04App.cpp: -------------------------------------------------------------------------------- 1 | /* Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 2 | 3 | Lesson 04a: Texturing 4 | Original Tutorial: 5 | http://www.opengl-tutorial.org/beginners-tutorials/tutorial-5-a-textured-cube/ 6 | 7 | Let's apply a texture to a primitive. For simplicity's sake, we'll use a plane instead of a cube, and 8 | we'll use multiple VBOs. Next tutorial we'll look at using structs to pass multiple attribute datasets 9 | to the VBO. 10 | */ 11 | 12 | #include "cinder/app/App.h" 13 | #include "cinder/app/RendererGl.h" 14 | #include "cinder/Camera.h" 15 | #include "cinder/gl/Batch.h" 16 | #include "cinder/gl/GlslProg.h" 17 | #include "cinder/gl/Texture.h" 18 | #include "cinder/ImageIo.h" 19 | 20 | using namespace ci; 21 | using namespace ci::app; 22 | using namespace std; 23 | 24 | class Lesson04App : public App { 25 | public: 26 | void setup() override; 27 | void update() override; 28 | void draw() override; 29 | 30 | 31 | gl::GlslProgRef mGlsl; 32 | gl::VboRef mPositionData, mColorData, mUVData; 33 | geom::BufferLayout mPositionLayout, mColorLayout, mUVLayout; 34 | gl::VboMeshRef mMesh; 35 | gl::BatchRef mBatch; 36 | gl::Texture2dRef mTexture; 37 | CameraPersp mCamera; 38 | }; 39 | 40 | void Lesson04App::setup() 41 | { 42 | getWindow()->setSize(1024, 768); 43 | 44 | mTexture = gl::Texture2d::create(loadImage(loadAsset("texture.png"))); 45 | try 46 | { 47 | mGlsl = gl::GlslProg::create(loadAsset("simple_vert.glsl"), loadAsset("simple_frag.glsl")); 48 | } 49 | catch (const gl::GlslProgExc &e) 50 | { 51 | console() << "Error loading shaders:" << endl; 52 | console() << e.what() << endl; 53 | quit(); 54 | } 55 | 56 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 57 | mCamera.lookAt(vec3(0, -3, 3), vec3(0), vec3(0, 1, 0)); 58 | 59 | vector cVertices = 60 | { 61 | vec3(1.0f, 1.0f, 0.0f), vec3(-1.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), 62 | vec3(1.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), 63 | }; 64 | 65 | vector cColors = 66 | { 67 | vec4(0.583f, 0.771f, 0.014f, 1.0f), vec4(0.609f, 0.115f, 0.436f, 1.0f), vec4(0.327f, 0.483f, 0.844f, 1.0f), 68 | vec4(0.822f, 0.569f, 0.201f, 1.0f), vec4(0.435f, 0.602f, 0.223f, 1.0f), vec4(0.310f, 0.747f, 0.185f, 1.0f), 69 | }; 70 | 71 | vector cUVs = 72 | { 73 | vec2(1.0,1.0), vec2(0.0,1.0), vec2(0.0,0.0), 74 | vec2(1.0,1.0), vec2(0.0,0.0), vec2(1.0,0.0) 75 | }; 76 | 77 | mPositionData = gl::Vbo::create(GL_ARRAY_BUFFER, cVertices, GL_STATIC_DRAW); 78 | mPositionLayout.append(geom::Attrib::POSITION, geom::DataType::FLOAT, 3, 0, 0); 79 | 80 | mColorData = gl::Vbo::create(GL_ARRAY_BUFFER, cColors, GL_STATIC_DRAW); 81 | mColorLayout.append(geom::Attrib::COLOR, geom::DataType::FLOAT, 4, 0, 0); 82 | 83 | mUVData = gl::Vbo::create(GL_ARRAY_BUFFER, cUVs, GL_STATIC_DRAW); 84 | mUVLayout.append(geom::Attrib::TEX_COORD_0, geom::DataType::FLOAT, 2, 0, 0); 85 | 86 | mMesh = gl::VboMesh::create(6, GL_TRIANGLES, { { mPositionLayout, mPositionData }, { mColorLayout, mColorData }, {mUVLayout, mUVData} }); 87 | mBatch = gl::Batch::create(mMesh, mGlsl); 88 | } 89 | 90 | void Lesson04App::update() 91 | { 92 | } 93 | 94 | void Lesson04App::draw() 95 | { 96 | gl::enableDepthRead(); 97 | gl::enableDepthWrite(); 98 | 99 | gl::clear(Color(0.1f, 0.15f, 0.25f)); 100 | gl::setMatrices(mCamera); 101 | 102 | mTexture->bind(0); 103 | mBatch->draw(); 104 | mTexture->unbind(); 105 | } 106 | 107 | CINDER_APP( Lesson04App, RendererGl ) 108 | -------------------------------------------------------------------------------- /Lesson04/vc2013/Lesson04.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lesson04", "Lesson04.vcxproj", "{4B421800-72CF-4B23-9F4F-209BB6F59218}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {4B421800-72CF-4B23-9F4F-209BB6F59218}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {4B421800-72CF-4B23-9F4F-209BB6F59218}.Debug|Win32.Build.0 = Debug|Win32 14 | {4B421800-72CF-4B23-9F4F-209BB6F59218}.Release|Win32.ActiveCfg = Release|Win32 15 | {4B421800-72CF-4B23-9F4F-209BB6F59218}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Lesson04/vc2013/Lesson04.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {4B421800-72CF-4B23-9F4F-209BB6F59218} 15 | Lesson04 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Lesson04/vc2013/Lesson04.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {bb5d1f56-b9a2-4b6b-97b8-f737aa287dca} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /Lesson04/vc2013/Lesson04.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Lesson04/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /Lesson04b/assets/simple_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform sampler2D texRgb; 4 | 5 | in vec4 Color; 6 | in vec2 TexCoord; 7 | 8 | out vec4 oColor; 9 | 10 | 11 | void main() 12 | { 13 | oColor = texture2D(texRgb, TexCoord); 14 | oColor *= Color; 15 | } -------------------------------------------------------------------------------- /Lesson04b/assets/simple_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; 6 | in vec2 ciTexCoord0; 7 | in vec4 ciColor; 8 | 9 | out highp vec2 TexCoord; 10 | out lowp vec4 Color; 11 | 12 | void main( void ) 13 | { 14 | gl_Position = ciModelViewProjection * ciPosition; 15 | Color = ciColor; 16 | TexCoord = ciTexCoord0; 17 | } -------------------------------------------------------------------------------- /Lesson04b/assets/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson04b/assets/texture.png -------------------------------------------------------------------------------- /Lesson04b/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson04b/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson04b/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /Lesson04b/src/Lesson04bApp.cpp: -------------------------------------------------------------------------------- 1 | /* Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 2 | 3 | Lesson 04b: Texturing Part II 4 | Original Tutorial: 5 | This one's a bonus and uses some more pure Cinder functionality. 6 | 7 | In this tutorial, we'll take a look at using custom datatypes to pass data to a VBO so we can 8 | use a single VBO for all of our vertex data. 9 | */ 10 | 11 | #include "cinder/app/App.h" 12 | #include "cinder/app/RendererGl.h" 13 | #include "cinder/Camera.h" 14 | #include "cinder/gl/Batch.h" 15 | #include "cinder/gl/GlslProg.h" 16 | #include "cinder/gl/Texture.h" 17 | #include "cinder/gl/scoped.h" 18 | #include "cinder/ImageIo.h" 19 | 20 | using namespace ci; 21 | using namespace ci::app; 22 | using namespace std; 23 | 24 | class Lesson04bApp : public App 25 | { 26 | public: 27 | void setup() override; 28 | void update() override; 29 | void draw() override; 30 | 31 | struct CioVertex 32 | { 33 | vec3 vPosition; 34 | vec4 vColor; 35 | vec2 vUV; 36 | 37 | CioVertex(vec3 pPos, vec4 pColor, vec2 pUV) : vPosition(pPos), vColor(pColor), vUV(pUV){} 38 | }; 39 | 40 | gl::GlslProgRef mGlsl; 41 | gl::VboRef mVertexData; 42 | geom::BufferLayout mVertexLayout; 43 | gl::VboMeshRef mMesh; 44 | gl::BatchRef mBatch; 45 | gl::Texture2dRef mTexture; 46 | CameraPersp mCamera; 47 | }; 48 | 49 | void Lesson04bApp::setup() 50 | { 51 | getWindow()->setSize(1024, 768); 52 | 53 | mTexture = gl::Texture2d::create(loadImage(loadAsset("texture.png"))); 54 | try 55 | { 56 | mGlsl = gl::GlslProg::create(loadAsset("simple_vert.glsl"), loadAsset("simple_frag.glsl")); 57 | } 58 | catch (const gl::GlslProgExc &e) 59 | { 60 | console() << "Error loading shaders:" << endl; 61 | console() << e.what() << endl; 62 | quit(); 63 | } 64 | 65 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 66 | mCamera.lookAt(vec3(0, -3, 3), vec3(0), vec3(0, 1, 0)); 67 | 68 | vector cVertList = 69 | { 70 | CioVertex(vec3(1.0f, 1.0f, 0.0f), vec4(0.583f, 0.771f, 0.014f, 1.0f), vec2(1.0, 1.0)), 71 | CioVertex(vec3(-1.0f, 1.0f, 0.0f), vec4(0.609f, 0.115f, 0.436f, 1.0f), vec2(0.0, 1.0)), 72 | CioVertex(vec3(-1.0f, -1.0f, 0.0f), vec4(0.327f, 0.483f, 0.844f, 1.0f), vec2(0.0, 0.0)), 73 | CioVertex(vec3(1.0f, 1.0f, 0.0f), vec4(0.822f, 0.569f, 0.201f, 1.0f), vec2(1.0, 1.0)), 74 | CioVertex(vec3(-1.0f, -1.0f, 0.0f), vec4(0.435f, 0.602f, 0.223f, 1.0f), vec2(0.0, 0.0)), 75 | CioVertex(vec3(1.0f, -1.0f, 0.0f), vec4(0.310f, 0.747f, 0.185f, 1.0f), vec2(1.0, 0.0)) 76 | }; 77 | 78 | mVertexData = gl::Vbo::create(GL_ARRAY_BUFFER, cVertList, GL_STATIC_DRAW); 79 | mVertexLayout.append(geom::Attrib::POSITION, 3, sizeof(CioVertex), offsetof(CioVertex, vPosition)); 80 | mVertexLayout.append(geom::Attrib::COLOR, 4, sizeof(CioVertex), offsetof(CioVertex, vColor)); 81 | mVertexLayout.append(geom::Attrib::TEX_COORD_0, 2, sizeof(CioVertex), offsetof(CioVertex, vUV)); 82 | 83 | mMesh = gl::VboMesh::create(6, GL_TRIANGLES, { { mVertexLayout, mVertexData }}); 84 | mBatch = gl::Batch::create(mMesh, mGlsl); 85 | } 86 | 87 | void Lesson04bApp::update() 88 | { 89 | } 90 | 91 | void Lesson04bApp::draw() 92 | { 93 | gl::enableDepthRead(); 94 | gl::enableDepthWrite(); 95 | 96 | gl::clear(Color(0.1f, 0.15f, 0.25f)); 97 | gl::setMatrices(mCamera); 98 | 99 | gl::ScopedTextureBind cTexture(mTexture); 100 | mBatch->draw(); 101 | } 102 | 103 | CINDER_APP(Lesson04bApp, RendererGl) 104 | -------------------------------------------------------------------------------- /Lesson04b/vc2013/Lesson04b.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lesson04b", "Lesson04b.vcxproj", "{099BBDBC-9375-4B26-B100-631A0EEB62D1}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {099BBDBC-9375-4B26-B100-631A0EEB62D1}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {099BBDBC-9375-4B26-B100-631A0EEB62D1}.Debug|Win32.Build.0 = Debug|Win32 14 | {099BBDBC-9375-4B26-B100-631A0EEB62D1}.Release|Win32.ActiveCfg = Release|Win32 15 | {099BBDBC-9375-4B26-B100-631A0EEB62D1}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Lesson04b/vc2013/Lesson04b.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {099BBDBC-9375-4B26-B100-631A0EEB62D1} 15 | Lesson04b 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Lesson04b/vc2013/Lesson04b.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {e47d79d0-52f8-4349-87c4-30f7c18dc673} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /Lesson04b/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /Lesson05/assets/simple_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform sampler2D texRGB; 4 | in vec4 Color; 5 | in vec2 TexCoord; 6 | out vec4 oColor; 7 | 8 | 9 | void main() 10 | { 11 | oColor = texture2D(texRGB, TexCoord); 12 | oColor *= Color; 13 | } -------------------------------------------------------------------------------- /Lesson05/assets/simple_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; 6 | in vec2 ciTexCoord0; 7 | in vec4 ciColor; 8 | 9 | out highp vec2 TexCoord; 10 | out lowp vec4 Color; 11 | 12 | void main( void ) 13 | { 14 | gl_Position = ciModelViewProjection * ciPosition; 15 | Color = ciColor; 16 | TexCoord = ciTexCoord0; 17 | } -------------------------------------------------------------------------------- /Lesson05/assets/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson05/assets/texture.png -------------------------------------------------------------------------------- /Lesson05/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson05/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/Lesson05/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /Lesson05/src/Lesson05App.cpp: -------------------------------------------------------------------------------- 1 | /* Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 2 | 3 | Lesson 05: Simple camera and mouse input 4 | Original Tutorial: 5 | Well, actually this one only follows opengl-tutorial.org in topic. 6 | 7 | Let's set up Cinder's MayaCamUI to get some simple mouse interaction 8 | */ 9 | 10 | #include "cinder/app/App.h" 11 | #include "cinder/app/RendererGl.h" 12 | #include "cinder/Camera.h" 13 | #include "cinder/gl/Batch.h" 14 | #include "cinder/gl/GlslProg.h" 15 | #include "cinder/gl/scoped.h" 16 | #include "cinder/gl/Texture.h" 17 | #include "cinder/ImageIo.h" 18 | #include "cinder/CameraUi.h" 19 | 20 | using namespace ci; 21 | using namespace ci::app; 22 | using namespace std; 23 | 24 | class Lesson05App : public App { 25 | public: 26 | void setup() override; 27 | void update() override; 28 | void draw() override; 29 | void mouseDown(MouseEvent pEvent) override; 30 | void mouseDrag(MouseEvent pEvent) override; 31 | 32 | struct CioVertex 33 | { 34 | vec3 vPosition; 35 | vec4 vColor; 36 | vec2 vUV; 37 | 38 | CioVertex(vec3 pPos, vec4 pColor, vec2 pUV) : vPosition(pPos), vColor(pColor), vUV(pUV){} 39 | }; 40 | 41 | gl::GlslProgRef mGlsl; 42 | gl::VboRef mVertexData; 43 | geom::BufferLayout mVertexLayout; 44 | gl::VboMeshRef mMesh; 45 | gl::BatchRef mBatch; 46 | gl::Texture2dRef mTexture; 47 | 48 | CameraPersp mCamera; 49 | CameraUi mCamUi; 50 | }; 51 | 52 | void Lesson05App::setup() 53 | { 54 | getWindow()->setSize(1024, 768); 55 | 56 | mTexture = gl::Texture2d::create(loadImage(loadAsset("texture.png"))); 57 | try 58 | { 59 | mGlsl = gl::GlslProg::create(loadAsset("simple_vert.glsl"), loadAsset("simple_frag.glsl")); 60 | } 61 | catch (const gl::GlslProgExc &e) 62 | { 63 | console() << "Error loading shaders:" << endl; 64 | console() << e.what() << endl; 65 | quit(); 66 | } 67 | 68 | vector cVertList = 69 | { 70 | CioVertex(vec3(1.0f, 1.0f, 0.0f), vec4(0.583f, 0.771f, 0.014f, 1.0f), vec2(1.0, 1.0)), 71 | CioVertex(vec3(-1.0f, 1.0f, 0.0f), vec4(0.609f, 0.115f, 0.436f, 1.0f), vec2(0.0, 1.0)), 72 | CioVertex(vec3(-1.0f, -1.0f, 0.0f), vec4(0.327f, 0.483f, 0.844f, 1.0f), vec2(0.0, 0.0)), 73 | CioVertex(vec3(1.0f, 1.0f, 0.0f), vec4(0.822f, 0.569f, 0.201f, 1.0f), vec2(1.0, 1.0)), 74 | CioVertex(vec3(-1.0f, -1.0f, 0.0f), vec4(0.435f, 0.602f, 0.223f, 1.0f), vec2(0.0, 0.0)), 75 | CioVertex(vec3(1.0f, -1.0f, 0.0f), vec4(0.310f, 0.747f, 0.185f, 1.0f), vec2(1.0, 0.0)) 76 | }; 77 | 78 | mVertexData = gl::Vbo::create(GL_ARRAY_BUFFER, cVertList, GL_STATIC_DRAW); 79 | mVertexLayout.append(geom::Attrib::POSITION, 3, sizeof(CioVertex), offsetof(CioVertex, vPosition)); 80 | mVertexLayout.append(geom::Attrib::COLOR, 4, sizeof(CioVertex), offsetof(CioVertex, vColor)); 81 | mVertexLayout.append(geom::Attrib::TEX_COORD_0, 2, sizeof(CioVertex), offsetof(CioVertex, vUV)); 82 | 83 | mMesh = gl::VboMesh::create(6, GL_TRIANGLES, { { mVertexLayout, mVertexData } }); 84 | mBatch = gl::Batch::create(mMesh, mGlsl); 85 | 86 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 87 | 88 | vec3 cEyePos(0, -3, 3); 89 | float cPivotDist = glm::length(cEyePos); 90 | mCamera.lookAt(cEyePos, vec3(0), vec3(0, 1, 0)); 91 | mCamera.setPivotDistance(cPivotDist); 92 | mCamUi = CameraUi(&mCamera, getWindow()); 93 | } 94 | 95 | void Lesson05App::mouseDown(MouseEvent pEvent) 96 | { 97 | 98 | } 99 | 100 | void Lesson05App::mouseDrag(MouseEvent pEvent) 101 | { 102 | } 103 | 104 | void Lesson05App::update() 105 | { 106 | } 107 | 108 | void Lesson05App::draw() 109 | { 110 | gl::enableDepthRead(); 111 | gl::enableDepthWrite(); 112 | 113 | gl::clear(Color(0.1f, 0.15f, 0.25f)); 114 | gl::setMatrices(mCamera); 115 | 116 | gl::ScopedTextureBind cTexture(mTexture); 117 | mBatch->draw(); 118 | } 119 | 120 | CINDER_APP( Lesson05App, RendererGl ) 121 | -------------------------------------------------------------------------------- /Lesson05/vc2013/Lesson05.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lesson05", "Lesson05.vcxproj", "{A848BC9B-0E64-4621-BFD6-88DF13DB1A59}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A848BC9B-0E64-4621-BFD6-88DF13DB1A59}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A848BC9B-0E64-4621-BFD6-88DF13DB1A59}.Debug|Win32.Build.0 = Debug|Win32 14 | {A848BC9B-0E64-4621-BFD6-88DF13DB1A59}.Release|Win32.ActiveCfg = Release|Win32 15 | {A848BC9B-0E64-4621-BFD6-88DF13DB1A59}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Lesson05/vc2013/Lesson05.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {A848BC9B-0E64-4621-BFD6-88DF13DB1A59} 15 | Lesson05 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Lesson05/vc2013/Lesson05.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {3d4c4784-bce3-437f-9320-620fb00f0297} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /Lesson05/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonBillboards/assets/billboard_frag.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D u_SamplerRGB; 2 | 3 | in vec2 UV; 4 | out vec4 o_Color; 5 | 6 | void main() 7 | { 8 | //Nothing special to see here 9 | o_Color = texture2D(u_SamplerRGB, UV); 10 | } -------------------------------------------------------------------------------- /LessonBillboards/assets/billboard_vert.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 ciModelViewProjection; //model-view-projection matrix for final transform 2 | uniform vec3 u_CameraUp; //camera up vector (from the app) 3 | uniform vec3 u_CameraRight; //camera right vector (from the app) 4 | 5 | in vec4 ciPosition; //per-instance mesh vertex position 6 | in vec2 ciTexCoord0; 7 | 8 | in vec3 i_Position; //per-instance mesh position 9 | 10 | out vec2 UV; 11 | 12 | void main() 13 | { 14 | 15 | UV = ciTexCoord0; 16 | 17 | //here we short cut a matrix transformation to get the billboarding effect 18 | //matrix * vector is basically column * vector_component, so this should 19 | //make sense: 20 | vec3 mBillboard = i_Position + u_CameraRight*ciPosition.x*0.75 + u_CameraUp*ciPosition.y*0.75; 21 | 22 | //and now we transform the billboarded position into clip-space 23 | gl_Position = ciModelViewProjection * vec4(mBillboard, 1.0); 24 | 25 | } -------------------------------------------------------------------------------- /LessonBillboards/assets/tex_petal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonBillboards/assets/tex_petal.png -------------------------------------------------------------------------------- /LessonBillboards/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonBillboards/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonBillboards/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonBillboards/src/LessonBillboardsApp.cpp: -------------------------------------------------------------------------------- 1 | #include "cinder/app/App.h" 2 | #include "cinder/gl/gl.h" 3 | #include "cinder/app/RendererGl.h" 4 | #include "cinder/gl/GlslProg.h" 5 | #include "cinder/gl/Batch.h" 6 | #include "cinder/gl/Texture.h" 7 | #include "cinder/Camera.h" 8 | #include "cinder/CameraUi.h" 9 | #include "cinder/Rand.h" 10 | 11 | using namespace ci; 12 | using namespace ci::app; 13 | using namespace std; 14 | 15 | class LessonBillboardsApp : public App 16 | { 17 | public: 18 | void setup(); 19 | void mouseDown(MouseEvent event); 20 | void update(); 21 | void draw(); 22 | 23 | private: 24 | gl::BatchRef mBatch; 25 | gl::VboRef mInstanceData; 26 | geom::BufferLayout mInstanceAttribs; 27 | 28 | gl::VboMeshRef mBillboardMesh; 29 | gl::GlslProgRef mShader; 30 | 31 | gl::Texture2dRef mTexRgb; 32 | 33 | CameraPersp mCamera; 34 | CameraUi mCamUI; 35 | }; 36 | 37 | void LessonBillboardsApp::setup() 38 | { 39 | vector cPositions; 40 | 41 | //Let's create a bunch of positions for our flower petals 42 | //standard vbo instancing here 43 | for (int i = 0; i < 1000; ++i) 44 | { 45 | cPositions.push_back(vec3(randFloat(-10.f, 10.f), randFloat(-10.f, 10.f), randFloat(-10.f, 10.f))); 46 | } 47 | 48 | mShader = gl::GlslProg::create(loadAsset("billboard_vert.glsl"), loadAsset("billboard_frag.glsl")); 49 | 50 | mInstanceData = gl::Vbo::create(GL_ARRAY_BUFFER, cPositions, GL_STATIC_DRAW); 51 | mInstanceAttribs.append(geom::Attrib::CUSTOM_0, 3, 0, 0, 1); 52 | mBillboardMesh = gl::VboMesh::create(geom::Plane().axes(vec3(0, 1, 0), vec3(1, 0, 0)).size(vec2(1))); 53 | mBillboardMesh->appendVbo(mInstanceAttribs, mInstanceData); 54 | mBatch = gl::Batch::create(mBillboardMesh, mShader, { { geom::CUSTOM_0, "i_Position" } }); 55 | 56 | //make sure our texture file lives in the assets directory 57 | //this is a 256x256 png with an alpha channel 58 | mTexRgb = gl::Texture2d::create(loadImage(loadAsset("tex_petal.png"))); 59 | 60 | gl::disable(GL_DEPTH_TEST); 61 | gl::disableDepthWrite(); 62 | gl::enableAlphaBlending(); 63 | 64 | getWindow()->setSize(1280, 720); 65 | setFrameRate(60); 66 | 67 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 68 | mCamera.setEyePoint(vec3(0, 0, -40)); 69 | mCamera.setViewDirection(vec3(0, 0, 1)); 70 | mCamera.setPivotDistance(40); 71 | mCamUI = CameraUi(&mCamera, getWindow(), 0); 72 | } 73 | 74 | void LessonBillboardsApp::mouseDown(MouseEvent event) 75 | { 76 | } 77 | 78 | void LessonBillboardsApp::update() 79 | { 80 | } 81 | 82 | void LessonBillboardsApp::draw() 83 | { 84 | // clear out the window with black 85 | gl::clear(Color(0, 0, 0)); 86 | gl::color(Color::white()); 87 | vec3 cCameraRight, cCameraUp; 88 | 89 | /* 90 | Billboarding in theory is pretty simple: 91 | We need to know what the camera's up and right vectors are, which Cinder gives us 92 | Once we have those, we transform the instance mesh's vertex positions by those vectors 93 | so the mesh is ALWAYS facing the camera (see billboard_vert.glsl for more comments) 94 | */ 95 | mCamUI.getCamera().getBillboardVectors(&cCameraRight, &cCameraUp); 96 | 97 | //Now we pass in the camera vectors as shader uniforms 98 | mBatch->getGlslProg()->uniform("u_CameraUp", cCameraUp); 99 | mBatch->getGlslProg()->uniform("u_CameraRight", cCameraRight); 100 | mBatch->getGlslProg()->uniform("u_SamplerRGB", 0); 101 | mTexRgb->bind(); 102 | 103 | //Then we draw our instances as usual 104 | gl::setMatrices(mCamUI.getCamera()); 105 | mBatch->drawInstanced(1000); 106 | mTexRgb->unbind(); 107 | 108 | //and let's draw some debug stuff just for fun 109 | gl::drawStrokedCube(vec3(0), vec3(20)); 110 | gl::color(Color(1, 0, 0)); 111 | gl::drawLine(vec3(0), vec3(3, 0, 0)); 112 | gl::color(Color(0, 1, 0)); 113 | gl::drawLine(vec3(0), vec3(0, 3, 0)); 114 | gl::color(Color(0, 0, 1)); 115 | gl::drawLine(vec3(0), vec3(0, 0, 3)); 116 | 117 | } 118 | 119 | CINDER_APP(LessonBillboardsApp, RendererGl) -------------------------------------------------------------------------------- /LessonBillboards/vc2013/LessonBillboards.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonBillboards", "LessonBillboards.vcxproj", "{EA2C3760-6777-4658-AEB9-129E94740021}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {EA2C3760-6777-4658-AEB9-129E94740021}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {EA2C3760-6777-4658-AEB9-129E94740021}.Debug|Win32.Build.0 = Debug|Win32 14 | {EA2C3760-6777-4658-AEB9-129E94740021}.Release|Win32.ActiveCfg = Release|Win32 15 | {EA2C3760-6777-4658-AEB9-129E94740021}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonBillboards/vc2013/LessonBillboards.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {EA2C3760-6777-4658-AEB9-129E94740021} 15 | LessonBillboards 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;$(CINDER_DEV)\include;$(CINDER_DEV)\boost 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | Level3 61 | ProgramDatabase 62 | true 63 | 64 | 65 | "$(CINDER_DEV)\include";..\include 66 | 67 | 68 | cinder-$(PlatformToolset)_d.lib;OpenGL32.lib;%(AdditionalDependencies) 69 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 70 | true 71 | Windows 72 | false 73 | 74 | LIBCMT;LIBCPMT 75 | 76 | 77 | 78 | 79 | ..\include;$(CINDER_DEV)\include;$(CINDER_DEV)\boost 80 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 81 | MultiThreaded 82 | 83 | Level3 84 | ProgramDatabase 85 | true 86 | 87 | 88 | true 89 | 90 | 91 | "$(CINDER_DEV)\include";..\include 92 | 93 | 94 | cinder-$(PlatformToolset).lib;OpenGL32.lib;%(AdditionalDependencies) 95 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 96 | false 97 | true 98 | Windows 99 | true 100 | 101 | false 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /LessonBillboards/vc2013/LessonBillboards.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {eb68d062-f76d-4566-b9a1-3df12ece3841} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /LessonBillboards/vc2013/LessonBillboards.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LessonBillboards/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonIndexedVBO/assets/index_vbo_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | out vec4 oColor; 4 | 5 | void main() 6 | { 7 | oColor = vec4(1.0,0.1,0.1,1.0); 8 | } -------------------------------------------------------------------------------- /LessonIndexedVBO/assets/index_vbo_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main( void ) 7 | { 8 | gl_Position = ciModelViewProjection * ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonIndexedVBO/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonIndexedVBO/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonIndexedVBO/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonIndexedVBO/src/LessonIndexedVBOApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 3 | 4 | Index VBOs: Drawing a VBO Mesh using an index buffer to re-use vertex positions 5 | Reference: 6 | http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/ 7 | */ 8 | #include "cinder/app/App.h" 9 | #include "cinder/app/RendererGl.h" 10 | #include "cinder/Camera.h" 11 | #include "cinder/GeomIo.h" 12 | #include "cinder/gl/gl.h" 13 | #include "cinder/gl/Batch.h" 14 | #include "cinder/gl/GlslProg.h" 15 | 16 | using namespace ci; 17 | using namespace ci::app; 18 | using namespace std; 19 | 20 | class LessonIndexedVBOApp : public App 21 | { 22 | public: 23 | void setup() override; 24 | void mouseDown(MouseEvent event) override; 25 | void update() override; 26 | void draw() override; 27 | 28 | gl::VboRef mPositionData, mIndexData; 29 | gl::VboMeshRef mVboMesh; 30 | geom::BufferLayout mPositionLayout, mIndexLayout; 31 | gl::BatchRef mBatch; 32 | gl::GlslProgRef mGlsl; 33 | 34 | CameraPersp mCamera; 35 | }; 36 | 37 | void LessonIndexedVBOApp::setup() 38 | { 39 | try 40 | { 41 | mGlsl = gl::GlslProg::create(loadAsset("index_vbo_vert.glsl"), loadAsset("index_vbo_frag.glsl")); 42 | } 43 | catch (const gl::GlslProgExc &e) 44 | { 45 | console() << "Error loading shader:" << endl; 46 | console() << e.what() << endl; 47 | quit(); 48 | } 49 | vector cVerts = 50 | { 51 | vec3(-1.0, -1.0, 0.0), vec3(-1.0, 1.0, 0.0), vec3(1.0, 1.0, 0.0), vec3(1.0, -1.0, 0.0) 52 | }; 53 | 54 | vector cIndices = 55 | { 56 | 0, 2, 1, 0, 3, 2 57 | }; 58 | 59 | mPositionData = gl::Vbo::create(GL_ARRAY_BUFFER, cVerts, GL_STATIC_DRAW); 60 | mPositionLayout.append(geom::Attrib::POSITION, 3, 0, 0, 0); 61 | 62 | mIndexData = gl::Vbo::create(GL_ELEMENT_ARRAY_BUFFER, cIndices, GL_STATIC_DRAW); 63 | mVboMesh = gl::VboMesh::create(cIndices.size(), GL_TRIANGLES, { { mPositionLayout, mPositionData } }, cIndices.size(), GL_UNSIGNED_SHORT, mIndexData); 64 | 65 | mBatch = gl::Batch::create(mVboMesh, mGlsl); 66 | 67 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 68 | mCamera.lookAt(vec3(3, 3, 3), vec3(0), vec3(0, 1, 0)); 69 | } 70 | 71 | void LessonIndexedVBOApp::mouseDown(MouseEvent event) 72 | { 73 | 74 | } 75 | 76 | void LessonIndexedVBOApp::update() 77 | { 78 | 79 | } 80 | 81 | void LessonIndexedVBOApp::draw() 82 | { 83 | gl::clear(Color(0.1f, 0.15f, 0.25f)); 84 | gl::setMatrices(mCamera); 85 | mBatch->draw(); 86 | } 87 | 88 | CINDER_APP(LessonIndexedVBOApp, RendererGl) 89 | -------------------------------------------------------------------------------- /LessonIndexedVBO/vc2013/LessonIndexedVBO.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonIndexedVBO", "LessonIndexedVBO.vcxproj", "{B50969AF-F299-4825-A29A-3F921A5CC2F5}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {B50969AF-F299-4825-A29A-3F921A5CC2F5}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {B50969AF-F299-4825-A29A-3F921A5CC2F5}.Debug|Win32.Build.0 = Debug|Win32 14 | {B50969AF-F299-4825-A29A-3F921A5CC2F5}.Release|Win32.ActiveCfg = Release|Win32 15 | {B50969AF-F299-4825-A29A-3F921A5CC2F5}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonIndexedVBO/vc2013/LessonIndexedVBO.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {B50969AF-F299-4825-A29A-3F921A5CC2F5} 15 | LessonIndexedVBO 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /LessonIndexedVBO/vc2013/LessonIndexedVBO.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {94d3fbc9-d9b7-45ad-8560-856961543dd8} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /LessonIndexedVBO/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/assets/dyn_vbo_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 Color; 4 | out vec4 oColor; 5 | 6 | void main() 7 | { 8 | oColor = Color; 9 | } -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/assets/dyn_vbo_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | in vec4 ciColor; 6 | out vec4 Color; 7 | 8 | void main( void ) 9 | { 10 | gl_Position = ciModelViewProjection * ciPosition; 11 | Color = ciColor; 12 | } -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonIndexedVBODynamic/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/src/LessonIndexedVBODynamicApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 3 | 4 | Dynamic VBOs: Drawing a VBO Mesh with per-frame buffer data updates 5 | Reference: 6 | https://www.opengl.org/wiki/Buffer_Object_Streaming 7 | 8 | NOTE: This is not a complete implimentation of the techniques presented above 9 | This techinque DOES NOT work on some lower end hardware (Intel HD, for example) 10 | */ 11 | #include "cinder/app/App.h" 12 | #include "cinder/app/RendererGl.h" 13 | #include "cinder/Camera.h" 14 | #include "cinder/GeomIo.h" 15 | #include "cinder/gl/gl.h" 16 | #include "cinder/gl/Batch.h" 17 | #include "cinder/gl/GlslProg.h" 18 | #include "cinder/CameraUi.h" 19 | #include "cinder/Rand.h" 20 | 21 | using namespace ci; 22 | using namespace ci::app; 23 | using namespace std; 24 | 25 | class LessonIndexedVBODynamicApp : public App 26 | { 27 | public: 28 | void setup() override; 29 | void update() override; 30 | void draw() override; 31 | 32 | void populateBuffers(bool pInit=true); 33 | 34 | gl::VboRef mPositionData, mColorData, mIndexData; 35 | gl::VboMeshRef mVboMesh; 36 | geom::BufferLayout mPositionLayout, mColorLayout; 37 | gl::BatchRef mBatch; 38 | gl::GlslProgRef mGlsl; 39 | 40 | CameraPersp mCamera; 41 | CameraUi mCamUI; 42 | 43 | int mMaxX, mMaxY, mMaxVerts; 44 | vector mVerts; 45 | vector mColors; 46 | vector mIndices; 47 | }; 48 | 49 | void LessonIndexedVBODynamicApp::setup() 50 | { 51 | mMaxX = 200; 52 | mMaxY = 200; 53 | try 54 | { 55 | mGlsl = gl::GlslProg::create(loadAsset("dyn_vbo_vert.glsl"), loadAsset("dyn_vbo_frag.glsl")); 56 | } 57 | catch (const gl::GlslProgExc &e) 58 | { 59 | console() << "Error loading shader:" << endl; 60 | console() << e.what() << endl; 61 | quit(); 62 | } 63 | 64 | populateBuffers(true); 65 | mBatch = gl::Batch::create(mVboMesh, mGlsl); 66 | 67 | vec3 cEyePos = vec3(0, 0, 5); 68 | float cPivotDist = length(cEyePos); 69 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 70 | mCamera.lookAt(cEyePos, vec3(0), vec3(0, 1, 0)); 71 | mCamera.setPivotDistance(cPivotDist); 72 | mCamUI = CameraUi(&mCamera, getWindow()); 73 | 74 | getWindow()->setSize(640,360); 75 | setFrameRate(30); 76 | } 77 | 78 | void LessonIndexedVBODynamicApp::populateBuffers(bool pInit) 79 | { 80 | mVerts.clear(); 81 | mColors.clear(); 82 | mIndices.clear(); 83 | 84 | for (int vy = 0; vy < mMaxY; ++vy) 85 | { 86 | for (int vx = 0; vx < mMaxX; ++vx) 87 | { 88 | float cX = lmap(vx, 0, mMaxX - 1, 1.6f, -1.6f); 89 | float cY = lmap(vy, 0, mMaxY - 1, 0.9f, -0.9f); 90 | float cZ = math::sin(((vy+getElapsedSeconds()*0.1f)+(vx+getElapsedSeconds()*0.3f)))*0.1f; 91 | mVerts.push_back(vec3(cX, cY, cZ)); 92 | 93 | float cR = lmap(vx, 0, mMaxX - 1, 0.0f, 1.0f); 94 | float cG = lmap(vy, 0, mMaxY - 1, 0.0f, 1.0f); 95 | float cB = math::cos(getElapsedSeconds()); 96 | cB = (cB + 1.0f)*0.5f; 97 | mColors.push_back(vec4(cR, cG, cB, 1.0)); 98 | } 99 | } 100 | 101 | mMaxVerts = mVerts.size(); 102 | 103 | for (int cid = 0; cid < mMaxVerts; ++cid) 104 | { 105 | int n = cid; 106 | int n_1 = n + 1; 107 | int n_x = n + mMaxX; 108 | int n_x1 = n + mMaxX + 1; 109 | 110 | if ((n >= 0 && n < mMaxVerts) && 111 | (n_1 >= 0 && n_1 < mMaxVerts) && 112 | (n_x >= 0 && n_x < mMaxVerts)) 113 | { 114 | if (mVerts.at(n_1).x <= mVerts.at(n).x) 115 | { 116 | mIndices.push_back(n); 117 | mIndices.push_back(n_1); 118 | mIndices.push_back(n_x); 119 | } 120 | } 121 | 122 | if ((n_1 >= 0 && n_1 < mMaxVerts) && 123 | (n_x1 >= 0 && n_x1 < mMaxVerts) && 124 | (n_x >= 0 && n_x < mMaxVerts)) 125 | { 126 | if (mVerts.at(n_x1).x <= mVerts.at(n_x).x) 127 | { 128 | mIndices.push_back(n_1); 129 | mIndices.push_back(n_x1); 130 | mIndices.push_back(n_x); 131 | } 132 | } 133 | } 134 | 135 | if (pInit) 136 | { 137 | mPositionData = gl::Vbo::create(GL_ARRAY_BUFFER, mVerts.size()*sizeof(vec3), mVerts.data(), GL_DYNAMIC_DRAW); 138 | mPositionLayout.append(geom::Attrib::POSITION, 3, 0, 0); 139 | 140 | mColorData = gl::Vbo::create(GL_ARRAY_BUFFER, mColors.size()*sizeof(vec4), mColors.data(), GL_DYNAMIC_DRAW); 141 | mColorLayout.append(geom::Attrib::COLOR, 4, 0, 0); 142 | 143 | mIndexData = gl::Vbo::create(GL_ELEMENT_ARRAY_BUFFER, mIndices.size()*sizeof(uint32_t), mIndices.data(), GL_DYNAMIC_DRAW); 144 | } 145 | else 146 | { 147 | mPositionData->bufferData(mVerts.size()*sizeof(vec3), mVerts.data(), GL_DYNAMIC_DRAW); 148 | mColorData->bufferData(mColors.size()*sizeof(vec4), mColors.data(), GL_DYNAMIC_DRAW); 149 | mIndexData->bufferData(mIndices.size()*sizeof(uint32_t), mIndices.data(), GL_DYNAMIC_DRAW); 150 | } 151 | mVboMesh = gl::VboMesh::create(mVerts.size(), GL_TRIANGLES, { { mPositionLayout, mPositionData }, { mColorLayout, mColorData } }, mIndices.size(), GL_UNSIGNED_INT, mIndexData); 152 | if (!pInit) 153 | mBatch->replaceVboMesh(mVboMesh); 154 | } 155 | 156 | void LessonIndexedVBODynamicApp::update() 157 | { 158 | mMaxX = randInt(25, 100); 159 | mMaxY = randInt(25, 100); 160 | int r = mMaxX % 2; 161 | if (r > 0)mMaxX += r; 162 | r = mMaxY % 2; 163 | if (r > 0)mMaxY += r; 164 | 165 | populateBuffers(false); 166 | } 167 | 168 | void LessonIndexedVBODynamicApp::draw() 169 | { 170 | gl::clear(Color(0.1f, 0.15f, 0.25f)); 171 | gl::setMatrices(mCamera); 172 | mBatch->draw(); 173 | 174 | gl::setMatricesWindow(getWindowSize()); 175 | gl::drawString("Frames Per Second: " + to_string(getAverageFps()), vec2(10)); 176 | } 177 | 178 | CINDER_APP(LessonIndexedVBODynamicApp, RendererGl) 179 | -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/vc2013/LessonIndexedVBODynamic.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonIndexedVBODynamic", "LessonIndexedVBODynamic.vcxproj", "{A47B83ED-0369-4AD5-A144-C8C6A6C062DC}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A47B83ED-0369-4AD5-A144-C8C6A6C062DC}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A47B83ED-0369-4AD5-A144-C8C6A6C062DC}.Debug|Win32.Build.0 = Debug|Win32 14 | {A47B83ED-0369-4AD5-A144-C8C6A6C062DC}.Release|Win32.ActiveCfg = Release|Win32 15 | {A47B83ED-0369-4AD5-A144-C8C6A6C062DC}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/vc2013/LessonIndexedVBODynamic.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {49abb852-d42f-427c-85c2-67e7cd0c76ae} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /LessonIndexedVBODynamic/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonInstancing/assets/inst_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform sampler2D texRgb; 4 | in vec2 TexCoord; 5 | in vec4 Color; 6 | 7 | out vec4 oColor; 8 | 9 | void main() 10 | { 11 | oColor = texture2D(texRgb, TexCoord); 12 | oColor*=Color; 13 | } -------------------------------------------------------------------------------- /LessonInstancing/assets/inst_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | 5 | in vec4 ciPosition; //source mesh vertex position 6 | in vec2 ciTexCoord0; //source mesh texture coordinate 7 | 8 | in vec3 iPosition; //per-instance mesh position ("mesh center") 9 | in vec4 iColor; //per-instance mesh color 10 | in float iSize; //per-instance mesh size 11 | 12 | out vec2 TexCoord; 13 | out vec4 Color; 14 | 15 | void main() 16 | { 17 | Color = iColor; 18 | TexCoord = ciTexCoord0; 19 | 20 | //First we scale the incoming vertex position by size 21 | vec4 cScaled = ciPosition * vec4(iSize,iSize,iSize,1.0); 22 | 23 | //Next, we offset the scaled position by the per-instance position 24 | vec4 cTranslated = cScaled + vec4(iPosition,1.0); 25 | 26 | //Finally, we transform the scaled and translated position into clip space 27 | gl_Position = ciModelViewProjection * cTranslated; 28 | } -------------------------------------------------------------------------------- /LessonInstancing/assets/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonInstancing/assets/texture.png -------------------------------------------------------------------------------- /LessonInstancing/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonInstancing/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonInstancing/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonInstancing/src/LessonInstancingApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 3 | 4 | Instancing: Using a VBO to "instance" meshes, that is defining and loading a mesh's vertex data once 5 | and drawing it multiple times with different attributes 6 | 7 | Reference: 8 | http://learnopengl.com/#!Advanced-OpenGL/Instancing 9 | */ 10 | #include "cinder/app/App.h" 11 | #include "cinder/app/RendererGl.h" 12 | #include "cinder/Camera.h" 13 | #include "cinder/GeomIo.h" 14 | #include "cinder/gl/Batch.h" 15 | #include "cinder/gl/gl.h" 16 | #include "cinder/gl/GlslProg.h" 17 | #include "cinder/gl/Texture.h" 18 | #include "cinder/ImageIo.h" 19 | 20 | using namespace ci; 21 | using namespace ci::app; 22 | using namespace std; 23 | 24 | class LessonInstancingApp : public App 25 | { 26 | public: 27 | void setup() override; 28 | void mouseDown( MouseEvent event ) override; 29 | void update() override; 30 | void draw() override; 31 | 32 | struct CioParticle 33 | { 34 | vec3 IPosition; 35 | vec4 IColor; 36 | float ISize; 37 | 38 | CioParticle(vec3 pPos, vec4 pColor, float pSize) :IPosition(pPos), IColor(pColor), ISize(pSize){} 39 | }; 40 | 41 | struct CioIVertex 42 | { 43 | vec3 VPosition; 44 | vec2 VUV; 45 | 46 | CioIVertex(vec3 pPos, vec2 pUV) :VPosition(pPos), VUV(pUV){} 47 | }; 48 | 49 | private: 50 | gl::VboRef mParticleData, mInstMeshData; 51 | gl::VboMeshRef mVboMesh; 52 | geom::BufferLayout mParticleLayout, mInstMeshLayout; 53 | gl::BatchRef mParticleBatch; 54 | gl::GlslProgRef mParticleShader; 55 | gl::TextureRef mTexRgb; 56 | 57 | CameraPersp mCamera; 58 | 59 | }; 60 | 61 | void LessonInstancingApp::setup() 62 | { 63 | mTexRgb = gl::Texture::create(loadImage(loadAsset("texture.png"))); 64 | try 65 | { 66 | mParticleShader = gl::GlslProg::create(loadAsset("inst_vert.glsl"), loadAsset("inst_frag.glsl")); 67 | } 68 | catch (const gl::GlslProgExc &e) 69 | { 70 | console() << "Error loading shaders: " << endl; 71 | console() << e.what() << endl; 72 | quit(); 73 | } 74 | vector cInstVerts = 75 | { 76 | CioIVertex(vec3(0.25, 0.25, 0.0), vec2(1.0, 1.0)), 77 | CioIVertex(vec3(-0.25, 0.25, 0.0), vec2(0.0, 1.0)), 78 | CioIVertex(vec3(-0.25, -0.25, 0.0), vec2(0.0, 0.0)), 79 | CioIVertex(vec3(0.25, 0.25, 0.0), vec2(1.0, 1.0)), 80 | CioIVertex(vec3(-0.25, -0.25, 0.0), vec2(0.0, 0.0)), 81 | CioIVertex(vec3(0.25, -0.25, 0.0), vec2(1.0, 0.0)) 82 | }; 83 | 84 | mInstMeshData = gl::Vbo::create(GL_ARRAY_BUFFER, cInstVerts, GL_STATIC_DRAW); 85 | mInstMeshLayout.append(geom::Attrib::POSITION, 3, sizeof(CioIVertex), offsetof(CioIVertex, VPosition)); 86 | mInstMeshLayout.append(geom::Attrib::TEX_COORD_0, 2, sizeof(CioIVertex), offsetof(CioIVertex, VUV)); 87 | mVboMesh = gl::VboMesh::create(6, GL_TRIANGLES, { { mInstMeshLayout, mInstMeshData } }); 88 | 89 | vector cParticles = 90 | { 91 | CioParticle(vec3(-1.0,1.0,0.0), vec4(1,0,0,1), 1.5f), 92 | CioParticle(vec3(1.0,1.0,0.0), vec4(0,1,0,1), 2.0f), 93 | CioParticle(vec3(1.0,-1.0,0.0), vec4(0,0,1,1), 3.0f), 94 | CioParticle(vec3(-1.0,-1.0,0.0), vec4(1,1,0,1), 3.5f) 95 | }; 96 | mParticleData = gl::Vbo::create(GL_ARRAY_BUFFER, cParticles.size()*sizeof(CioParticle), cParticles.data(), GL_STATIC_DRAW); 97 | mParticleLayout.append(geom::Attrib::CUSTOM_0, 3, sizeof(CioParticle), offsetof(CioParticle, IPosition), 1); 98 | mParticleLayout.append(geom::Attrib::CUSTOM_1, 4, sizeof(CioParticle), offsetof(CioParticle, IColor), 1); 99 | mParticleLayout.append(geom::Attrib::CUSTOM_2, 1, sizeof(CioParticle), offsetof(CioParticle, ISize), 1); 100 | 101 | mVboMesh->appendVbo(mParticleLayout, mParticleData); 102 | mParticleBatch = gl::Batch::create(mVboMesh, mParticleShader, { { geom::Attrib::CUSTOM_0, "iPosition" }, { geom::Attrib::CUSTOM_1, "iColor" }, { geom::Attrib::CUSTOM_2, "iSize" }}); 103 | 104 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 105 | mCamera.lookAt(vec3(0, 0, 3), vec3(0), vec3(0, 1, 0)); 106 | } 107 | 108 | void LessonInstancingApp::mouseDown( MouseEvent event ) 109 | { 110 | } 111 | 112 | void LessonInstancingApp::update() 113 | { 114 | } 115 | 116 | void LessonInstancingApp::draw() 117 | { 118 | gl::clear( Color( 0.1f, 0.15f, 0.25f ) ); 119 | gl::setMatrices(mCamera); 120 | 121 | gl::ScopedTextureBind cTexture(mTexRgb); 122 | mParticleBatch->drawInstanced(4); 123 | } 124 | 125 | CINDER_APP( LessonInstancingApp, RendererGl ) 126 | -------------------------------------------------------------------------------- /LessonInstancing/vc2013/LessonInstancing.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonInstancing", "LessonInstancing.vcxproj", "{CD55F86D-4235-4C5A-AED5-D67ED10526DC}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {CD55F86D-4235-4C5A-AED5-D67ED10526DC}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {CD55F86D-4235-4C5A-AED5-D67ED10526DC}.Debug|Win32.Build.0 = Debug|Win32 14 | {CD55F86D-4235-4C5A-AED5-D67ED10526DC}.Release|Win32.ActiveCfg = Release|Win32 15 | {CD55F86D-4235-4C5A-AED5-D67ED10526DC}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonInstancing/vc2013/LessonInstancing.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {CD55F86D-4235-4C5A-AED5-D67ED10526DC} 15 | LessonInstancing 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"$(CINDER_DEV)\include";"$(CINDER_DEV)\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /LessonInstancing/vc2013/LessonInstancing.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {e47483a9-ab7d-4af1-89ba-d67efacc2d54} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /LessonInstancing/vc2013/LessonInstancing.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LessonInstancing/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonInstancingAdvanced/assets/frag.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 Color; 4 | out vec4 oColor; 5 | 6 | void main() 7 | { 8 | oColor = Color; 9 | } -------------------------------------------------------------------------------- /LessonInstancingAdvanced/assets/vert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | uniform mat4 ciViewMatrix; 3 | uniform mat4 ciProjectionMatrix; 4 | uniform vec3 u_CameraRight; 5 | uniform vec3 u_CameraUp; 6 | 7 | in vec4 ciPosition; 8 | 9 | in mat4 iModelMatrix; 10 | in vec3 iPosition; 11 | in vec4 iColor; 12 | in float iSize; 13 | 14 | out vec4 Color; 15 | 16 | void main() 17 | { 18 | //If this all looks familiar, it should! We're not doing too much different 19 | //from the previous instancing sample, the only major change is that 20 | //instead of using the default model-view-projection matrix, 21 | //we're constructing our own from per-instance attribute data 22 | 23 | //Transform the point into "billboard" space; 24 | vec3 cPosition = iPosition + u_CameraRight*ciPosition.x*iSize+u_CameraUp*ciPosition.y*iSize; 25 | 26 | //Transform the position into clip space, remember matrix concatenation is RIGHT TO LEFT! 27 | gl_Position = ciProjectionMatrix * ciViewMatrix * iModelMatrix * vec4(cPosition,1.0); 28 | Color = iColor; 29 | } -------------------------------------------------------------------------------- /LessonInstancingAdvanced/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonInstancingAdvanced/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonInstancingAdvanced/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonInstancingAdvanced/src/LessonInstancingAdvancedApp.cpp: -------------------------------------------------------------------------------- 1 | #include "cinder/app/App.h" 2 | #include "cinder/app/RendererGl.h" 3 | #include "cinder/Camera.h" 4 | #include "cinder/CameraUi.h" 5 | #include "cinder/gl/gl.h" 6 | #include "cinder/gl/Batch.h" 7 | #include "cinder/gl/GlslProg.h" 8 | #include "cinder/Rand.h" 9 | 10 | using namespace ci; 11 | using namespace ci::app; 12 | using namespace std; 13 | 14 | int S_NUM_PARTICLES = 1000; 15 | class LessonInstancingAdvancedApp : public App 16 | { 17 | public: 18 | void setup() override; 19 | void update() override; 20 | void draw() override; 21 | 22 | struct Particle 23 | { 24 | vec3 mPos; 25 | vec3 mVel; 26 | ColorA mColor; 27 | int mLife, mAge; 28 | float mRotSpeed; 29 | float mSize, mSize_0; 30 | 31 | //We'll use this to store our new per-instance transform 32 | mat4 mTransform; 33 | 34 | Particle() 35 | { 36 | mPos = vec3(0); 37 | mVel = vec3(randFloat(-0.002f, 0.002f), randFloat(0.004f, 0.01f), randFloat(-0.002f, 0.002f)); 38 | mColor = ColorA(0.f, randFloat(), randFloat(), randFloat(0.1f, 0.75f)); 39 | mRotSpeed = randFloat(-1.f, 1.f); 40 | mLife = randInt(120, 360); 41 | mAge = mLife; 42 | mSize = randFloat(0.1f, 1.0f); 43 | mSize_0 = mSize; 44 | } 45 | 46 | void step(float pElapsed, vec3 pAxis) 47 | { 48 | mAge--; 49 | if (mAge > 0) 50 | { 51 | //set the matrix to the identitiy 52 | mTransform = glm::mat4(); 53 | 54 | //first we update the position in the usual fashion... 55 | mPos += mVel; 56 | mSize = lerp(0, mSize_0, (float)mAge / (float)mLife); 57 | //now we can generate a model matrix from our position and rotation factors 58 | mTransform = glm::translate(mTransform, mPos); 59 | mTransform = glm::rotate(mTransform, mRotSpeed*pElapsed*0.1f, pAxis); 60 | } 61 | } 62 | }; 63 | 64 | private: 65 | vector mParticles; 66 | CameraPersp mCamera; 67 | CameraUi mCamUi; 68 | 69 | gl::BatchRef mBatch; 70 | gl::VboRef mData; 71 | geom::BufferLayout mAttribs; 72 | gl::VboMeshRef mMesh; 73 | gl::GlslProgRef mShader; 74 | }; 75 | 76 | void LessonInstancingAdvancedApp::setup() 77 | { 78 | getWindow()->setSize(1280, 720); 79 | setFrameRate(60.f); 80 | 81 | vec3 cEyePos = vec3(0, 0, 5); 82 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 83 | mCamera.lookAt(cEyePos, vec3(0), vec3(0, 1, 0)); 84 | mCamera.setPivotDistance(length(cEyePos)); 85 | mCamUi = CameraUi(&mCamera, getWindow()); 86 | 87 | mParticles.push_back(Particle()); 88 | mShader = gl::GlslProg::create(loadAsset("vert.glsl"), loadAsset("frag.glsl")); 89 | mData = gl::Vbo::create(GL_ARRAY_BUFFER, mParticles, GL_DYNAMIC_DRAW); 90 | 91 | // Instead of passing in position as an attribute by itself, 92 | // we pass in the whole transform matrix as an attribute. 93 | mAttribs.append(geom::CUSTOM_0, 16, sizeof(Particle), offsetof(Particle, mTransform), 1); 94 | mAttribs.append(geom::CUSTOM_1, 4, sizeof(Particle), offsetof(Particle, mColor), 1); 95 | mAttribs.append(geom::CUSTOM_2, 1, sizeof(Particle), offsetof(Particle, mSize), 1); 96 | 97 | mMesh = gl::VboMesh::create(geom::Plane().size(vec2(0.25)).axes(vec3(1, 0, 0), vec3(0, 1, 0))); 98 | mMesh->appendVbo(mAttribs, mData); 99 | 100 | mBatch = gl::Batch::create(mMesh, mShader, { { geom::CUSTOM_0, "iModelMatrix" }, { geom::CUSTOM_1, "iColor" }, { geom::CUSTOM_2, "iSize" } }); 101 | 102 | gl::enableAlphaBlending(); 103 | } 104 | 105 | 106 | void LessonInstancingAdvancedApp::update() 107 | { 108 | if (mParticles.size() < S_NUM_PARTICLES) 109 | mParticles.push_back(Particle()); 110 | 111 | // To guarantee that our particles are billboarded and rotating properly, 112 | // we need to pass in the camera's view direction vector as our per-instance 113 | // rotation axis. View direction is essentially the camera's Z-vector. 114 | for (auto pit = mParticles.begin(); pit != mParticles.end();) 115 | { 116 | pit->step((float)getElapsedFrames(), mCamera.getViewDirection()); 117 | if (pit->mAge <= 0) 118 | pit = mParticles.erase(pit); 119 | else 120 | ++pit; 121 | } 122 | 123 | mData->bufferData(mParticles.size()*sizeof(Particle), mParticles.data(), GL_DYNAMIC_DRAW); 124 | } 125 | 126 | void LessonInstancingAdvancedApp::draw() 127 | { 128 | gl::clear(Color(0, 0, 0)); 129 | gl::setMatrices(mCamera); 130 | 131 | vec3 cRight, cUp; 132 | mCamera.getBillboardVectors(&cRight, &cUp); 133 | mBatch->getGlslProg()->uniform("u_CameraRight", cRight); 134 | mBatch->getGlslProg()->uniform("u_CameraUp", cUp); 135 | 136 | gl::color(Color::white()); 137 | mBatch->drawInstanced(mParticles.size()); 138 | 139 | gl::color(Color(1, 0, 0)); 140 | gl::drawLine(vec3(0), vec3(2, 0, 0)); 141 | gl::color(Color(0, 1, 0)); 142 | gl::drawLine(vec3(0), vec3(0, 2, 0)); 143 | gl::color(Color(0, 0, 1)); 144 | gl::drawLine(vec3(0), vec3(0, 0, 2)); 145 | } 146 | 147 | CINDER_APP(LessonInstancingAdvancedApp, RendererGl) 148 | -------------------------------------------------------------------------------- /LessonInstancingAdvanced/vc2013/LessonInstancingAdvanced.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 2013 3 | VisualStudioVersion = 12.0.31101.0 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonInstancingAdvanced", "LessonInstancingAdvanced.vcxproj", "{BBD1F9EC-16BF-4B74-B222-8C741939A4C2}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|x64 = Debug|x64 10 | Release|x64 = Release|x64 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {BBD1F9EC-16BF-4B74-B222-8C741939A4C2}.Debug|x64.ActiveCfg = Debug|x64 14 | {BBD1F9EC-16BF-4B74-B222-8C741939A4C2}.Debug|x64.Build.0 = Debug|x64 15 | {BBD1F9EC-16BF-4B74-B222-8C741939A4C2}.Release|x64.ActiveCfg = Release|x64 16 | {BBD1F9EC-16BF-4B74-B222-8C741939A4C2}.Release|x64.Build.0 = Release|x64 17 | EndGlobalSection 18 | GlobalSection(SolutionProperties) = preSolution 19 | HideSolutionNode = FALSE 20 | EndGlobalSection 21 | EndGlobal 22 | -------------------------------------------------------------------------------- /LessonInstancingAdvanced/vc2013/LessonInstancingAdvanced.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {BBD1F9EC-16BF-4B74-B222-8C741939A4C2} 15 | LessonInstancingAdvanced 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;$(CINDER_DEV)\include;$(CINDER_DEV)\boost 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "$(CINDER_DEV)\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;$(CINDER_DEV)\include;$(CINDER_DEV)\boost 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "$(CINDER_DEV)\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "$(CINDER_DEV)\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /LessonInstancingAdvanced/vc2013/LessonInstancingAdvanced.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {5952f2bc-3350-4a07-9f62-c645909329c2} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | -------------------------------------------------------------------------------- /LessonInstancingAdvanced/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonLightingBasics1/assets/basic_lighting_light.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform vec3 LightColor; 4 | out vec4 oColor; 5 | 6 | void main() 7 | { 8 | oColor = vec4(LightColor,1); 9 | } -------------------------------------------------------------------------------- /LessonLightingBasics1/assets/basic_lighting_light.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main() 7 | { 8 | gl_Position = ciModelViewProjection*ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonLightingBasics1/assets/basic_lighting_plane.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | out vec4 oColor; 4 | 5 | void main() 6 | { 7 | oColor = vec4(0.5); 8 | } -------------------------------------------------------------------------------- /LessonLightingBasics1/assets/basic_lighting_plane.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main() 7 | { 8 | gl_Position = ciModelViewProjection*ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonLightingBasics1/assets/basic_lighting_torus.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform vec3 ViewDirection; 4 | uniform vec3 LightColor; 5 | uniform vec3 LightPosition; 6 | 7 | uniform float SpecularScale; 8 | uniform float SpecularPower; 9 | uniform float AmbientScale; 10 | 11 | in vec4 Color; 12 | in vec3 ObjectNormal; 13 | in vec4 WorldPosition; 14 | 15 | out vec4 oColor; 16 | 17 | void main() 18 | { 19 | vec3 cNormal = normalize(ObjectNormal); 20 | vec3 cLightDir = normalize(LightPosition - WorldPosition.xyz); 21 | vec3 cEyeDir = normalize(ViewDirection); 22 | vec3 cReflectDir = reflect(cLightDir, cNormal); 23 | 24 | float cDiffTerm = max(dot(cLightDir, cNormal), 0.0); 25 | float cSpecTerm = pow(max(dot(cEyeDir, cReflectDir), 0), SpecularPower); 26 | 27 | vec3 cDiffContrib = LightColor * cDiffTerm; 28 | vec3 cSpecContrib = SpecularScale * cSpecTerm * LightColor; 29 | vec3 cAmbientContrib = LightColor * AmbientScale; 30 | vec3 cLightContrib = cDiffContrib+cAmbientContrib+cSpecContrib; 31 | 32 | oColor = Color * vec4(cLightContrib,1); 33 | } -------------------------------------------------------------------------------- /LessonLightingBasics1/assets/basic_lighting_torus.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | uniform mat4 ciModelMatrix; 5 | 6 | in vec4 ciPosition; 7 | in vec3 ciNormal; 8 | in vec3 iPosition; 9 | in vec4 iColor; 10 | 11 | out vec4 Color; 12 | out vec3 ObjectNormal; 13 | out vec4 WorldPosition; 14 | 15 | void main() 16 | { 17 | Color = iColor; 18 | 19 | ObjectNormal = mat3(transpose(inverse(ciModelMatrix)))*ciNormal; 20 | 21 | vec4 cInstPos = ciPosition + vec4(iPosition,1.0); 22 | WorldPosition = ciModelMatrix*cInstPos; 23 | gl_Position = ciModelViewProjection * cInstPos; 24 | } -------------------------------------------------------------------------------- /LessonLightingBasics1/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonLightingBasics1/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonLightingBasics1/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonLightingBasics1/src/LessonLightingBasics1App.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Cinder OpenGL-Tutorial - Cinder GL tutorials based on www.opengl-tutorial.org 3 | 4 | Basic Lighting: A simple ambient+diffuse+specular per-pixel lighting implementation 5 | We'll also look at how to use Cinder's built in params window to control our shader parameters 6 | 7 | Reference: 8 | http://learnopengl.com/#!Lighting/Basic-Lighting 9 | */ 10 | #include "cinder/app/App.h" 11 | #include "cinder/app/RendererGl.h" 12 | #include "cinder/gl/gl.h" 13 | #include "cinder/gl/Batch.h" 14 | #include "cinder/gl/GlslProg.h" 15 | #include "cinder/gl/Shader.h" 16 | #include "cinder/Camera.h" 17 | #include "cinder/CameraUi.h" 18 | #include "cinder/params/Params.h" 19 | 20 | using namespace ci; 21 | using namespace ci::app; 22 | using namespace std; 23 | 24 | class LessonLightingBasics1App : public App 25 | { 26 | public: 27 | void setup(); 28 | void update(); 29 | void draw(); 30 | 31 | struct ITorus 32 | { 33 | vec3 IPosition; 34 | vec4 IColor; 35 | ITorus(vec3 pPos, vec4 pCol) :IPosition(pPos), IColor(pCol){} 36 | }; 37 | private: 38 | gl::VboRef mInstanceData; 39 | geom::BufferLayout mInstanceAttribs; 40 | gl::VboMeshRef mTorusMesh; 41 | gl::BatchRef mTorusBatch; 42 | gl::GlslProgRef mTorusShader; 43 | 44 | vec3 mLightPos; 45 | Color mLightColor; 46 | float mAmbientScale, mSpecScale, mSpecPow; 47 | gl::VboMeshRef mLightMesh; 48 | gl::BatchRef mLightBatch; 49 | gl::GlslProgRef mLightShader; 50 | 51 | gl::VboMeshRef mPlaneMesh; 52 | gl::BatchRef mPlaneBatch; 53 | gl::GlslProgRef mPlaneShader; 54 | 55 | CameraPersp mCamera; 56 | CameraUi mCamUI; 57 | 58 | params::InterfaceGlRef mGUI; 59 | }; 60 | 61 | void LessonLightingBasics1App::setup() 62 | { 63 | getWindow()->setSize(1280, 720); 64 | mLightColor = Color(1, 1, 0); 65 | mLightPos = vec3(0,0.75,0); 66 | mAmbientScale = 1.0f; 67 | mSpecScale = 1.0f; 68 | mSpecPow = 32.f; 69 | 70 | auto ad = getAssetPath("basic_lighting_torus.vert"); 71 | 72 | try 73 | { 74 | mTorusShader = gl::GlslProg::create(loadAsset("basic_lighting_torus.vert"), loadAsset("basic_lighting_torus.frag")); 75 | mLightShader = gl::GlslProg::create(loadAsset("basic_lighting_light.vert"), loadAsset("basic_lighting_light.frag")); 76 | mPlaneShader = gl::GlslProg::create(loadAsset("basic_lighting_plane.vert"), loadAsset("basic_lighting_plane.frag")); 77 | } 78 | catch (const gl::GlslProgExc &e) 79 | { 80 | console() << e.what() << endl; 81 | } 82 | 83 | vector cPositions = 84 | { 85 | ITorus(vec3(-1, 0.25, -1), vec4(0.5,0.25,0,1)), 86 | ITorus(vec3(1, 0.25, -1), vec4(0.25, 0.25, 0.1, 1)), 87 | ITorus(vec3(-1, 0.25, 1), vec4(0.1, 0.25, 0.25, 1)), 88 | ITorus(vec3(1, 0.25, 1), vec4(0.0, 0.25, 0.5, 1)) 89 | }; 90 | 91 | mTorusMesh = gl::VboMesh::create(geom::Torus().radius(1.0f, 0.99f)); 92 | mInstanceData = gl::Vbo::create(GL_ARRAY_BUFFER, cPositions, GL_STATIC_DRAW); 93 | mInstanceAttribs.append(geom::CUSTOM_0, 3, sizeof(ITorus), offsetof(ITorus, IPosition), 1); 94 | mInstanceAttribs.append(geom::CUSTOM_1, 4, sizeof(ITorus), offsetof(ITorus, IColor), 1); 95 | mTorusMesh->appendVbo(mInstanceAttribs, mInstanceData); 96 | mTorusBatch = gl::Batch::create(mTorusMesh, mTorusShader, { { geom::CUSTOM_0, "iPosition" }, { geom::CUSTOM_1, "iColor" } }); 97 | mTorusBatch->getGlslProg()->uniform("LightPosition", mLightPos); 98 | mTorusBatch->getGlslProg()->uniform("LightColor", mLightColor); 99 | mTorusBatch->getGlslProg()->uniform("AmbientScale", mAmbientScale); 100 | mTorusBatch->getGlslProg()->uniform("SpecularScale", mSpecScale); 101 | mTorusBatch->getGlslProg()->uniform("SpecularPower", mSpecPow); 102 | 103 | mLightMesh = gl::VboMesh::create(geom::Sphere().subdivisions(16).center(mLightPos).radius(0.01f)); 104 | mLightBatch = gl::Batch::create(mLightMesh, mLightShader); 105 | mLightBatch->getGlslProg()->uniform("LightColor", mLightColor); 106 | 107 | 108 | mPlaneMesh = gl::VboMesh::create(geom::Plane()); 109 | mPlaneBatch = gl::Batch::create(mPlaneMesh, mPlaneShader); 110 | 111 | vec3 cEyePos = vec3(0, 0.65f, -2.25f); 112 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 113 | mCamera.lookAt(cEyePos, vec3(0), vec3(0, 1, 0)); 114 | mCamera.setPivotDistance(length(cEyePos)); 115 | mCamUI = CameraUi(&mCamera, getWindow()); 116 | 117 | //Now let's set up our parameter window 118 | //There's really not too much to it at this point, just 119 | //create the object and call addParam with a name and a pointer 120 | mGUI = params::InterfaceGl::create("Params", vec2(200, 200)); 121 | mGUI->addParam("Light Color", &mLightColor); 122 | mGUI->addParam("Ambient Strength", &mAmbientScale); 123 | mGUI->addParam("Specular Strength", &mSpecScale); 124 | mGUI->addParam("Specular Power", &mSpecPow); 125 | 126 | gl::enableDepthRead(); 127 | gl::enableDepthWrite(); 128 | } 129 | 130 | void LessonLightingBasics1App::update() 131 | { 132 | } 133 | 134 | void LessonLightingBasics1App::draw() 135 | { 136 | // clear out the window with black 137 | gl::clear( Color( 0, 0, 0 ) ); 138 | gl::setMatrices(mCamera); 139 | 140 | mPlaneBatch->draw(); 141 | 142 | mLightBatch->getGlslProg()->uniform("LightColor", mLightColor); 143 | mLightBatch->draw(); 144 | 145 | mTorusBatch->getGlslProg()->uniform("ViewDirection", mCamera.getViewDirection()); 146 | mTorusBatch->getGlslProg()->uniform("LightColor", mLightColor); 147 | mTorusBatch->getGlslProg()->uniform("AmbientScale", mAmbientScale); 148 | mTorusBatch->getGlslProg()->uniform("SpecularScale", mSpecScale); 149 | mTorusBatch->getGlslProg()->uniform("SpecularPower", mSpecPow); 150 | mTorusBatch->drawInstanced(4); 151 | 152 | gl::setMatricesWindow(getWindowSize()); 153 | mGUI->draw(); 154 | } 155 | 156 | CINDER_APP( LessonLightingBasics1App, RendererGl ) 157 | -------------------------------------------------------------------------------- /LessonLightingBasics1/vc2013/LessonLightingBasics1.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonLightingBasics1", "LessonLightingBasics1.vcxproj", "{9DDB0966-F443-4238-BDD8-DA60D874E5AB}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {9DDB0966-F443-4238-BDD8-DA60D874E5AB}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {9DDB0966-F443-4238-BDD8-DA60D874E5AB}.Debug|Win32.Build.0 = Debug|Win32 14 | {9DDB0966-F443-4238-BDD8-DA60D874E5AB}.Release|Win32.ActiveCfg = Release|Win32 15 | {9DDB0966-F443-4238-BDD8-DA60D874E5AB}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonLightingBasics1/vc2013/LessonLightingBasics1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {fc596cee-d93c-4a30-a09d-bc86eb1279c4} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | Source Files\shaders 50 | 51 | 52 | Source Files\shaders 53 | 54 | 55 | Source Files\shaders 56 | 57 | 58 | Source Files\shaders 59 | 60 | 61 | -------------------------------------------------------------------------------- /LessonLightingBasics1/vc2013/LessonLightingBasics1.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LessonLightingBasics1/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/basic_lighting_light.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform vec3 LightColor; 4 | out vec4 oColor; 5 | 6 | void main() 7 | { 8 | oColor = vec4(LightColor,1); 9 | } -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/basic_lighting_light.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main() 7 | { 8 | gl_Position = ciModelViewProjection*ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/basic_lighting_plane.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | out vec4 oColor; 4 | 5 | void main() 6 | { 7 | oColor = vec4(0.5); 8 | } -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/basic_lighting_plane.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main() 7 | { 8 | gl_Position = ciModelViewProjection*ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/basic_lighting_torus.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform vec3 ViewDirection; 4 | uniform vec3 LightColor; 5 | uniform vec3 LightPosition; 6 | 7 | uniform float SpecularScale; 8 | uniform float SpecularPower; 9 | uniform float AmbientScale; 10 | 11 | in vec4 Color; 12 | in vec3 ObjectNormal; 13 | in vec4 WorldPosition; 14 | 15 | out vec4 oColor; 16 | 17 | void main() 18 | { 19 | vec3 cNormal = normalize(ObjectNormal); 20 | vec3 cLightDir = normalize(LightPosition - vec3(WorldPosition.xyz)); 21 | vec3 cEyeDir = normalize(ViewDirection); 22 | vec3 cReflectDir = reflect(cLightDir, cNormal); 23 | 24 | float cDiffTerm = max(dot(cLightDir, cNormal), 0.0); 25 | float cSpecTerm = pow(max(dot(cEyeDir, cReflectDir), 0), SpecularPower); 26 | 27 | vec3 cDiffContrib = LightColor * cDiffTerm; 28 | vec3 cSpecContrib = SpecularScale * cSpecTerm * LightColor; 29 | vec3 cAmbientContrib = LightColor * AmbientScale; 30 | vec3 cLightContrib = cDiffContrib+cAmbientContrib+cSpecContrib; 31 | 32 | oColor = Color * vec4(cLightContrib,1); 33 | } -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/basic_lighting_torus.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | uniform mat4 ciModelMatrix; 5 | uniform mat3 ciNormalMatrix; 6 | 7 | in vec4 ciPosition; 8 | in vec3 ciNormal; 9 | in vec3 iPosition; 10 | in vec4 iColor; 11 | 12 | out vec4 Color; 13 | out vec3 ObjectNormal; 14 | out vec4 WorldPosition; 15 | 16 | void main() 17 | { 18 | Color = iColor; 19 | ObjectNormal = ciNormal; 20 | WorldPosition = ciModelMatrix*ciPosition; 21 | gl_Position = ciModelViewProjection * (4.0*ciPosition + vec4(iPosition,0)); 22 | } -------------------------------------------------------------------------------- /LessonLightingBasics2/assets/normal_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonLightingBasics2/assets/normal_4.png -------------------------------------------------------------------------------- /LessonLightingBasics2/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonLightingBasics2/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonLightingBasics2/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonLightingBasics2/src/LessonLightingBasics2App.cpp: -------------------------------------------------------------------------------- 1 | #include "cinder/app/App.h" 2 | #include "cinder/app/RendererGl.h" 3 | #include "cinder/gl/gl.h" 4 | #include "cinder/gl/Batch.h" 5 | #include "cinder/gl/GlslProg.h" 6 | #include "cinder/Camera.h" 7 | #include "cinder/CameraUi.h" 8 | #include "cinder/params/Params.h" 9 | 10 | using namespace ci; 11 | using namespace ci::app; 12 | using namespace std; 13 | 14 | class LessonLightingBasics2App : public App 15 | { 16 | public: 17 | void setup(); 18 | void update(); 19 | void draw(); 20 | 21 | struct ISphere 22 | { 23 | vec3 IPosition; 24 | vec4 IColor; 25 | ISphere(vec3 pPos, vec4 pCol) :IPosition(pPos), IColor(pCol){} 26 | }; 27 | private: 28 | gl::VboRef mInstanceData; 29 | geom::BufferLayout mInstanceAttribs; 30 | gl::VboMeshRef mTorusMesh; 31 | gl::BatchRef mTorusBatch; 32 | gl::GlslProgRef mTorusShader; 33 | 34 | vec3 mLightPos; 35 | Color mLightColor; 36 | float mAmbientScale, mSpecScale, mSpecPow; 37 | gl::VboMeshRef mLightMesh; 38 | gl::BatchRef mLightBatch; 39 | gl::GlslProgRef mLightShader; 40 | 41 | gl::VboMeshRef mPlaneMesh; 42 | gl::BatchRef mPlaneBatch; 43 | gl::GlslProgRef mPlaneShader; 44 | 45 | CameraPersp mCamera; 46 | CameraUi mCamUI; 47 | 48 | params::InterfaceGlRef mGUI; 49 | }; 50 | 51 | void LessonLightingBasics2App::setup() 52 | { 53 | getWindow()->setSize(1280, 720); 54 | mLightColor = Color(1, 1, 0); 55 | mLightPos = vec3(0, 0.75, 0); 56 | mAmbientScale = 1.0f; 57 | mSpecScale = 1.0f; 58 | mSpecPow = 32.f; 59 | 60 | try 61 | { 62 | mTorusShader = gl::GlslProg::create(loadAsset("basic_lighting_torus.vert"), loadAsset("basic_lighting_torus.frag")); 63 | mLightShader = gl::GlslProg::create(loadAsset("basic_lighting_light.vert"), loadAsset("basic_lighting_light.frag")); 64 | mPlaneShader = gl::GlslProg::create(loadAsset("basic_lighting_plane.vert"), loadAsset("basic_lighting_plane.frag")); 65 | } 66 | catch (const gl::GlslProgExc &e) 67 | { 68 | console() << e.what() << endl; 69 | } 70 | 71 | vector cPositions = 72 | { 73 | ISphere(vec3(-1.25, 0.75, -1.25), vec4(0.5, 0.25, 0, 1)), 74 | ISphere(vec3(1.25, 0.75, -1.25), vec4(0.25, 0.25, 0.1, 1)), 75 | ISphere(vec3(-1.25, 0.75, 1.25), vec4(0.1, 0.25, 0.25, 1)), 76 | ISphere(vec3(1.25, 0.75, 1.25), vec4(0.0, 0.25, 0.5, 1)) 77 | }; 78 | 79 | mTorusMesh = gl::VboMesh::create(geom::Sphere().radius(0.15f)); 80 | mInstanceData = gl::Vbo::create(GL_ARRAY_BUFFER, cPositions, GL_STATIC_DRAW); 81 | mInstanceAttribs.append(geom::CUSTOM_0, 3, sizeof(ISphere), offsetof(ISphere, IPosition), 1); 82 | mInstanceAttribs.append(geom::CUSTOM_1, 4, sizeof(ISphere), offsetof(ISphere, IColor), 1); 83 | mTorusMesh->appendVbo(mInstanceAttribs, mInstanceData); 84 | mTorusBatch = gl::Batch::create(mTorusMesh, mTorusShader, { { geom::CUSTOM_0, "iPosition" }, { geom::CUSTOM_1, "iColor" } }); 85 | mTorusBatch->getGlslProg()->uniform("LightPosition", mLightPos); 86 | mTorusBatch->getGlslProg()->uniform("LightColor", mLightColor); 87 | mTorusBatch->getGlslProg()->uniform("AmbientScale", mAmbientScale); 88 | mTorusBatch->getGlslProg()->uniform("SpecularScale", mSpecScale); 89 | mTorusBatch->getGlslProg()->uniform("SpecularPower", mSpecPow); 90 | 91 | mLightMesh = gl::VboMesh::create(geom::Sphere().subdivisions(16).center(mLightPos).radius(0.01f)); 92 | mLightBatch = gl::Batch::create(mLightMesh, mLightShader); 93 | mLightBatch->getGlslProg()->uniform("LightColor", mLightColor); 94 | 95 | 96 | mPlaneMesh = gl::VboMesh::create(geom::Plane()); 97 | mPlaneBatch = gl::Batch::create(mPlaneMesh, mPlaneShader); 98 | 99 | vec3 cEyePos(0, 0.65f, -2.25f); 100 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 101 | mCamera.lookAt(cEyePos, vec3(0), vec3(0, 1, 0)); 102 | mCamera.setPivotDistance(length(cEyePos)); 103 | mCamUI = CameraUi(&mCamera, getWindow()); 104 | 105 | mGUI = params::InterfaceGl::create("Params", vec2(200, 200)); 106 | mGUI->addParam("Light Color", &mLightColor); 107 | mGUI->addParam("Ambient Strength", &mAmbientScale); 108 | mGUI->addParam("Specular Strength", &mSpecScale); 109 | mGUI->addParam("Specular Power", &mSpecPow); 110 | 111 | gl::enableDepthRead(); 112 | gl::enableDepthWrite(); 113 | } 114 | 115 | void LessonLightingBasics2App::update() 116 | { 117 | } 118 | 119 | void LessonLightingBasics2App::draw() 120 | { 121 | // clear out the window with black 122 | gl::clear(Color(0, 0, 0)); 123 | gl::setMatrices(mCamera); 124 | 125 | mPlaneBatch->draw(); 126 | 127 | gl::pushMatrices(); 128 | mLightPos.x = math::sin(getElapsedSeconds()); 129 | mLightPos.z = math::cos(getElapsedSeconds()); 130 | gl::translate(mLightPos); 131 | mLightBatch->getGlslProg()->uniform("LightColor", mLightColor); 132 | mLightBatch->draw(); 133 | gl::popMatrices(); 134 | 135 | mTorusBatch->getGlslProg()->uniform("ViewDirection", mCamera.getViewDirection()); 136 | mTorusBatch->getGlslProg()->uniform("LightPosition", mLightPos); 137 | mTorusBatch->getGlslProg()->uniform("LightColor", mLightColor); 138 | mTorusBatch->getGlslProg()->uniform("AmbientScale", mAmbientScale); 139 | mTorusBatch->getGlslProg()->uniform("SpecularScale", mSpecScale); 140 | mTorusBatch->getGlslProg()->uniform("SpecularPower", mSpecPow); 141 | mTorusBatch->drawInstanced(4); 142 | 143 | gl::setMatricesWindow(getWindowSize()); 144 | mGUI->draw(); 145 | } 146 | 147 | CINDER_APP(LessonLightingBasics2App, RendererGl) 148 | -------------------------------------------------------------------------------- /LessonLightingBasics2/vc2013/LessonLightingBasics2.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonLightingBasics2", "LessonLightingBasics2.vcxproj", "{EB22BC26-08FD-4E3C-AD6D-52578A41D567}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {EB22BC26-08FD-4E3C-AD6D-52578A41D567}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {EB22BC26-08FD-4E3C-AD6D-52578A41D567}.Debug|Win32.Build.0 = Debug|Win32 14 | {EB22BC26-08FD-4E3C-AD6D-52578A41D567}.Release|Win32.ActiveCfg = Release|Win32 15 | {EB22BC26-08FD-4E3C-AD6D-52578A41D567}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonLightingBasics2/vc2013/LessonLightingBasics2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {3edf8cf3-122d-4a07-b80b-592efa981276} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Source Files\shaders 44 | 45 | 46 | Source Files\shaders 47 | 48 | 49 | Source Files\shaders 50 | 51 | 52 | Source Files\shaders 53 | 54 | 55 | Source Files\shaders 56 | 57 | 58 | Source Files\shaders 59 | 60 | 61 | -------------------------------------------------------------------------------- /LessonLightingBasics2/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /LessonRTT1/assets/basic_lighting_light.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform vec3 LightColor; 4 | out vec4 oColor; 5 | 6 | void main() 7 | { 8 | oColor = vec4(LightColor,1); 9 | } -------------------------------------------------------------------------------- /LessonRTT1/assets/basic_lighting_light.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main() 7 | { 8 | gl_Position = ciModelViewProjection*ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonRTT1/assets/basic_lighting_plane.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | out vec4 oColor; 4 | 5 | void main() 6 | { 7 | oColor = vec4(0.5); 8 | } -------------------------------------------------------------------------------- /LessonRTT1/assets/basic_lighting_plane.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | in vec4 ciPosition; 5 | 6 | void main() 7 | { 8 | gl_Position = ciModelViewProjection*ciPosition; 9 | } -------------------------------------------------------------------------------- /LessonRTT1/assets/basic_lighting_torus.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform vec3 ViewDirection; 4 | uniform vec3 LightColor; 5 | uniform vec3 LightPosition; 6 | 7 | uniform float SpecularScale; 8 | uniform float SpecularPower; 9 | uniform float AmbientScale; 10 | 11 | in vec4 Color; 12 | in vec3 ObjectNormal; 13 | in vec4 WorldPosition; 14 | 15 | out vec4 oColor; 16 | 17 | void main() 18 | { 19 | vec3 cNormal = normalize(ObjectNormal); 20 | vec3 cLightDir = normalize(LightPosition - vec3(WorldPosition.xyz)); 21 | vec3 cEyeDir = normalize(ViewDirection); 22 | vec3 cReflectDir = reflect(cLightDir, cNormal); 23 | 24 | float cDiffTerm = max(dot(cLightDir, cNormal), 0.0); 25 | float cSpecTerm = pow(max(dot(cEyeDir, cReflectDir), 0), SpecularPower); 26 | 27 | vec3 cDiffContrib = LightColor * cDiffTerm; 28 | vec3 cSpecContrib = SpecularScale * cSpecTerm * LightColor; 29 | vec3 cAmbientContrib = LightColor * AmbientScale; 30 | vec3 cLightContrib = cDiffContrib+cAmbientContrib+cSpecContrib; 31 | 32 | oColor = Color * vec4(cLightContrib,1); 33 | } -------------------------------------------------------------------------------- /LessonRTT1/assets/basic_lighting_torus.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 ciModelViewProjection; 4 | uniform mat4 ciModelMatrix; 5 | uniform mat3 ciNormalMatrix; 6 | 7 | in vec4 ciPosition; 8 | in vec3 ciNormal; 9 | in vec3 iPosition; 10 | in vec4 iColor; 11 | 12 | out vec4 Color; 13 | out vec3 ObjectNormal; 14 | out vec4 WorldPosition; 15 | 16 | void main() 17 | { 18 | Color = iColor; 19 | ObjectNormal = ciNormal; 20 | WorldPosition = ciModelMatrix*ciPosition; 21 | gl_Position = ciModelViewProjection * (4.0*ciPosition + vec4(iPosition,0)); 22 | } -------------------------------------------------------------------------------- /LessonRTT1/include/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cinder/CinderResources.h" 3 | 4 | //#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LessonRTT1/resources/cinder_app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SethGibson/CiOpenGl-Tutorial/7fc1a44c9eca806f2b779a470dc7ed576ee13125/LessonRTT1/resources/cinder_app_icon.ico -------------------------------------------------------------------------------- /LessonRTT1/src/LessonRTT1App.cpp: -------------------------------------------------------------------------------- 1 | #include "cinder/app/App.h" 2 | #include "cinder/app/RendererGl.h" 3 | #include "cinder/gl/gl.h" 4 | #include "cinder/gl/Batch.h" 5 | #include "cinder/gl/Fbo.h" 6 | #include "cinder/gl/GlslProg.h" 7 | #include "cinder/Camera.h" 8 | #include "cinder/MayaCamUI.h" 9 | #include "cinder/params/Params.h" 10 | 11 | using namespace ci; 12 | using namespace ci::app; 13 | using namespace std; 14 | 15 | class LessonRTT1App : public App 16 | { 17 | public: 18 | void setup(); 19 | void mouseDown(MouseEvent event); 20 | void mouseDrag(MouseEvent event); 21 | void update(); 22 | void draw(); 23 | 24 | struct ITorus 25 | { 26 | vec3 IPosition; 27 | vec4 IColor; 28 | ITorus(vec3 pPos, vec4 pCol) :IPosition(pPos), IColor(pCol){} 29 | }; 30 | 31 | private: 32 | void setupShadowMap(); 33 | void renderShadowMap(): 34 | 35 | gl::VboRef mInstanceData; 36 | geom::BufferLayout mInstanceAttribs; 37 | gl::VboMeshRef mTorusMesh; 38 | gl::BatchRef mTorusBatch; 39 | gl::GlslProgRef mTorusShader; 40 | 41 | vec3 mLightPos; 42 | Color mLightColor; 43 | float mAmbientScale, mSpecScale, mSpecPow; 44 | gl::VboMeshRef mLightMesh; 45 | gl::BatchRef mLightBatch; 46 | gl::GlslProgRef mLightShader; 47 | gl::FboRef mShadowMap; 48 | 49 | gl::VboMeshRef mPlaneMesh; 50 | gl::BatchRef mPlaneBatch; 51 | gl::GlslProgRef mPlaneShader; 52 | 53 | CameraPersp mCamera; 54 | MayaCamUI mMayaUI; 55 | 56 | params::InterfaceGlRef mGUI; 57 | }; 58 | 59 | void LessonRTT1App::setup() 60 | { 61 | getWindow()->setSize(1280, 720); 62 | mLightColor = Color(1, 1, 0); 63 | mLightPos = vec3(0, 0.75, 0); 64 | mAmbientScale = 1.0f; 65 | mSpecScale = 1.0f; 66 | mSpecPow = 32.f; 67 | 68 | try 69 | { 70 | mTorusShader = gl::GlslProg::create(loadAsset("basic_lighting_torus.vert"), loadAsset("basic_lighting_torus.frag")); 71 | mLightShader = gl::GlslProg::create(loadAsset("basic_lighting_light.vert"), loadAsset("basic_lighting_light.frag")); 72 | mPlaneShader = gl::GlslProg::create(loadAsset("basic_lighting_plane.vert"), loadAsset("basic_lighting_plane.frag")); 73 | } 74 | catch (const gl::GlslProgExc &e) 75 | { 76 | console() << e.what() << endl; 77 | } 78 | 79 | vector cPositions = 80 | { 81 | ITorus(vec3(-1.25, 0.5, -1.25), vec4(0.5, 0.25, 0, 1)), 82 | ITorus(vec3(1.25, 0.5, -1.25), vec4(0.25, 0.25, 0.1, 1)), 83 | ITorus(vec3(-1.25, 0.5, 1.25), vec4(0.1, 0.25, 0.25, 1)), 84 | ITorus(vec3(1.25, 0.5, 1.25), vec4(0.0, 0.25, 0.5, 1)) 85 | }; 86 | 87 | mTorusMesh = gl::VboMesh::create(geom::Torus().radius(0.25f, 0.2f)); 88 | mInstanceData = gl::Vbo::create(GL_ARRAY_BUFFER, cPositions, GL_STATIC_DRAW); 89 | mInstanceAttribs.append(geom::CUSTOM_0, 3, sizeof(ITorus), offsetof(ITorus, IPosition), 1); 90 | mInstanceAttribs.append(geom::CUSTOM_1, 4, sizeof(ITorus), offsetof(ITorus, IColor), 1); 91 | mTorusMesh->appendVbo(mInstanceAttribs, mInstanceData); 92 | mTorusBatch = gl::Batch::create(mTorusMesh, mTorusShader, { { geom::CUSTOM_0, "iPosition" }, { geom::CUSTOM_1, "iColor" } }); 93 | mTorusBatch->getGlslProg()->uniform("LightPosition", mLightPos); 94 | mTorusBatch->getGlslProg()->uniform("LightColor", mLightColor); 95 | mTorusBatch->getGlslProg()->uniform("AmbientScale", mAmbientScale); 96 | mTorusBatch->getGlslProg()->uniform("SpecularScale", mSpecScale); 97 | mTorusBatch->getGlslProg()->uniform("SpecularPower", mSpecPow); 98 | 99 | mLightMesh = gl::VboMesh::create(geom::Sphere().subdivisions(16).center(mLightPos).radius(0.01f)); 100 | mLightBatch = gl::Batch::create(mLightMesh, mLightShader); 101 | mLightBatch->getGlslProg()->uniform("LightColor", mLightColor); 102 | 103 | 104 | mPlaneMesh = gl::VboMesh::create(geom::Plane()); 105 | mPlaneBatch = gl::Batch::create(mPlaneMesh, mPlaneShader); 106 | 107 | mCamera.setPerspective(45.0f, getWindowAspectRatio(), 0.1f, 100.0f); 108 | mCamera.lookAt(vec3(0, 0.65f, -2.25f), vec3(0), vec3(0, 1, 0)); 109 | mCamera.setCenterOfInterestPoint(vec3(0)); 110 | mMayaUI.setCurrentCam(mCamera); 111 | 112 | mGUI = params::InterfaceGl::create("Params", vec2(200, 200)); 113 | mGUI->addParam("Light Color", &mLightColor); 114 | mGUI->addParam("Ambient Strength", &mAmbientScale); 115 | mGUI->addParam("Specular Strength", &mSpecScale); 116 | mGUI->addParam("Specular Power", &mSpecPow); 117 | 118 | gl::enableDepthRead(); 119 | gl::enableDepthWrite(); 120 | } 121 | 122 | void LessonRTT1App::setupShadowMap() 123 | { 124 | 125 | } 126 | 127 | void LessonRTT1App::mouseDown(MouseEvent event) 128 | { 129 | mMayaUI.mouseDown(event.getPos()); 130 | } 131 | 132 | void LessonRTT1App::mouseDrag(MouseEvent event) 133 | { 134 | mMayaUI.mouseDrag(event.getPos(), event.isLeftDown(), false, event.isRightDown()); 135 | } 136 | 137 | void LessonRTT1App::renderShadowMap() 138 | { 139 | 140 | } 141 | 142 | void LessonRTT1App::update() 143 | { 144 | } 145 | 146 | void LessonRTT1App::draw() 147 | { 148 | // clear out the window with black 149 | gl::clear(Color(0, 0, 0)); 150 | gl::setMatrices(mMayaUI.getCamera()); 151 | 152 | mPlaneBatch->draw(); 153 | 154 | mLightBatch->getGlslProg()->uniform("LightColor", mLightColor); 155 | mLightBatch->draw(); 156 | 157 | mTorusBatch->getGlslProg()->uniform("ViewDirection", mMayaUI.getCamera().getViewDirection()); 158 | mTorusBatch->getGlslProg()->uniform("LightColor", mLightColor); 159 | mTorusBatch->getGlslProg()->uniform("AmbientScale", mAmbientScale); 160 | mTorusBatch->getGlslProg()->uniform("SpecularScale", mSpecScale); 161 | mTorusBatch->getGlslProg()->uniform("SpecularPower", mSpecPow); 162 | mTorusBatch->drawInstanced(4); 163 | 164 | gl::setMatricesWindow(getWindowSize()); 165 | mGUI->draw(); 166 | } 167 | 168 | CINDER_APP(LessonRTT1App, RendererGl) 169 | -------------------------------------------------------------------------------- /LessonRTT1/vc2013/LessonRTT1.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LessonRTT1", "LessonRTT1.vcxproj", "{0639A636-2A0F-4697-AC2D-F1AAB277BEA8}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {0639A636-2A0F-4697-AC2D-F1AAB277BEA8}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {0639A636-2A0F-4697-AC2D-F1AAB277BEA8}.Debug|Win32.Build.0 = Debug|Win32 14 | {0639A636-2A0F-4697-AC2D-F1AAB277BEA8}.Release|Win32.ActiveCfg = Release|Win32 15 | {0639A636-2A0F-4697-AC2D-F1AAB277BEA8}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /LessonRTT1/vc2013/LessonRTT1.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | {0639A636-2A0F-4697-AC2D-F1AAB277BEA8} 15 | LessonRTT1 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | false 22 | v120 23 | Unicode 24 | true 25 | 26 | 27 | Application 28 | true 29 | v120 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | <_ProjectFileVersion>10.0.30319.1 43 | true 44 | false 45 | 46 | 47 | $(ProjectDir)$(Platform)\$(Configuration)\ 48 | 49 | 50 | $(ProjectDir)$(Platform)\$(Configuration)\ 51 | 52 | 53 | 54 | Disabled 55 | ..\include;"..\..\..\..\libs\Cinder\include";"..\..\..\..\libs\Cinder\boost" 56 | WIN32;_DEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 57 | EnableFastChecks 58 | MultiThreadedDebug 59 | 60 | 61 | Level3 62 | ProgramDatabase 63 | true 64 | 65 | 66 | "..\..\..\..\libs\Cinder\include";..\include 67 | 68 | 69 | cinder-$(PlatformToolset)_d.lib;%(AdditionalDependencies) 70 | "..\..\..\..\libs\Cinder\lib\msw\$(PlatformTarget)" 71 | true 72 | Windows 73 | false 74 | 75 | 76 | LIBCMT;LIBCPMT 77 | 78 | 79 | 80 | 81 | ..\include;"..\..\..\..\libs\Cinder\include";"..\..\..\..\libs\Cinder\boost" 82 | WIN32;NDEBUG;_WINDOWS;NOMINMAX;_WIN32_WINNT=0x0502;%(PreprocessorDefinitions) 83 | MultiThreaded 84 | 85 | 86 | Level3 87 | ProgramDatabase 88 | true 89 | 90 | 91 | true 92 | 93 | 94 | "..\..\..\..\libs\Cinder\include";..\include 95 | 96 | 97 | cinder-$(PlatformToolset).lib;%(AdditionalDependencies) 98 | "..\..\..\..\libs\Cinder\lib\msw\$(PlatformTarget)" 99 | false 100 | true 101 | Windows 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /LessonRTT1/vc2013/LessonRTT1.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 5 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 6 | 7 | 8 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 9 | h;hpp;hxx;hm;inl;inc;xsd 10 | 11 | 12 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 13 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 14 | 15 | 16 | 17 | 18 | Source Files 19 | 20 | 21 | Source Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | 28 | 29 | Header Files 30 | 31 | 32 | 33 | 34 | Resource Files 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /LessonRTT1/vc2013/Resources.rc: -------------------------------------------------------------------------------- 1 | #include "../include/Resources.h" 2 | 3 | 1 ICON "..\\resources\\cinder_app_icon.ico" 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | __UPDATE:__ I'm deprecating this series of tutorials, when I started this I didn't really have a good direction, I just sorta threw a bunch of stuff together that seemed to sorta make sense, but I'm not so sure that was the best approach in retro (but then, when is it ever??). So I'm prepping a new series of tutorials that focuses less on trying to co-relate OpenGL to Cinder and just teach the Cinder OpenGL wrapper and some general Cinder stuff. May not be the best approach, but personally it's made for a better flowing, more cohesive set of tutorials. I'm going to polish up what's here so it works with Cinder's master branch (and therefore hopefully with 0.9.0), but I won't be adding anything to this. Hopefully this has helped or will help someone, Cheers! 2 | 3 | # CiOpenGl-Tutorial 4 | 5 | Gettings started with Cinder glNext(0.9.0?)'s new OpenGL API. 6 | 7 | _DISCLAIMER: This project should be considered experimental until expressly stated otherwise, as Cinder's API is subject to change!_ 8 | 9 | This repo is a port of various modern OpenGL tutorials to Cinder, both for learning purposes and as stubs for other work.
10 | Original content can be found at/taken from:
11 | 12 | * [OpenGL-Tutorial.org](http://www.opengl-tutorial.org) 13 | * [OGLDev's Modern OpenGL Tutorials](http://ogldev.atspace.co.uk/) 14 | * [Learn OpenGL](http://learnopengl.com/) 15 | * My brain 16 | 17 | ## Installation Notes 18 | * Update your Cinder glNext branch to the most recent commit. If LessonInstanncingAdvanced builds and runs successfully, your version of Cinder is up-to-date enough. 19 | * Clone this anywhere on your system and add an environment variable called **CINDER_DEV**, which should point to the top level of your glNext install, e.g. **C:\dev\libraries\Cinder** or something like that. The environment variable is optional, but be sure to change the VS projects to point to your Cinder install otherwise. 20 | * Each project has an individual solution, or you can open the included **CiOpenGl-Tutorial.sln**. 21 | 22 | ## Lessons 23 | * Lesson01: Triangle 24 | * Lesson02: Camera 25 | * Lesson03: 3D Shapes, Vertex Attributes 26 | * Lesson04: Basic Texturing 27 | * Lesson04b: Interleaved Vertex Attributes 28 | * Lesson05: Cinder Interactive Camera (Cinder::MayaCamUI) 29 | * LessonIndexedVBO: Drawing VBOMesh with Indices 30 | * LessonIndexedVBODynamic: Drawing VBOMesh with Dynamic Attributes 31 | * LessonInstancing: Drawing Instanced Geometry with per-Instance Attributes 32 | * LessonLightingBasic1: Diffuse+Ambient+Specular 33 | * LessonBillboards: Instanced Billboards 34 | 35 | 36 | ### Coming Soon (Subject to Change) 37 | * LessonVBORanged: Dynamic VBOs using ranged buffers 38 | * LessonVBOSubBuffer: Dynamic VBOs using sub buffering 39 | * LessonInstancingDynamic: Instanced Geometry with Dynamic per-Instance Attributes (Particles) 40 | * LessonLightingBasic2: Diffuse+Ambient+Specular+Normal Mapping 41 | * LessonRTT1: Shadow Maps 42 | * LessonRTT2: Skyboxes 43 | * LessonRTT3: FSFX 44 | * Various things involving depth-based point clouds 45 | 46 | Questions, comments, suggestions to [my inbox](mailto:seth.gibson1@gmail.com). Also, I love PRs. 47 | -------------------------------------------------------------------------------- /REVISIONS.md: -------------------------------------------------------------------------------- 1 | **Development Notes and Revisions** 2 | * 2015.05.05 - Added Advanced Instancing (requires glslProgRebase or post glslProgRebase merge) 3 | * 2015.05.02 - Updated to use CameraUi changes, added LessonBillboards, cleaned up some names 4 | * 2015.03.11 - Updated lessons for Cinder::App refactor 5 | * 2015.03.10 - Added LessonLightingBasic1 6 | --------------------------------------------------------------------------------