// The start of the Application int App::start(const std::vector<std::string> &args) { clan::DisplayWindowDescription 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(clan::Size( 800, 480 ), false); clan::DisplayWindow window(win_desc); clan::SlotContainer cc; cc.connect(window.sig_window_close(), clan::bind_member(this, &App::on_window_close)); cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &App::on_input_up)); std::string theme; if (clan::FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (clan::FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw clan::Exception("No themes found"); clan::GUIWindowManagerTexture wm(window); clan::GUIManager gui(wm, theme); clan::Canvas canvas(window); // Deleted automatically by the GUI Options *options = new Options(gui, clan::Rect(0, 0, canvas.get_size())); clan::Image image_grid(canvas, "../Blend/Resources/grid.png"); clan::Texture2D texture_particle(canvas, "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(); clan::ShaderObject vertex_shader(canvas, clan::shadertype_vertex, text_shader_vertex); if(!vertex_shader.compile()) { throw clan::Exception(clan::string_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } clan::ShaderObject fragment_shader(canvas, clan::shadertype_fragment, text_shader_fragment); if(!fragment_shader.compile()) { throw clan::Exception(clan::string_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } clan::ProgramObject program_object(canvas); 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 clan::Exception(clan::string_format("Unable to link program object: %1", program_object.get_info_log())); } program_object.set_uniform1i("Texture0", 0); options->request_repaint(); clan::BlendStateDescription blend_state_desc; blend_state_desc.enable_blending(true); blend_state_desc.set_blend_function(clan::blend_src_alpha, clan::blend_one, clan::blend_src_alpha, clan::blend_one); clan::BlendState blend_state(canvas, blend_state_desc); clan::GameTime game_time; while (!quit) { game_time.update(); wm.process(); wm.draw_windows(canvas); int num_particles = options->num_particles; if (num_particles > max_particles) num_particles = max_particles; move_particles(game_time.get_time_elapsed(), num_particles); const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; // Draw the grid image_grid.draw(canvas, grid_xpos, grid_ypos); if (num_particles > 0) { std::vector<clan::Vec2f> positions; std::vector<clan::Colorf> colors; positions.resize(num_particles); colors.resize(num_particles); for (int cnt=0; cnt<num_particles; cnt++) { positions[cnt] = clan::Vec2f(grid_xpos + particles[cnt].xpos, grid_ypos + particles[cnt].ypos); switch (cnt % 3) { case 0: colors[cnt] = clan::Colorf(1.0f, 0.0f, 0.0f, 1.0f); break; case 1: colors[cnt] = clan::Colorf(0.0f, 1.0f, 0.0f, 1.0f); break; case 2: colors[cnt] = clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f); break; } }; canvas.flush(); clan::GraphicContext gc = canvas.get_gc(); canvas.set_blend_state(blend_state); clan::RasterizerStateDescription raster_state_desc; raster_state_desc.set_point_size(options->point_size); raster_state_desc.set_point_sprite_origin(clan::origin_upper_left); clan::RasterizerState raster_state(canvas, raster_state_desc); canvas.set_rasterizer_state(raster_state); clan::PrimitivesArray primarray(gc); clan::VertexArrayVector<clan::Vec2f> gpu_positions = clan::VertexArrayVector<clan::Vec2f>(gc, &positions[0], positions.size()); clan::VertexArrayVector<clan::Colorf> gpu_colors = clan::VertexArrayVector<clan::Colorf>(gc, &colors[0], colors.size()); primarray.set_attributes(0, gpu_positions); primarray.set_attributes(1, gpu_colors); ProgramUniforms buffer; buffer.cl_ModelViewProjectionMatrix = canvas.get_projection() * canvas.get_modelview(); clan::UniformVector<ProgramUniforms> uniform_vector(gc, &buffer, 1); gc.set_uniform_buffer(0, uniform_vector); gc.set_texture(0, texture_particle); gc.set_program_object(program_object); gc.draw_primitives(clan::type_points, num_particles, primarray); gc.reset_program_object(); gc.reset_texture(0); gc.reset_blend_state(); gc.reset_rasterizer_state(); } window.flip(1); clan::KeepAlive::process(); } return 0; }
// The start of the Application int App::start(const std::vector<CL_String> &args) { CL_DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_stencil_size(8); // For simplicity this example does not use the depth components //win_desc.set_depth_size(16); win_desc.set_title("Stencil Example"); win_desc.set_size(CL_Size( 900, 570 ), 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_Image image_ball(gc, "../Blend/Resources/ball.png"); grid_space = (float) (image_grid.get_width() - image_ball.get_width()); setup_balls(); CL_BufferControl buffer_control; CL_BufferControl default_buffer_control; options->request_repaint(); CL_Font font(gc, "Tahoma", 24); 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_balls = options->num_balls; if (num_balls > max_balls) num_balls = max_balls; if (options->is_moveballs_set) move_balls(time_diff, num_balls); gc.clear_stencil(0); // Draw the grid const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; image_grid.draw(gc, grid_xpos, grid_ypos); // Draw the circle onto the stencil if (options->is_circle_set) { buffer_control.enable_logic_op(false); buffer_control.enable_stencil_test(true); buffer_control.set_stencil_compare_func(cl_comparefunc_always, cl_comparefunc_always); buffer_control.set_stencil_fail(cl_stencil_incr_wrap, cl_stencil_incr_wrap); buffer_control.set_stencil_pass_depth_fail(cl_stencil_incr_wrap, cl_stencil_incr_wrap); buffer_control.set_stencil_pass_depth_pass(cl_stencil_incr_wrap, cl_stencil_incr_wrap); buffer_control.enable_color_write(false); buffer_control.enable_depth_write(false); buffer_control.enable_depth_test(false); gc.set_buffer_control(buffer_control); CL_Draw::circle(gc, grid_xpos + image_grid.get_width()/2, grid_ypos + image_grid.get_height()/2, 100, CL_Colorf::white); } buffer_control.enable_color_write(true); buffer_control.enable_logic_op(false); buffer_control.enable_stencil_test(true); buffer_control.set_stencil_compare_func(options->compare_function, options->compare_function); buffer_control.set_stencil_compare_reference(options->compare_reference, options->compare_reference); buffer_control.set_stencil_write_mask(255, 255); buffer_control.set_stencil_compare_mask(255, 255); buffer_control.set_stencil_fail(options->stencil_fail, options->stencil_fail);; // Note, depth testing disabled for this example buffer_control.set_stencil_pass_depth_fail(options->stencil_pass, options->stencil_pass); buffer_control.set_stencil_pass_depth_pass(options->stencil_pass, options->stencil_pass); buffer_control.enable_depth_write(false); buffer_control.enable_depth_test(false); gc.set_buffer_control(buffer_control); for (int cnt=0; cnt<num_balls; cnt++) { image_ball.draw(gc, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos); } gc.set_buffer_control(default_buffer_control); CL_Image stencil_image = get_stencil(gc, CL_Rect(grid_xpos, grid_ypos, image_grid.get_width(), image_grid.get_height())); const float stencil_image_xpos = 400.0f; const float stencil_image_ypos = 30.0f; const float stencil_image_scale = 0.5f; stencil_image.set_scale(stencil_image_scale, stencil_image_scale); stencil_image.draw(gc, stencil_image_xpos, stencil_image_ypos); CL_Draw::box(gc, CL_Rectf(stencil_image_xpos, stencil_image_ypos, CL_Sizef(stencil_image.get_width() * stencil_image_scale, stencil_image.get_height() * stencil_image_scale)), CL_Colorf::white); font.draw_text(gc, stencil_image_xpos, stencil_image_ypos - 4.0f, "Stencil", CL_Colorf::black); // Add a note to avoid confusion font.draw_text(gc, 10.0f, 500.0, "(This example does not use the stencil depth buffer comparison or the stencil bitmask)", CL_Colorf::black); window.flip(1); CL_KeepAlive::process(); } return 0; }
// 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; }
// The start of the Application int App::start(const std::vector<std::string> &args) { clan::DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("MapMode Example"); win_desc.set_size(clan::Size( 800, 480 ), false); clan::DisplayWindow window(win_desc); clan::SlotContainer cc; cc.connect(window.sig_window_close(), clan::bind_member(this, &App::on_window_close)); cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &App::on_input_up)); std::string theme; if (clan::FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (clan::FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw clan::Exception("No themes found"); clan::GUIWindowManagerTexture wm(window); clan::GUIManager gui(wm, theme); clan::Canvas canvas(window); // Deleted automatically by the GUI Options *options = new Options(gui, clan::Rect(0, 0, canvas.get_size())); clan::Image image_grid(canvas, "../Blend/Resources/grid.png"); clan::Image image_ball(canvas, "../Blend/Resources/ball.png"); float grid_width = (float) image_grid.get_width(); float grid_height = (float) image_grid.get_height(); grid_space = (float) (image_grid.get_width() - image_ball.get_width()); setup_balls(); options->request_repaint(); clan::GameTime game_time; while (!quit) { game_time.update(); wm.process(); wm.draw_windows(canvas); int num_balls = options->num_balls; if (num_balls > max_balls) num_balls = max_balls; if (options->is_moveballs_set) move_balls(game_time.get_time_elapsed(), num_balls); canvas.set_map_mode(options->current_mapmode); const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; if (options->current_mapmode == clan::map_user_projection) { clan::Sizef area_size(grid_width + (grid_xpos * 2.0f), grid_height + (grid_ypos * 2.0f)); set_user_projection(canvas, area_size, options); } // Draw the grid image_grid.draw(canvas, grid_xpos, grid_ypos); for (int cnt=0; cnt<num_balls; cnt++) { image_ball.draw(canvas, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos); } canvas.set_modelview(clan::Mat4f::identity()); canvas.set_projection(clan::Mat4f::identity()); canvas.set_map_mode(clan::map_2d_upper_left); canvas.get_gc().set_viewport(canvas.get_size()); window.flip(1); clan::KeepAlive::process(); } return 0; }
// The start of the Application int App::start(const std::vector<std::string> &args) { clan::DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("Perlin Noise Example"); win_desc.set_size(clan::Size( 800, 520 ), false); clan::DisplayWindow window(win_desc); clan::SlotContainer cc; cc.connect(window.sig_window_close(), clan::bind_member(this, &App::on_window_close)); cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &App::on_input_up)); std::string theme; if (clan::FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (clan::FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw clan::Exception("No themes found"); clan::Canvas canvas(window); clan::GUIWindowManagerTexture wm(window); clan::GUIManager gui(wm, theme); // Deleted automatically by the GUI Options *options = new Options(gui, canvas.get_size()); clan::Image image_grid(canvas, "../../Display_Render/Blend/Resources/grid.png"); image_grid.set_color(clan::Colorf(0.4f, 0.4f, 1.0f, 1.0f)); clan::PerlinNoise noise; clan::Image noise_image; clan::TextureFormat last_sized_format = clan::tf_rgb8; float last_amplitude = 0.0f; int last_width = 0; int last_height = 0; int last_octaves = 0 ; float last_start_x = 0.0f; float last_length_x = 0.0f; float last_start_y = 0.0f; float last_length_y = 0.0f; float last_position_z = 0.0f; float last_position_w = 0.0f; PerlinDimension last_dimension = perlin_2d; bool last_is_normals_set = false; while (!quit) { wm.process(); wm.draw_windows(canvas); bool changed_flag = false; if (last_dimension != options->dimension) { changed_flag = true; last_dimension = options->dimension; } if (last_is_normals_set != options->is_normals_set) { changed_flag = true; last_is_normals_set = options->is_normals_set; } if (last_sized_format != options->sized_format) { changed_flag = true; last_sized_format = options->sized_format; noise.set_format(last_sized_format); } if (last_amplitude != options->amplitude) { changed_flag = true; last_amplitude = options->amplitude; noise.set_amplitude(last_amplitude); } if (last_width != options->width) { changed_flag = true; last_width = options->width; noise.set_size(last_width, last_height); } if (last_height != options->height) { changed_flag = true; last_height = options->height; noise.set_size(last_width, last_height); } if (last_octaves != options->octaves) { changed_flag = true; last_octaves = options->octaves; noise.set_octaves(last_octaves); } if (last_start_x != options->start_x) { changed_flag = true; last_start_x = options->start_x; } if (last_length_x != options->length_x) { changed_flag = true; last_length_x = options->length_x; } if (last_start_y != options->start_y) { changed_flag = true; last_start_y = options->start_y; } if (last_length_y != options->length_y) { changed_flag = true; last_length_y = options->length_y; } if (last_position_z != options->position_z) { changed_flag = true; last_position_z = options->position_z; } if (last_position_w != options->position_w) { changed_flag = true; last_position_w = options->position_w; } if (changed_flag) { clan::PixelBuffer pbuff; switch (last_dimension) { case perlin_1d: pbuff = noise.create_noise1d(last_start_x, last_start_x + last_length_x); break; case perlin_2d: pbuff = noise.create_noise2d(last_start_x, last_start_x + last_length_x, last_start_y, last_start_y + last_length_y); break; case perlin_3d: pbuff = noise.create_noise3d(last_start_x, last_start_x + last_length_x, last_start_y, last_start_y + last_length_y, last_position_z); break; case perlin_4d: default: pbuff = noise.create_noise4d(last_start_x, last_start_x + last_length_x, last_start_y, last_start_y + last_length_y, last_position_z, last_position_w); break; } if (last_is_normals_set) pbuff = convert_to_normalmap(pbuff); pbuff = pbuff.to_format(clan::tf_rgba8); // Required for clanD3D noise_image = clan::Image(canvas, pbuff, pbuff.get_size()); } image_grid.draw(canvas, 32, 32); noise_image.draw(canvas, 33, 33); window.flip(1); clan::KeepAlive::process(); } return 0; }
// The start of the Application int App::start(const std::vector<std::string> &args) { clan::DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_stencil_size(8); // For simplicity this example does not use the depth components //win_desc.set_depth_size(16); win_desc.set_title("Stencil Example"); win_desc.set_size(clan::Size( 900, 570 ), false); clan::DisplayWindow window(win_desc); clan::Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); clan::Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); std::string theme; if (clan::FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (clan::FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw clan::Exception("No themes found"); clan::GUIWindowManagerTexture wm(window); clan::GUIManager gui(wm, theme); clan::Canvas canvas(window); // Deleted automatically by the GUI Options *options = new Options(gui, clan::Rect(0, 0, canvas.get_size())); clan::Image image_grid(canvas, "../Blend/Resources/grid.png"); clan::Image image_ball(canvas, "../Blend/Resources/ball.png"); grid_space = (float) (image_grid.get_width() - image_ball.get_width()); setup_balls(); options->request_repaint(); clan::Font font(canvas, "Tahoma", 20); clan::BlendStateDescription blend_desc; blend_desc.enable_color_write(false, false, false, false); clan::BlendState blend_state_no_color_write(canvas, blend_desc); clan::GameTime game_time; while (!quit) { game_time.update(); wm.process(); wm.draw_windows(canvas); int num_balls = options->num_balls; if (num_balls > max_balls) num_balls = max_balls; if (options->is_moveballs_set) move_balls(game_time.get_time_elapsed(), num_balls); canvas.clear_stencil(0); // Draw the grid const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; image_grid.draw(canvas, grid_xpos, grid_ypos); clan::DepthStencilStateDescription stencil_desc; // Draw the circle onto the stencil if (options->is_circle_set) { stencil_desc.enable_stencil_test(true); stencil_desc.set_stencil_compare_front(clan::compare_always, 255, 255); stencil_desc.set_stencil_compare_back(clan::compare_always, 255, 255); stencil_desc.set_stencil_op_front(clan::stencil_incr_wrap, clan::stencil_incr_wrap, clan::stencil_incr_wrap); stencil_desc.set_stencil_op_back(clan::stencil_incr_wrap, clan::stencil_incr_wrap, clan::stencil_incr_wrap); stencil_desc.enable_depth_write(false); stencil_desc.enable_depth_test(false); clan::DepthStencilState stencil_state(canvas, stencil_desc); canvas.set_depth_stencil_state(stencil_state); canvas.set_blend_state(blend_state_no_color_write); canvas.fill_circle(grid_xpos + image_grid.get_width()/2, grid_ypos + image_grid.get_height()/2, 100, clan::Colorf::white); canvas.reset_blend_state(); } stencil_desc.enable_stencil_test(true); stencil_desc.set_stencil_compare_front(options->compare_function, options->compare_reference, 255); stencil_desc.set_stencil_compare_back(options->compare_function, options->compare_reference, 255); stencil_desc.set_stencil_op_front(options->stencil_fail, options->stencil_pass, options->stencil_pass); stencil_desc.set_stencil_op_back(options->stencil_fail, options->stencil_pass, options->stencil_pass); // Note, depth testing disabled for this example stencil_desc.enable_depth_write(false); stencil_desc.enable_depth_test(false); clan::BlendState blend_state(canvas, blend_desc); clan::DepthStencilState stencil_state(canvas, stencil_desc); canvas.set_depth_stencil_state(stencil_state); for (int cnt=0; cnt<num_balls; cnt++) { image_ball.draw(canvas, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos); } canvas.reset_depth_stencil_state(); clan::Image stencil_image = get_stencil(canvas, clan::Rect(grid_xpos, grid_ypos, image_grid.get_width(), image_grid.get_height())); const float stencil_image_xpos = 400.0f; const float stencil_image_ypos = 30.0f; const float stencil_image_scale = 0.5f; stencil_image.set_scale(stencil_image_scale, stencil_image_scale); stencil_image.draw(canvas, stencil_image_xpos, stencil_image_ypos); canvas.draw_box(clan::Rectf(stencil_image_xpos, stencil_image_ypos, clan::Sizef(stencil_image.get_width() * stencil_image_scale, stencil_image.get_height() * stencil_image_scale)), clan::Colorf::white); font.draw_text(canvas, stencil_image_xpos, stencil_image_ypos - 4.0f, "Stencil", clan::Colorf::black); // Add a note to avoid confusion font.draw_text(canvas, 10.0f, 500.0, "(This example does not use the stencil depth buffer comparison or the stencil bitmask)", clan::Colorf::black); window.flip(1); clan::KeepAlive::process(); } return 0; }
// The start of the Application int App::start(const std::vector<CL_String> &args) { CL_DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("MapMode 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_Image image_ball(gc, "../Blend/Resources/ball.png"); float grid_width = (float) image_grid.get_width(); float grid_height = (float) image_grid.get_height(); grid_space = (float) (image_grid.get_width() - image_ball.get_width()); setup_balls(); 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_balls = options->num_balls; if (num_balls > max_balls) num_balls = max_balls; if (options->is_moveballs_set) move_balls(time_diff, num_balls); gc.set_map_mode(options->current_mapmode); const float grid_xpos = 10.0f; const float grid_ypos = 10.0f; if (options->current_mapmode == cl_user_projection) { CL_Sizef area_size(grid_width + (grid_xpos * 2.0f), grid_height + (grid_ypos * 2.0f)); set_user_projection(gc, area_size, options); } // Draw the grid image_grid.draw(gc, grid_xpos, grid_ypos); gc.flush_batcher(); // <--- Fix me, this should not be required for cl_user_projection for (int cnt=0; cnt<num_balls; cnt++) { image_ball.draw(gc, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos); } gc.set_modelview(CL_Mat4f::identity()); gc.set_projection(CL_Mat4f::identity()); gc.set_map_mode(cl_map_2d_upper_left); window.flip(1); CL_KeepAlive::process(); } return 0; }