void blinnphong_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_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[0].specular_power, 30.0f); glUniform3fv(uniforms[0].specular_albedo, 1, vmath::vec3(1.0f)); object.render(); #endif }