void App::render(GraphicContext &gc) { gc.clear(Colorf(0.0f, 0.0f, 0.0f, 1.0f)); Rect viewport_rect(0, 0, Size(gc.get_width(), gc.get_height())); gc.set_viewport(viewport_rect); gc.clear_depth(1.0f); Mat4f modelview_matrix = scene.gs->camera_modelview; scene.Draw(modelview_matrix, gc); gc.reset_program_object(); }
void App::calculate_matricies(GraphicContext &gc) { scene.gs->camera_projection = Mat4f::perspective(45.0f, ((float) gc.get_width()) / ((float) gc.get_height()), 0.1f, 1000.0f, handed_left, clip_negative_positive_w); float ortho_size = 60.0f / 2.0f; scene.gs->light_projection = Mat4f::ortho(-ortho_size, ortho_size, -ortho_size, ortho_size, 0.1f, 1000.0f, handed_left, clip_negative_positive_w); scene.gs->camera_modelview = Mat4f::identity(); camera->GetWorldMatrix(scene.gs->camera_modelview); scene.gs->camera_modelview.inverse(); scene.gs->light_modelview = Mat4f::identity(); light_distant->GetWorldMatrix(scene.gs->light_modelview); scene.gs->light_modelview.inverse(); }
void HSV::render_texture(Canvas &canvas, ProgramObject &program, Texture &texture, float hue_offset) { GraphicContext gc = canvas.get_gc(); Rectf rect(0.0f, 0.0f, (float)gc.get_width(), (float)gc.get_height()); Rectf texture_unit1_coords(0.0f, 0.0f, 1.0f, 1.0f); Vec2f positions[6] = { Vec2f(rect.left, rect.top), Vec2f(rect.right, rect.top), Vec2f(rect.left, rect.bottom), Vec2f(rect.right, rect.top), Vec2f(rect.left, rect.bottom), Vec2f(rect.right, rect.bottom) }; Vec2f tex1_coords[6] = { Vec2f(texture_unit1_coords.left, texture_unit1_coords.top), Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), Vec2f(texture_unit1_coords.right, texture_unit1_coords.bottom) }; PrimitivesArray primarray(gc); VertexArrayVector<Vec2f> gpu_positions = VertexArrayVector<Vec2f>(gc, positions, 6); VertexArrayVector<Vec2f> gpu_tex1_coords = VertexArrayVector<Vec2f>(gc, tex1_coords, 6); primarray.set_attributes(0, gpu_positions); primarray.set_attributes(1, gpu_tex1_coords); ProgramUniforms buffer; buffer.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_modelview(); buffer.HueOffset0 = hue_offset; UniformVector<ProgramUniforms> uniform_vector(gc, &buffer, 1); gc.set_uniform_buffer(0, uniform_vector); gc.set_texture(0, texture); gc.set_program_object(program); gc.draw_primitives(type_triangles, 6, primarray); gc.reset_program_object(); gc.reset_texture(0); }
// The start of the Application int App::start(const std::vector<std::string> &args) { try { DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("HDR Example"); win_desc.set_size(Size( 600, 630 ), false); DisplayWindow window(win_desc); Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); GraphicContext gc = window.get_gc(); // Load and link shaders ProgramObject shader = ProgramObject::load(gc, "Resources/vertex_shader.glsl", "Resources/fragment_shader.glsl"); shader.bind_attribute_location(0, "Position"); shader.bind_attribute_location(2, "TexCoord0"); if (!shader.link()) throw Exception("Unable to link shader program: Error:" + shader.get_info_log()); const float dynamic_range_start = -1.5f; const float dynamic_range_end = 1.5f; const Size image_size(gc.get_width() - 64, 128); Texture image_rgb32f = create_rgb32f(gc, image_size, dynamic_range_start, dynamic_range_end); Font font(gc, "Tahoma", 20); clan::ubyte64 time_last = System::get_time(); bool direction = false; while (!quit) { clan::ubyte64 time_now = System::get_time(); time_delta = ((float) time_now - time_last) / 1000.0f; time_last = time_now; if (direction) { color_offset.r += time_delta * 1.0f; if (color_offset.r > 2.0f) { color_offset.r = 2.0f; direction = false; } } else { color_offset.r -= time_delta * 1.0f; if (color_offset.r < -2.0f) { color_offset.r = -2.0f; direction = true; } } color_offset.g = color_offset.r; color_offset.b = color_offset.r; gc.clear(Colorf(0.2f,0.2f,0.5f)); font.draw_text(gc, 32, 50, "Showing Texture RGB values from " + StringHelp::float_to_text(dynamic_range_start) + " to " + StringHelp::float_to_text(dynamic_range_end)); draw_image(gc, image_rgb32f, 32.0f, 100.0f, shader, Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); font.draw_text(gc, 32, 350, "Showing Texture with an offset to the floating point color component"); draw_image(gc, image_rgb32f, 32.0f, 400.0f, shader, color_offset); KeepAlive::process(0); window.flip(1); } } catch(Exception &exception) { // Create a console window for text-output if not available ConsoleWindow console("Console", 80, 160); Console::write_line("Exception caught: " + exception.get_message_and_stack_trace()); console.display_close_message(); return -1; } return 0; }