void Options::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect) { CL_BlendMode blendmode; blendmode.enable_blending(false); gc.set_blend_mode(blendmode); CL_Draw::fill(gc, update_rect, CL_Colorf(0.4f, 0.4f, 0.6f, 0.0f)); gc.reset_blend_mode(); }
CL_GraphicContext CL_GUIWindowManagerProvider_System::begin_paint(CL_GUITopLevelWindow *handle, const CL_Rect &update_region) { CL_GraphicContext &gc = window_map[handle]->window.get_gc(); gc.set_map_mode(cl_map_2d_upper_left); // TODO: Is gc.set_cliprect() required - Should the components clip instead? gc.set_cliprect(update_region); CL_BlendMode blendmode; blendmode.enable_blending(true); gc.set_blend_mode(blendmode); return gc; }
void Graphics::setBlendMode(BlendMode blendMode) { CL_BlendMode mode; switch (blendMode) { case BLEND_DISABLE: mode.enable_blending(false); break; case BLEND_ALPHA: mode.set_blend_function(cl_blend_one, cl_blend_one_minus_src_alpha, cl_blend_one, cl_blend_one_minus_src_alpha); break; case BLEND_ADD: mode.set_blend_function(cl_blend_one, cl_blend_one, cl_blend_one, cl_blend_one); break; case BLEND_SUBTRACT: mode.set_blend_equation(cl_blend_equation_reverse_subtract, cl_blend_equation_reverse_subtract); mode.set_blend_function(cl_blend_one, cl_blend_one, cl_blend_one, cl_blend_one); break; case BLEND_MULTIPLY: mode.set_blend_function(cl_blend_dest_color, cl_blend_one_minus_src_alpha, cl_blend_dest_color, cl_blend_one_minus_src_alpha); break; } mBlendMode = blendMode; mWindow.get_gc().set_blend_mode(mode); }
// The start of the Application int App::start(const std::vector<CL_String> &args) { CL_OpenGLWindowDescription win_desc; //win_desc.set_version(3, 2, false); win_desc.set_allow_resize(true); win_desc.set_title("Point Sprite Example"); win_desc.set_size(CL_Size( 800, 480 ), false); CL_DisplayWindow window(win_desc); CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); CL_String theme; if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw CL_Exception("No themes found"); CL_GUIWindowManagerTexture wm(window); CL_GUIManager gui(wm, theme); CL_GraphicContext gc = window.get_gc(); // Deleted automatically by the GUI Options *options = new Options(gui, CL_Rect(0, 0, gc.get_size())); CL_Image image_grid(gc, "../Blend/Resources/grid.png"); CL_Texture texture_particle(gc, "Resources/particle.png"); float grid_width = (float) image_grid.get_width(); float grid_height = (float) image_grid.get_height(); grid_space = (float) (image_grid.get_width()); setup_particles(); CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, text_shader_vertex); if(!vertex_shader.compile()) { throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, text_shader_fragment); if(!fragment_shader.compile()) { throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } CL_ProgramObject program_object(gc); program_object.attach(vertex_shader); program_object.attach(fragment_shader); program_object.bind_attribute_location(0, "InPosition"); program_object.bind_attribute_location(1, "InColor"); if (!program_object.link()) { throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log())); } options->request_repaint(); unsigned int time_last = CL_System::get_time(); while (!quit) { unsigned int time_now = CL_System::get_time(); float time_diff = (float) (time_now - time_last); time_last = time_now; wm.process(); wm.draw_windows(gc); int num_particles = options->num_particles; if (num_particles > max_particles) num_particles = max_particles; move_particles(time_diff, num_particles); const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; // Draw the grid image_grid.draw(gc, grid_xpos, grid_ypos); if (num_particles > 0) { std::vector<CL_Vec2f> positions; std::vector<CL_Vec4f> colors; positions.resize(num_particles); colors.resize(num_particles); for (int cnt=0; cnt<num_particles; cnt++) { positions[cnt] = CL_Vec2f(grid_xpos + particles[cnt].xpos, grid_ypos + particles[cnt].ypos); switch (cnt % 3) { case 0: colors[cnt] = CL_Vec4f(1.0f, 0.0f, 0.0f, 1.0f); break; case 1: colors[cnt] = CL_Vec4f(0.0f, 1.0f, 0.0f, 1.0f); break; case 2: colors[cnt] = CL_Vec4f(0.0f, 0.0f, 1.0f, 1.0f); break; } }; CL_BlendMode blend; blend.enable_blending(true); blend.set_blend_function(cl_blend_src_alpha, cl_blend_one, cl_blend_src_alpha, cl_blend_one); gc.set_blend_mode(blend); CL_Pen pen; pen.enable_point_sprite(true); pen.set_point_size(options->point_size); pen.set_point_sprite_origin(cl_point_sprite_origin_upper_left); gc.set_pen(pen); program_object.set_uniform1i("Texture0", 0); gc.set_texture(0, texture_particle); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, &positions[0]); prim_array.set_attributes(1, &colors[0]); gc.set_program_object(program_object); gc.draw_primitives(cl_points, num_particles, prim_array); gc.reset_program_object(); gc.reset_texture(0); gc.reset_blend_mode(); gc.reset_pen(); } window.flip(1); CL_KeepAlive::process(); } return 0; }