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 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); }
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(); }