void SineScroll::draw_demo(clan::Canvas &canvas, int delta_ms) { clan::Rectf rect(0.0f, 0.0f, clan::Sizef(300.0f, 300.0f)); clan::Rectf texture_unit1_coords(0.0f, 0.0f, 1.0f, 1.0f); std::vector<clan::Vec2f> dest_position; std::vector<clan::Vec2f> texture_position; int dest_width = canvas.get_width(); if (dest_width <=0) return; int dest_xoffset = 0; int gc_height = canvas.get_height(); int dest_height = 128; int dest_start_y = (gc_height - dest_height) / 2; float texture_y_start = 0.15f; // Set to 0.0f for start and 1.0f for end to use the entire texture float texture_y_end = 0.5f; dest_position.reserve(dest_width * 2); texture_position.reserve(dest_width * 2); float sin_amplitude = ( (float) gc_height / 4.0f); if (delta_ms > 1000) // Limit to 1 second to frame delta_ms = 1000; sin_offset += ((float) delta_ms / 1000.0f); if (sin_offset > (2.0f * clan::PI)) sin_offset -= clan::PI * 2.0f; for (int cnt=0; cnt < dest_width; cnt++) { float y_offset = sin_amplitude * sin( sin_offset + (float) cnt / 100.0f ) ; dest_position.push_back( clan::Vec2f( cnt, dest_start_y + y_offset ) ); dest_position.push_back( clan::Vec2f( cnt, dest_start_y + dest_height + y_offset) ); texture_position.push_back( clan::Vec2f( (float) cnt / dest_width, texture_y_start ) ); texture_position.push_back( clan::Vec2f( (float) cnt / dest_width, texture_y_end ) ); } canvas.draw_lines(&dest_position[0], &texture_position[0], dest_position.size(), texture); }
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 HSV::render_texture(CL_GraphicContext &gc, CL_ProgramObject &program, CL_Texture &texture, float hue_offset) { CL_Rectf rect(0.0f, 0.0f, (float)gc.get_width(), (float)gc.get_height()); CL_Rectf texture_unit1_coords(0.0f, 0.0f, 1.0f, 1.0f); CL_Vec2f positions[6] = { CL_Vec2f(rect.left, rect.top), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.top), CL_Vec2f(rect.left, rect.bottom), CL_Vec2f(rect.right, rect.bottom) }; CL_Vec2f tex1_coords[6] = { CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.top), CL_Vec2f(texture_unit1_coords.left, texture_unit1_coords.bottom), CL_Vec2f(texture_unit1_coords.right, texture_unit1_coords.bottom) }; CL_PrimitivesArray primarray(gc); primarray.set_attributes(0, positions); primarray.set_attribute(1, CL_Vec1f(hue_offset)); primarray.set_attributes(2, tex1_coords); gc.set_texture(0, texture); gc.set_program_object(program, cl_program_matrix_modelview_projection); gc.draw_primitives(cl_triangles, 6, primarray); gc.reset_program_object(); gc.reset_texture(0); }
void GUI::draw() { std::vector<clan::GUIWindowManagerTextureWindow> windows = wm.get_windows(); std::vector<clan::GUIWindowManagerTextureWindow>::size_type index, size; size = windows.size(); for (index = 0; index < size; index++) { clan::GUIWindowManagerTextureWindow texture_window = windows[index]; Component3D *component3d = dynamic_cast<Component3D *> (texture_window.get_toplevel_component()); if (!component3d) { // Note, it may be possible to handle popup windows at this point continue; } component3d->resultant_matrix = clan::Mat4f::multiply(canvas.get_modelview(), component3d->object_matrix); canvas.push_modelview(); canvas.mult_modelview(component3d->object_matrix); component3d->resultant_matrix = clan::Mat4f::multiply(app->get_projection_matrix(), canvas.get_modelview()); // Translate 2D coords to 3D coords //canvas.mult_translate(-1.0f, 1.0f); canvas.mult_scale(2.0f/canvas.get_width(), -2.0f/canvas.get_height()); // Prepare to draw clan::Subtexture subtexture = texture_window.get_texture(); clan::Texture2D texture = subtexture.get_texture(); clan::Rect window_geometry = texture_window.get_geometry(); clan::Rect subtexture_geometry = subtexture.get_geometry(); clan::Rectf texture_unit1_coords(subtexture_geometry); // Note, we ignore the GUI position, and simply center the window clan::Size window_size = subtexture_geometry.get_size(); clan::Rectf rect(-window_size.width/2.0f, -window_size.height/2.0f, clan::Sizef(window_size)); clan::Vec2f positions[6] = { clan::Vec2f(rect.left, rect.top), clan::Vec2f(rect.right, rect.top), clan::Vec2f(rect.left, rect.bottom), clan::Vec2f(rect.right, rect.top), clan::Vec2f(rect.left, rect.bottom), clan::Vec2f(rect.right, rect.bottom) }; float texture_width = (float) texture.get_width(); float texture_height = (float) texture.get_height(); float texel_centre = 0.375f; float src_left = (texture_unit1_coords.left + texel_centre) / texture_width; float src_right = (texture_unit1_coords.right + texel_centre) / texture_width; float src_top = (texture_unit1_coords.top + texel_centre) / texture_height; float src_bottom = (texture_unit1_coords.bottom + texel_centre) / texture_height; clan::Vec2f tex1_coords[6] = { clan::Vec2f(src_left, src_top), clan::Vec2f(src_right, src_top), clan::Vec2f(src_left, src_bottom), clan::Vec2f(src_right, src_top), clan::Vec2f(src_left, src_bottom), clan::Vec2f(src_right, src_bottom) }; canvas.fill_triangles(positions, tex1_coords, 6, texture, component3d->component_color); canvas.pop_modelview(); } }