void render(double currentTime) { const GLfloat color[] = {0.0f, 0.2f, 0.0f, 1.0f}; glClearBufferfv(GL_COLOR, 0, color); glUseProgram(this->prog); glDrawArrays(GL_TRIANGLES, 0, 3); }
void render(double currentTime) { const GLfloat color[] = {1.0f, 0.5+0.5*sin(3.0*currentTime), 0.0f, 1.0f}; glClearBufferfv(GL_COLOR, 0, color); glUseProgram(this->prog); glPointSize(20.0f); glDrawArrays(GL_POINTS, 0, 1); }
void RenderSystem::v_Render() { float bgColor[4] ={ 0.0f, 0.0f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, bgColor); m_Window.Render(); }
void RenderSystem::v_Render() { static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, black); m_Plane.Render(GetAspect()); }
void CoordinateSystemsApplication::Draw(float DeltaSeconds) { glClearBufferfv(GL_COLOR, 0, &mBackgroundColor[0]); glClear(GL_DEPTH_BUFFER_BIT); Application::Draw(DeltaSeconds); glfwSwapBuffers(window); }
void RenderSystem::v_Render() { static const glm::vec4 bgColor(0.2f, 0.4f, 0.5f, 1.0f); glClearBufferfv(GL_COLOR, 0, &bgColor[0]); static const GLfloat aspect = GetAspect(); m_Rectangle.Render(aspect); }
void RenderSystem::v_Render() { static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, &black[0]); m_Triangle.Render(); }
bool render() { glm::ivec2 WindowSize = this->getWindowSize(); glViewport(0, 0, WindowSize.x, WindowSize.y); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); return true; }
void v_Render() { float t = (float)glfwGetTime(); static const float black[] = { 0.0f, 0.0f, 0.0f, 1.0f }; static const float one = 1.0f; glUseProgram(flock_update_program); vmath::vec3 goal = vmath::vec3(sinf(t * 0.34f), cosf(t * 0.29f), sinf(t * 0.12f) * cosf(t * 0.5f)); goal = goal * vmath::vec3(35.0f, 25.0f, 60.0f); glUniform3fv(uniforms.update.goal, 1, goal); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, flock_buffer[frame_index]); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, flock_buffer[frame_index ^ 1]); glDispatchCompute(NUM_WORKGROUPS, 1, 1); glViewport(0, 0, GetScreenWidth(), GetScreenHeight()); glClearBufferfv(GL_COLOR, 0, black); glClearBufferfv(GL_DEPTH, 0, &one); glUseProgram(flock_render_program); vmath::mat4 mv_matrix = vmath::lookat(vmath::vec3(0.0f, 0.0f, -400.0f), vmath::vec3(0.0f, 0.0f, 0.0f), vmath::vec3(0.0f, 1.0f, 0.0f)); vmath::mat4 proj_matrix = vmath::perspective(60.0f, getAspect(), 0.1f, 3000.0f); vmath::mat4 mvp = proj_matrix * mv_matrix; glUniformMatrix4fv(uniforms.render.mvp, 1, GL_FALSE, mvp); glBindVertexArray(flock_render_vao[frame_index]); glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 8, FLOCK_SIZE); frame_index ^= 1; }
virtual void render(double currentTime) { static const GLfloat black[] = { 0.85f, 0.95f, 1.0f, 1.0f }; static const GLfloat one = 1.0f; static double last_time = 0.0; static double total_time = 0.0; if (!paused) total_time += (currentTime - last_time); last_time = currentTime; float t = (float)total_time * 0.03f; float r = sinf(t * 5.37f) * 15.0f + 16.0f; float h = cosf(t * 4.79f) * 2.0f + 3.2f; glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, black); glClearBufferfv(GL_DEPTH, 0, &one); vmath::mat4 mv_matrix = /* vmath::translate(0.0f, 0.0f, -1.4f) * vmath::translate(0.0f, -0.4f, 0.0f) * */ // vmath::rotate((float)currentTime * 6.0f, 0.0f, 1.0f, 0.0f) * vmath::lookat(vmath::vec3(sinf(t) * r, h, cosf(t) * r), vmath::vec3(0.0f), vmath::vec3(0.0f, 1.0f, 0.0f)); vmath::mat4 proj_matrix = vmath::perspective(60.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUseProgram(program); glUniformMatrix4fv(uniforms.mv_matrix, 1, GL_FALSE, mv_matrix); glUniformMatrix4fv(uniforms.proj_matrix, 1, GL_FALSE, proj_matrix); glUniformMatrix4fv(uniforms.mvp_matrix, 1, GL_FALSE, proj_matrix * mv_matrix); glUniform1f(uniforms.dmap_depth, enable_displacement ? dmap_depth : 0.0f); glUniform1i(uniforms.enable_fog, enable_fog ? 1 : 0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); if (wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDrawArraysInstanced(GL_PATCHES, 0, 4, 64 * 64); }
void display() { // Update of the uniform buffer { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); //glm::mat4 Projection = glm::perspectiveFov(45.f, 640.f, 480.f, 0.1f, 100.0f); glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 8.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * View * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glViewport(0, 0, Window.Size.x, Window.Size.y); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::DEPTH_MULTISAMPLE]); float Depth(1.0f); glClearBufferfv(GL_DEPTH , 0, &Depth); // Bind rendering objects glUseProgram(ProgramName[program::TEXTURE]); glUniformBlockBinding(ProgramName[program::TEXTURE], UniformTransform, glf::semantic::uniform::TRANSFORM0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glBindVertexArray(VertexArrayName[program::TEXTURE]); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 2, 0); // Pass 2 glDisable(GL_DEPTH_TEST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glUseProgram(ProgramName[program::SPLASH]); glActiveTexture(GL_TEXTURE0); glBindVertexArray(VertexArrayName[program::SPLASH]); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]); glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); glf::swapBuffers(); }
enum piglit_result piglit_display(void) { bool pass = true; const float clearColor[3] = { 1, 1, 0 }; /* Clear Defualt Framebuffer */ glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo); glClearColor(1,1,0,1); glClear(GL_COLOR_BUFFER_BIT); /* Clear texture[0] with glClear() */ glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]); glClearColor(clearColor[0], clearColor[1], clearColor[2], 1); glClear(GL_COLOR_BUFFER_BIT); /* Clear texture[1] with glClearBuffer() */ glBindFramebuffer(GL_FRAMEBUFFER, fbo[1]); glClearBufferfv(GL_COLOR, 0, clearColor); /* Display glClear texture */ if(!display_layered_texture(0, 0, piglit_width/2, piglit_height, piglit_width, piglit_height, GL_TEXTURE_2D_ARRAY, texture[0], layers)) { printf("Failed to display layered texture for glClear\n"); pass = false; } /* Display glClearBuffer texture */ if(!display_layered_texture(piglit_width/2, 0, piglit_width/2, piglit_height, piglit_width, piglit_height, GL_TEXTURE_2D_ARRAY, texture[1], layers)) { printf("Failed to display layered texture for glClearBuffer\n"); pass = false; } /* Check for passing conditions for glClear*/ if(!piglit_probe_rect_rgb(0, 0, piglit_width/2, piglit_height, clearColor)) { printf("Incorrect probe value for glClear test.\n"); pass = false; } /* Check for passing conditions for glClearBuffer*/ if(!piglit_probe_rect_rgb(piglit_width/2, 0, piglit_width/2, piglit_height, clearColor)) { printf("Incorrect probe value for glClearBuffer test.\n"); pass = false; } if(!piglit_check_gl_error(GL_NO_ERROR)) pass = false; piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); //glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } { glViewport(0, 0, static_cast<GLsizei>(WindowSize.x) * this->FramebufferScale, static_cast<GLsizei>(WindowSize.y) * this->FramebufferScale); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); glEnable(GL_FRAMEBUFFER_SRGB); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glUseProgram(ProgramName[program::RENDER]); glBindVertexArray(VertexArrayName[program::RENDER]); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glDrawArraysInstanced(GL_POINTS, 0, 8, 1); glDisable(GL_BLEND); } { glViewport(0, 0, static_cast<GLsizei>(WindowSize.x), static_cast<GLsizei>(WindowSize.y)); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDisable(GL_FRAMEBUFFER_SRGB); glUseProgram(ProgramName[program::SPLASH]); glActiveTexture(GL_TEXTURE0); glBindVertexArray(VertexArrayName[program::SPLASH]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); } return true; }
void model_loader_app::render(double t) { static const GLfloat background[] = { 0.0f, 0.0f, 0.0f, 1.0f }; static const GLfloat one = 1.0f; glClearBufferfv(GL_COLOR, 0, background); glClearBufferfv(GL_DEPTH, 0, &one); glUseProgram(program); glViewport(0, 0, info.windowWidth, info.windowHeight); // camera orientation POINT cursor; GetCursorPos(&cursor); float viewangle_x = float(cursor.x-info.windowWidth/2)/4.0; float viewangle_y = float(cursor.y-info.windowWidth/2)/4.0; if(mMesh) { glm::mat4 tmpMat = glm::rotate(glm::mat4(1.0), glm::radians(viewangle_y), glm::vec3(1.0, 0.0, 0.0)); tmpMat = glm::rotate(tmpMat, glm::radians(viewangle_x), glm::vec3(0.0, 1.0, 0.0)); tmpMat = glm::mat4(1.0f); glm::mat4 proj_matrix = glm::perspective(glm::radians(90.0f), (float)info.windowWidth / (float)info.windowHeight, 1.0f, 1000.0f); glm::mat4 mv_matrix = tmpMat * glm::translate(glm::mat4(1.0), glm::vec3(-mMesh->getSize()[0], 0.0, mMesh->getViewPos().z)+mMesh->getViewPos()); //mv_matrix = mv_matrix*glm::rotate<float>(glm::mat4(1.0f), glm::radians(t*30), glm::vec3(0.0, 1.0, 0.0)); glm::mat4 skeleton_matrix = glm::translate(mv_matrix, glm::vec3(mMesh->getSize()[0]*2, 0, 0)); glUseProgram(skeletonProgram); glUniformMatrix4fv(skeleton_proj_location, 1, GL_FALSE, &proj_matrix[0][0]); glUniformMatrix4fv(skeleton_mv_location, 1, GL_FALSE, &skeleton_matrix[0][0]); mMesh->draw(t, skeletonProgram, true); glUseProgram(program); glUniformMatrix4fv(proj_location, 1, GL_FALSE, &proj_matrix[0][0]); glUniformMatrix4fv(mv_location, 1, GL_FALSE, &mv_matrix[0][0]); mMesh->draw(t); bool bSkeleton = true; } glUseProgram(uiProgram); glUniform1i(glGetUniformLocation(uiProgram, "bleftpressed"), bLeftPressed ? 1:0); glUniform1i(glGetUniformLocation(uiProgram, "brightpressed"), bRightPressed?1:0); glDrawArrays(GL_TRIANGLES, 0, 30); }
virtual void render(double currentTime) { static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, black); glUseProgram(program[program_index]); // glUniform1f(0, sinf((float)currentTime) * 5.0f + 6.0f); glUniform1f(0, 5.3f); glDrawArrays(GL_PATCHES, 0, 4); }
static bool test_glClearBuffer(const GLenum drawbufs[4]) { int i; for (i = 0; i < 4; i++) glClearBufferfv(GL_COLOR, i, colors_all_different[i]); return probe_buffers(drawbufs, colors_all_different); }
void render(double t) { static const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, green); glUseProgram(program); glViewport(0, 0, info.windowWidth, info.windowHeight); //glUniform1f(0, (float)(sin(t) * 16.0 + 16.0)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }
void render_big_ubo_plus_uniform(double currentTime) { static const GLfloat blue[] = { 0.0f, 0.0f, 0.25f, 1.0f }; static const GLfloat one = 1.0f; float f = (float)currentTime * 0.3f; int i; int j; glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, blue); glClearBufferfv(GL_DEPTH, 0, &one); glUseProgram(ubo_plus_uniform_program); glBindBufferBase(GL_UNIFORM_BUFFER, 0, transform_ubo); transform_t * transform = (transform_t *)glMapBufferRange(GL_UNIFORM_BUFFER, 0, NUM_CUBES * sizeof(transform_t), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); for (i = 0; i < NUM_CUBES; i++) { float fi = 4.0f * (float)i / (float)NUM_CUBES; fi = 0.0f; transform[i].proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); transform[i].mv_matrix = vmath::translate(0.0f, 0.0f, -4.0f) * vmath::translate(sinf(5.1f * f + fi) * 1.0f, cosf(7.7f * f + fi) * 1.0f, sinf(6.3f * f + fi) * cosf(1.5f * f + fi) * 2.0f) * vmath::rotate(f * 45.0f + fi, 0.0f, 1.0f, 0.0f) * vmath::rotate(f * 81.0f + fi, 1.0f, 0.0f, 0.0f); } glUnmapBuffer(GL_UNIFORM_BUFFER); for (j = 0; j < NUM_PASSES; j++) { for (i = 0; i < NUM_CUBES; i++) { glUniform1i(uniforms.ubo_plus_uniform.transform_index, i); glDrawArraysInstancedBaseInstance(draw_triangles ? GL_TRIANGLES : GL_POINTS, 0, 36, 1, 0); } } }
void OGLIndexedDraw::Render(double time) { glm::vec4 bgColor(0.32f, 0.61f, 1.0f, 1.0f); glClear(GL_DEPTH_BUFFER_BIT); glClearBufferfv(GL_COLOR, 0, &bgColor[0]); glUniform1f(hDivLocation, heightDivider); glDrawElements(GL_TRIANGLE_STRIP, (int)indices.size(), GL_UNSIGNED_SHORT, nullptr); }
virtual void render(double currentTime) { int i; static const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f }; static const GLfloat one = 1.0f; glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, green); glClearBufferfv(GL_DEPTH, 0, &one); glUseProgram(program); vmath::mat4 proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUniformMatrix4fv(proj_location, 1, GL_FALSE, proj_matrix); #ifdef MANY_CUBES for (i = 0; i < 24; i++) { float f = (float)i + (float)currentTime * 0.3f; vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -20.0f) * vmath::rotate((float)currentTime * 45.0f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 21.0f, 1.0f, 0.0f, 0.0f) * vmath::translate(sinf(2.1f * f) * 2.0f, cosf(1.7f * f) * 2.0f, sinf(1.3f * f) * cosf(1.5f * f) * 2.0f); glUniformMatrix4fv(mv_location, 1, GL_FALSE, mv_matrix); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); } #else float f = (float)currentTime * 0.3f; vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -4.0f) * vmath::translate(sinf(2.1f * f) * 0.5f, cosf(1.7f * f) * 0.5f, sinf(1.3f * f) * cosf(1.5f * f) * 2.0f) * vmath::rotate((float)currentTime * 45.0f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 81.0f, 1.0f, 0.0f, 0.0f); glUniformMatrix4fv(mv_location, 1, GL_FALSE, mv_matrix); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); #endif }
void ShadowMapping::run(double time){ glEnable(GL_DEPTH_TEST); renderScene(true, time); if (params_["renderDepth"]){ static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 0.0f }; glClearBufferfv(GL_COLOR, 0, black); const GLfloat depth[] = {1.0f}; glClearBufferfv(GL_DEPTH, 0, depth); glDisable(GL_DEPTH_TEST); glBindVertexArray(nQuadVao_); glUseProgram(nDepthProgram_); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, nDepthDebug_); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }else{ renderScene(false, time); } }
void simpletri::do_render(double time) { static const GLfloat green[] = {0.0f, 0.25f, 0.0f, 1.0f}; glClearBufferfv(GL_COLOR, 0, green); glUseProgram(prog); glBindVertexArray(vao); // Note that we're drawing without a bound array buffer, which is allowed in core profile // http://renderingpipeline.com/2012/03/attribute-less-rendering/ // https://www.opengl.org/wiki_132/index.php/Vertex_Rendering glDrawArrays(GL_TRIANGLES, 0, 3); }
virtual void render(double currentTime) { static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, red); glUseProgram(program); glPointSize(40.0f); glDrawArrays(GL_POINTS, 0, 1); }
void display() { GLsizeiptr BufferSize = sizeof(glm::mat4); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::byte* Pointer = (glm::byte*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, BufferSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT); glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); { glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y + 45.0f, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x + 45.0f, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; *(glm::mat4*)Pointer = MVP; } { glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y + 45.0f, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x + 90.f + 45.0f, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; *(glm::mat4*)(Pointer + UniformBufferOffset) = MVP; } // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y)); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); glBindProgramPipeline(PipelineName); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glBindBufferRange(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, BufferSize); glBindBufferRange(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM1, BufferName[buffer::TRANSFORM], UniformBufferOffset, BufferSize); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL]); for(GLint i = 0; i < 2; ++i) { glProgramUniform1i(ProgramName, UniformInstance, i); glDrawElementsInstancedBaseVertexBaseInstance( GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } glf::swapBuffers(); }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::ortho(0.f, 256.f, 0.f, 256.f, 0.f, 16.f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindVertexArray(VertexArrayName); glActiveTexture(GL_TEXTURE0); glBindProgramPipeline(PipelineName[program::UINT]); { glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8UI])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8UI]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } glBindProgramPipeline(PipelineName[program::NORM]); { glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA32F])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA32F]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8_SNORM])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8_SNORM]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } return true; }
virtual void render(double currentTime) { static const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, green); glUseProgram(program); glPointSize(5.0f); glDrawArrays(GL_PATCHES, 0, 3); }
bool render() { glm::ivec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); //glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 8.0f); glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(5.0f)); *Pointer = Projection * this->view() * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glViewport(0, 0, WindowSize.x, WindowSize.y); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::DEPTH_MULTISAMPLE]); float Depth(1.0f); glClearBufferfv(GL_DEPTH , 0, &Depth); // Bind rendering objects glUseProgram(ProgramName[program::TEXTURE]); glUniformBlockBinding(ProgramName[program::TEXTURE], UniformTransform, semantic::uniform::TRANSFORM0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glBindVertexArray(VertexArrayName[program::TEXTURE]); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 2, 0); // Pass 2 glDisable(GL_DEPTH_TEST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glUseProgram(ProgramName[program::SPLASH]); glActiveTexture(GL_TEXTURE0); glBindVertexArray(VertexArrayName[program::SPLASH]); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]); glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); return true; }
void display() { // Update of the uniform buffer { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::perspectiveFov(45.f, 640.f, 480.f, 0.1f, 100.0f); //glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * View * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glBindProgramPipeline(PipelineName[program::COMPUTE]); glBindImageTexture(image::POSITION_INPUT, TextureName[texture::POSITION_INPUT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F); glBindImageTexture(image::TEXCOORD_INPUT, TextureName[texture::TEXCOORD_INPUT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F); glBindImageTexture(image::COLOR_INPUT, TextureName[texture::COLOR_INPUT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F); glBindImageTexture(image::POSITION_OUTPUT, TextureName[texture::POSITION_OUTPUT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); glBindImageTexture(image::TEXCOORD_OUTPUT, TextureName[texture::TEXCOORD_OUTPUT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); glBindImageTexture(image::COLOR_OUTPUT, TextureName[texture::COLOR_OUTPUT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glDispatchCompute(GLuint(VertexCount), 1, 1); glViewportIndexedf(0, 0, 0, GLfloat(Window.Size.x), GLfloat(Window.Size.y)); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]); glBindProgramPipeline(PipelineName[program::GRAPHICS]); glActiveTexture(GL_TEXTURE0 + glf::semantic::sampling::SAMPLER_DIFFUSE); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glActiveTexture(GL_TEXTURE0 + sampling::SAMPLER_POSITION); glBindTexture(GL_TEXTURE_BUFFER, TextureName[texture::POSITION_OUTPUT]); glActiveTexture(GL_TEXTURE0 + sampling::SAMPLER_TEXCOORD); glBindTexture(GL_TEXTURE_BUFFER, TextureName[texture::TEXCOORD_OUTPUT]); glActiveTexture(GL_TEXTURE0 + sampling::SAMPLER_COLOR); glBindTexture(GL_TEXTURE_BUFFER, TextureName[texture::COLOR_OUTPUT]); glBindVertexArray(VertexArrayName); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glDrawElementsInstancedBaseVertexBaseInstance( GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, GLF_BUFFER_OFFSET(0), 1, 0, 0); glf::swapBuffers(); }
void render(double currentTime) { const GLfloat bckColor[] = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat white[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, bckColor); glClearBufferfv(GL_DEPTH, 0, white); glBindTexture(GL_TEXTURE_1D, _texToon); glViewport(0, 0, info.windowWidth, info.windowHeight); vmath::mat4 proj = vmath::perspective(60.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); vmath::mat4 mv = vmath::translate(0.0f, 0.0f, -3.0f) * vmath::rotate((float)currentTime * 13.75f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 7.75f, 0.0f, 0.0f, 1.0f) * vmath::rotate((float)currentTime * 15.3f, 1.0f, 0.0f, 0.0f); glUniformMatrix4fv(mvLocation, 1, GL_FALSE, mv); glUniformMatrix4fv(projLocation, 1, GL_FALSE, proj); _object.render(); }
virtual void render(double currentTime) { static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 1.0f }; static const GLfloat one = 1.0f; glViewport(0, 0, info.windowWidth, info.windowHeight); glClearBufferfv(GL_COLOR, 0, black); glUseProgram(program); vmath::mat4 proj_matrix = vmath::perspective(50.0f, (float)info.windowWidth / (float)info.windowHeight, 0.1f, 1000.0f); glUniformMatrix4fv(proj_location, 1, GL_FALSE, proj_matrix); // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if (sample_shading) { glEnable(GL_SAMPLE_SHADING); glMinSampleShading(1.0f); } else { glDisable(GL_SAMPLE_SHADING); } #ifdef MANY_CUBES for (i = 0; i < 24; i++) { float f = (float)i + (float)currentTime * 0.3f; vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -20.0f) * vmath::rotate((float)currentTime * 45.0f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 21.0f, 1.0f, 0.0f, 0.0f) * vmath::translate(sinf(2.1f * f) * 2.0f, cosf(1.7f * f) * 2.0f, sinf(1.3f * f) * cosf(1.5f * f) * 2.0f); glUniformMatrix4fv(mv_location, 1, GL_FALSE, mv_matrix); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); } #else float f = (float)currentTime * 0.3f; currentTime = 3.15; vmath::mat4 mv_matrix = vmath::translate(0.0f, 0.0f, -4.0f) * /*vmath::translate(sinf(2.1f * f) * 0.5f, cosf(1.7f * f) * 0.5f, sinf(1.3f * f) * cosf(1.5f * f) * 2.0f) **/ vmath::rotate((float)currentTime * 45.0f, 0.0f, 1.0f, 0.0f) * vmath::rotate((float)currentTime * 81.0f, 1.0f, 0.0f, 0.0f); glUniformMatrix4fv(mv_location, 1, GL_FALSE, mv_matrix); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); #endif }