void cullindirect_app::startup() { GLuint first, count; object.load("media/objects/asteroids.sbm"); glGenBuffers(1, &buffers.parameters); glBindBuffer(GL_PARAMETER_BUFFER_ARB, buffers.parameters); glBufferStorage(GL_PARAMETER_BUFFER_ARB, 256, nullptr, 0); glGenBuffers(1, &buffers.drawCandidates); glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffers.drawCandidates); CandidateDraw* pDraws = new CandidateDraw[CANDIDATE_COUNT]; int i; for (i = 0; i < CANDIDATE_COUNT; i++) { object.get_sub_object_info(i % object.get_sub_object_count(), first, count); pDraws[i].sphereCenter = vmath::vec3(0.0f); pDraws[i].sphereRadius = 4.0f; pDraws[i].firstVertex = first; pDraws[i].vertexCount = count; } glBufferStorage(GL_SHADER_STORAGE_BUFFER, CANDIDATE_COUNT * sizeof(CandidateDraw), pDraws, 0); delete [] pDraws; glGenBuffers(1, &buffers.drawCommands); glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffers.drawCommands); glBufferStorage(GL_SHADER_STORAGE_BUFFER, CANDIDATE_COUNT * sizeof(DrawArraysIndirectCommand), nullptr, GL_MAP_READ_BIT); glGenBuffers(1, &buffers.modelMatrices); glBindBuffer(GL_UNIFORM_BUFFER, buffers.modelMatrices); glBufferStorage(GL_UNIFORM_BUFFER, 1024 * sizeof(vmath::mat4), nullptr, GL_MAP_WRITE_BIT); glGenBuffers(1, &buffers.transforms); glBindBuffer(GL_UNIFORM_BUFFER, buffers.transforms); glBufferStorage(GL_UNIFORM_BUFFER, sizeof(TransformBuffer), nullptr, GL_MAP_WRITE_BIT); load_shaders(); overlay.init(128, 50); texture = sb7::ktx::file::load("media/textures/rocks.ktx"); }
void assignment1_app::startup() { load_shaders(); glGenVertexArrays(1, &cube_vao); //glGenVertexArrays(n, &array) returns n vertex array object names in arrays glBindVertexArray(cube_vao); //glBindVertexArray(array) binds the vertex array object with name array. #pragma region Cube Pos Buffer glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(cube_data), cube_data, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); #pragma endregion #pragma region Cube Color Buffer glGenBuffers(1, &colorBuffer); glBindBuffer(GL_ARRAY_BUFFER, colorBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(color_data), color_data, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); #pragma endregion #pragma region Cube Normals Buffer glGenBuffers(1, &normalsBuffer); glBindBuffer(GL_ARRAY_BUFFER, normalsBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(normals_data), normals_data, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); #pragma endregion #pragma region Buffer For Uniform Block glGenBuffers(1, &uniforms_buffer); glBindBuffer(GL_UNIFORM_BUFFER, uniforms_buffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(uniforms_block), NULL, GL_DYNAMIC_DRAW); #pragma endregion useUniformColor = falseVec; glGenVertexArrays(1, &sphere_vao); glBindVertexArray(sphere_vao); object.load("bin\\media\\objects\\sphere.sbm"); #pragma region OPENGL Settings glEnable(GL_CULL_FACE); // Use face culling to see into the room. glFrontFace(GL_CW); //glFrontFace(GLenum mode) In a scene composed entirely of opaque closed surfaces, back-facing polygons are never visible. glEnable(GL_DEPTH_TEST); //glEnable(GLenum cap) glEnable and glDisable enable and disable various capabilities. glDepthFunc(GL_LEQUAL); //glDepthFunc(GLenum func) specifies the function used to compare each incoming pixel depth value with the depth value present in the depth buffer. #pragma endregion }
void bumpmapping_app::startup() { load_shaders(); glActiveTexture(GL_TEXTURE0); textures.color = sb7::ktx::file::load("media/textures/ladybug_co.ktx"); glActiveTexture(GL_TEXTURE1); textures.normals = sb7::ktx::file::load("media/textures/ladybug_nm.ktx"); object.load("media/objects/ladybug.sbm"); }
void phonglighting_app::startup() { load_shaders(); glGenBuffers(1, &uniforms_buffer); glBindBuffer(GL_UNIFORM_BUFFER, uniforms_buffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(uniforms_block), NULL, GL_DYNAMIC_DRAW); object.load("media/objects/sphere.sbm"); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); }
void bumpmapping_app::render(double currentTime) { static const GLfloat zeros[] = { 0.0f, 0.0f, 0.0f, 0.0f }; static const GLfloat gray[] = { 0.1f, 0.1f, 0.1f, 0.0f }; static const GLfloat ones[] = { 1.0f }; static double last_time = 0.0; static double total_time = 0.0; if (!paused) total_time += (currentTime - last_time); last_time = currentTime; const float f = (float)total_time; glClearBufferfv(GL_COLOR, 0, gray); glClearBufferfv(GL_DEPTH, 0, ones); glViewport(0, 0, info.windowWidth, info.windowHeight); glEnable(GL_DEPTH_TEST); glUseProgram(program); vmath::mat4 proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUniformMatrix4fv(uniforms.proj_matrix, 1, GL_FALSE, proj_matrix); vmath::mat4 mv_matrix = vmath::translate(0.0f, -0.2f, -5.5f) * vmath::rotate(14.5f, 1.0f, 0.0f, 0.0f) * vmath::rotate(-20.0f, 0.0f, 1.0f, 0.0f) * //vmath::rotate(t * 14.5f, 0.0f, 1.0f, 0.0f) * //vmath::rotate(0.0f, 1.0f, 0.0f, 0.0f) * vmath::mat4::identity(); glUniformMatrix4fv(uniforms.mv_matrix, 1, GL_FALSE, mv_matrix); glUniform3fv(uniforms.light_pos, 1, vmath::vec3(40.0f * sinf(f), 30.0f + 20.0f * cosf(f), 40.0f)); object.render(); }
void pmbstreaming_app::startup() { glGenBuffers(1, &buffer); glBindBuffer(GL_UNIFORM_BUFFER, buffer); glBufferStorage(GL_UNIFORM_BUFFER, BUFFER_SIZE, nullptr, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); vs_uniforms = (MATRICES*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, BUFFER_SIZE, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); GLuint shaders[2] = { sb7::shader::load("media/shaders/pmbstreaming/pmbstreaming.vs.glsl", GL_VERTEX_SHADER), sb7::shader::load("media/shaders/pmbstreaming/pmbstreaming.fs.glsl", GL_FRAGMENT_SHADER) }; program = sb7::program::link_from_shaders(shaders, 2, true); object.load("media/objects/torus_nrms_tc.sbm"); glBindBufferBase(GL_UNIFORM_BUFFER, 0, buffer); overlay.init(128, 50); glActiveTexture(GL_TEXTURE0); texture = sb7::ktx::file::load("media/textures/pattern1.ktx"); for (int i = 0; i < CHUNK_COUNT; i++) { fence[i] = 0; } }
void pmbstreaming_app::render(double currentTime) { static float lastTime = 0.0f; static int frames = 0; float nowTime = float(currentTime); int isSignaled; static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 0.0f }; static const GLfloat one[] = { 1.0f }; vmath::mat4 proj_matrix = vmath::perspective(60.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1800.0f); vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -3.0f) * vmath::rotate((float)currentTime * 43.75f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 17.75f, 0.0f, 0.0f, 1.0f) * vmath::rotate((float)currentTime * 35.3f, 1.0f, 0.0f, 0.0f); glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, black); glClearBufferfv(GL_DEPTH, 0, one); glUseProgram(program); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); if (mode == ONE_SYNC) { if (fence[0] != 0) { glGetSynciv(fence[0], GL_SYNC_STATUS, sizeof(int), nullptr, &isSignaled); stalled = isSignaled == GL_UNSIGNALED; glClientWaitSync(fence[0], 0, GL_TIMEOUT_IGNORED); glDeleteSync(fence[0]); } } else if (mode == RINGED_SYNC) { if (fence[sync_index] != 0) { glGetSynciv(fence[sync_index], GL_SYNC_STATUS, sizeof(int), nullptr, &isSignaled); stalled = isSignaled == GL_UNSIGNALED; glClientWaitSync(fence[sync_index], 0, GL_TIMEOUT_IGNORED); glDeleteSync(fence[sync_index]); } } vs_uniforms[sync_index].modelview = mv_matrix; vs_uniforms[sync_index].projection = proj_matrix; if (mode == RINGED_SYNC) { object.render(1, sync_index); } else { object.render(1, 0); } if (nowTime > (lastTime + 0.25f)) { fps = float(frames) / (nowTime - lastTime); frames = 0; lastTime = nowTime; } updateOverlay(); if (mode == FINISH) { glFinish(); stalled = true; } else if (mode == ONE_SYNC) { fence[0] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } else if (mode == RINGED_SYNC) { fence[sync_index] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } sync_index = (sync_index + 1) % CHUNK_COUNT; frames++; }
void phonglighting_app::render(double currentTime) { static const GLfloat zeros[] = { 0.0f, 0.0f, 0.0f, 0.0f }; static const GLfloat gray[] = { 0.1f, 0.1f, 0.1f, 0.0f }; static const GLfloat ones[] = { 1.0f }; const float f = (float)currentTime; glUseProgram(per_vertex ? per_vertex_program : per_fragment_program); glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, gray); glClearBufferfv(GL_DEPTH, 0, ones); /* vmath::mat4 model_matrix = vmath::rotate((float)currentTime * 14.5f, 0.0f, 1.0f, 0.0f) * vmath::rotate(180.0f, 0.0f, 0.0f, 1.0f) * vmath::rotate(20.0f, 1.0f, 0.0f, 0.0f); */ vmath::vec3 view_position = vmath::vec3(0.0f, 0.0f, 50.0f); vmath::mat4 view_matrix = vmath::lookat(view_position, vmath::vec3(0.0f, 0.0f, 0.0f), vmath::vec3(0.0f, 1.0f, 0.0f)); vmath::vec3 light_position = vmath::vec3(20.0f, 20.0f, 0.0f); vmath::mat4 light_proj_matrix = vmath::frustum(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 200.0f); vmath::mat4 light_view_matrix = vmath::lookat(light_position, vmath::vec3(0.0f), vmath::vec3(0.0f, 1.0f, 0.0f)); #if defined(MANY_OBJECTS) int i, j; for (j = 0; j < 7; j++) { for (i = 0; i < 7; i++) { glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); uniforms_block * block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); vmath::mat4 model_matrix = vmath::translate((float)i * 2.75f - 8.25f, 6.75f - (float)j * 2.25f, 0.0f); block->mv_matrix = view_matrix * model_matrix; block->view_matrix = view_matrix; block->proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUnmapBuffer(GL_UNIFORM_BUFFER); glUniform1f(uniforms[per_vertex ? 1 : 0].specular_power, powf(2.0f, (float)j + 2.0f)); glUniform3fv(uniforms[per_vertex ? 1 : 0].specular_albedo, 1, vmath::vec3((float)i / 9.0f + 1.0f / 9.0f)); object.render(); } } #else glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); uniforms_block * block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); vmath::mat4 model_matrix = vmath::scale(7.0f); block->mv_matrix = view_matrix * model_matrix; block->view_matrix = view_matrix; block->proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUnmapBuffer(GL_UNIFORM_BUFFER); glUniform1f(uniforms[per_vertex ? 1 : 0].specular_power, 30.0f); glUniform3fv(uniforms[per_vertex ? 1 : 0].specular_albedo, 1, vmath::vec3(1.0f)); object.render(); #endif }
void cullindirect_app::render(double currentTime) { static const GLfloat farplane[] = { 1.0f }; static float lastTime = 0.0f; static int frames = 0; float nowTime = float(currentTime); int i; // Set viewport and clear glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, sb7::color::Black); glClearBufferfv(GL_DEPTH, 0, farplane); // Bind and clear atomic counter glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, buffers.parameters); glClearBufferSubData(GL_ATOMIC_COUNTER_BUFFER, GL_R32UI, 0, sizeof(GLuint), GL_RED_INTEGER, GL_UNSIGNED_INT, nullptr); // Bind shader storage buffers glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffers.drawCandidates); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffers.drawCommands); // Bind model matrix UBO and fill with data glBindBufferBase(GL_UNIFORM_BUFFER, 0, buffers.modelMatrices); vmath::mat4* pModelMatrix = (vmath::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 1024 * sizeof(vmath::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); for (i = 0; i < 1024; i++) { float f = float(i) / 127.0f + nowTime * 0.025f; float g = float(i) / 127.0f; const vmath::mat4 model_matrix = vmath::translate(70.0f * vmath::vec3(sinf(f * 3.0f), cosf(f * 5.0f), cosf(f * 9.0f))) * vmath::rotate(nowTime * 140.0f, vmath::normalize(vmath::vec3(sinf(g * 35.0f), cosf(g * 75.0f), cosf(g * 39.0f)))); pModelMatrix[i] = model_matrix; } glUnmapBuffer(GL_UNIFORM_BUFFER); // Bind view + projection matrix UBO and fill glBindBufferBase(GL_UNIFORM_BUFFER, 1, buffers.transforms); TransformBuffer* pTransforms = (TransformBuffer*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(TransformBuffer), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); float t = nowTime * 0.1f; const vmath::mat4 view_matrix = vmath::lookat(vmath::vec3(150.0f * cosf(t), 0.0f, 150.0f * sinf(t)), vmath::vec3(0.0f, 0.0f, 0.0f), vmath::vec3(0.0f, 1.0f, 0.0f)); const vmath::mat4 proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 1.0f, 2000.0f); pTransforms->view_matrix = view_matrix; pTransforms->proj_matrix = proj_matrix; pTransforms->view_proj_matrix = proj_matrix * view_matrix; glUnmapBuffer(GL_UNIFORM_BUFFER); // Bind the culling compute shader and dispatch it glUseProgram(programs.cull); glDispatchCompute(CANDIDATE_COUNT / 16, 1, 1); // Barrier glMemoryBarrier(GL_COMMAND_BARRIER_BIT); // Get ready to render glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glBindVertexArray(object.get_vao()); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); // Bind indirect command buffer and parameter buffer glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffers.drawCommands); glBindBuffer(GL_PARAMETER_BUFFER_ARB, buffers.parameters); glUseProgram(programs.draw); // Draw glMultiDrawArraysIndirectCountARB(GL_TRIANGLES, 0, 0, CANDIDATE_COUNT, 0); // Update overlay if (nowTime > (lastTime + 0.25f)) { fps = float(frames) / (nowTime - lastTime); frames = 0; lastTime = nowTime; } glDisable(GL_CULL_FACE); updateOverlay(); frames++; }
void assignment1_app::render(double currentTime) { const float f = (float)currentTime; glUseProgram(per_vertex ? per_vertex_program : per_fragment_program); #pragma region Calculations for mouse interaction camera rotation and translation matrix float fAngle = 0.0f; vmath::vec3 axis_in_camera_coord = (0.0f, 1.0f, 0.0f); if (iCurMouseX != iPrevMouseX || iCurMouseY != iPrevMouseY) { // Arcball Rotation if (bRotate) { vmath::vec3 va = getArcballVector(iPrevMouseX, iPrevMouseY); vmath::vec3 vb = getArcballVector(iCurMouseX, iCurMouseY); fAngle = acos(fmin(1.0f, vmath::dot(va, vb))); axis_in_camera_coord = vmath::cross(va, vb); axis_in_camera_coord = vmath::normalize(axis_in_camera_coord); iPrevMouseX = iCurMouseX; iPrevMouseY = iCurMouseY; rotationMatrix *= vmath::rotate(vmath::degrees(fAngle), axis_in_camera_coord); } // Zoom in and out if (bZoom) { fZpos += (iCurMouseY - iPrevMouseY); if (fZpos > 500) { fZpos = 500; } else if (fZpos < 10) { fZpos = 10; } iPrevMouseY = iCurMouseY; iPrevMouseX = iCurMouseX; } // Pan camera left, right, up, and down if (bPan) { fXpos += (iCurMouseX - iPrevMouseX); fYpos += (iCurMouseY - iPrevMouseY); iPrevMouseY = iCurMouseY; iPrevMouseX = iCurMouseX; translationMatrix = vmath::translate(fXpos / (info.windowWidth / fZpos), -fYpos / (info.windowWidth / fZpos), 0.0f); } //Light position tracks with the camera lightPos = vmath::vec4(iLightPosX * translationMatrix[0][0] + iLightPosX * translationMatrix[0][1] + iLightPosX * translationMatrix[0][2], iLightPosY * translationMatrix[1][0] + iLightPosY * translationMatrix[1][1] + iLightPosY * translationMatrix[1][2], iLightPosZ * translationMatrix[2][0] + iLightPosZ * translationMatrix[2][1] + iLightPosZ * translationMatrix[2][2], 1.0f ); lightPos = vmath::vec4(lightPos[0] * rotationMatrix[0][0] + lightPos[0] * rotationMatrix[0][1] + lightPos[0] * rotationMatrix[0][2], lightPos[1] * rotationMatrix[1][0] + lightPos[1] * rotationMatrix[1][1] + lightPos[1] * rotationMatrix[1][2], lightPos[2] * rotationMatrix[2][0] + lightPos[2] * rotationMatrix[2][1] + lightPos[2] * rotationMatrix[2][2], 1.0f ); } #pragma endregion glViewport(0, 0, info.windowWidth, info.windowHeight); // Create sky blue background glClearBufferfv(GL_COLOR, 0, skyBlue); glClearBufferfv(GL_DEPTH, 0, ones); // Set up view and perspective matrix vmath::vec3 view_position = vmath::vec3(0.0f, 0.0f, fZpos); vmath::mat4 view_matrix = vmath::lookat(view_position, vmath::vec3(0.0f, 0.0f, 0.0f), vmath::vec3(0.0f, 1.0f, 0.0f)); view_matrix *= translationMatrix; view_matrix *= rotationMatrix; vmath::mat4 perspective_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUnmapBuffer(GL_UNIFORM_BUFFER); //release the mapping of a buffer object's data store into the client's address space glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); uniforms_block * block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); #pragma region Uniforms that remain constant for all geometery block->proj_matrix = perspective_matrix; block->lightPos = lightPos; #pragma endregion #pragma region Draw Sphere glBindVertexArray(sphere_vao); glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT); vmath::mat4 model_matrix = vmath::translate(-9.3f, -16.0f, 1.0f) * vmath::scale(6.0f); block->mv_matrix = view_matrix * model_matrix; block->view_matrix = view_matrix; block->uni_color = purple; block->useUniformColor = useUniformColor; block->invertNormals = falseVec; block->isSphere = trueVec; glCullFace(GL_BACK); object.render(); #pragma endregion glUnmapBuffer(GL_UNIFORM_BUFFER); //release the mapping of a buffer object's data store into the client's address space glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT); #pragma region Uniforms that remain constant for cubes block->uni_color = orange; block->useUniformColor = falseVec; block->isSphere = falseVec; #pragma endregion #pragma region bind cube vertex data glBindVertexArray(cube_vao); glBindBuffer(GL_ARRAY_BUFFER, buffer); glEnableVertexAttribArray(0); //enable or disable a generic vertex attribute array glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); //define an array of generic vertex attribute data void glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) glBindBuffer(GL_ARRAY_BUFFER, normalsBuffer); glEnableVertexAttribArray(1); //enable or disable a generic vertex attribute array glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0); //define an array of generic vertex attribute data void glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) glBindBuffer(GL_ARRAY_BUFFER, colorBuffer); glEnableVertexAttribArray(2); //enable or disable a generic vertex attribute array glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, 0); //define an array of generic vertex attribute data void glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) glUnmapBuffer(GL_UNIFORM_BUFFER); glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT); #pragma endregion #pragma region Draw Room model_matrix = //vmath::rotate((float)currentTime * 14.5f, 0.0f, 1.0f, 0.0f) * //used to constantly rotate vmath::rotate(45.0f, 0.0f, 1.0f, 0.0f)* vmath::scale(22.0f); block->mv_matrix = view_matrix * model_matrix; block->view_matrix = view_matrix; block->invertNormals = falseVec; glCullFace(GL_FRONT); glDrawArrays(GL_TRIANGLES, 0, numberOfCubeVertices); #pragma endregion #pragma region Draw Cube glUnmapBuffer(GL_UNIFORM_BUFFER); //release the mapping of a buffer object's data store into the client's address space glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniforms_buffer); block = (uniforms_block *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(uniforms_block), GL_MAP_WRITE_BIT); model_matrix = vmath::rotate(0.0f, 0.0f, 1.0f, 0.0f) * vmath::translate(10.0f, -17.3f, -1.0f) * vmath::scale(5.0f); block->mv_matrix = view_matrix * model_matrix; block->view_matrix = view_matrix; block->useUniformColor = falseVec; block->invertNormals = trueVec; glCullFace(GL_BACK); glDrawArrays(GL_TRIANGLES, 0, numberOfCubeVertices); #pragma endregion }