int ExampleText::start(const std::vector<CL_String> &args) { // Create a console window for text-output if not available CL_ConsoleWindow console("Console"); quit = false; // Set a videomode CL_DisplayWindowDescription desc; desc.set_allow_resize(false); desc.set_title("ClanLib CL_SpanLayout Example"); desc.set_size(CL_Size(800, 600), true); CL_DisplayWindow window(desc); // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &ExampleText::on_window_close); // Connect a keyboard handler to on_key_up() CL_Slot slot_keyboard_up = window.get_ic().get_keyboard().sig_key_up().connect(this, &ExampleText::on_keyboard_up); CL_GraphicContext gc = window.get_gc(); CL_TextureGroup texture_group(gc, CL_Size(512, 512)); CL_FontDescription font_desc; font_desc.set_typeface_name("Tahoma"); font_desc.set_anti_alias(true); font_desc.set_height(32); CL_Font_System font_normal(gc, font_desc); font_desc.set_weight(800); font_desc.set_height(40); CL_Font_System font_bold(gc, font_desc); // Share the font texture font_normal.set_texture_group(texture_group); font_bold.set_texture_group(texture_group); CL_Texture texture_text(gc, text_window_size, text_window_size); texture_text.set_wrap_mode(cl_wrap_repeat, cl_wrap_repeat, cl_wrap_repeat); texture_text.set_min_filter(cl_filter_linear); texture_text.set_mag_filter(cl_filter_linear); // Create the framebuffer, and attach the texture text into its color buffer CL_FrameBuffer fb_text; fb_text = CL_FrameBuffer(gc); fb_text.attach_color_buffer(0, texture_text); float angle = 0.0f; std::vector<CL_SpanLayout> layout; // Count number of lines int num_lines = 0; for (const char **text_ptr = TextToShow; *text_ptr; text_ptr++) { num_lines++; } // Extend layout vector layout.resize(num_lines); int ypos = 60; for (int line_count=0; line_count < num_lines; line_count++, ypos += 8) { layout[line_count] = CL_SpanLayout(); layout[line_count].set_position(CL_Point(20, ypos)); layout[line_count].set_align(cl_justify); const char *text_ptr = TextToShow[line_count]; if (text_ptr[0] == '-') { layout[line_count].add_text(text_ptr, font_normal, CL_Colorf::red); } else if (strstr(text_ptr, "Clan")) { layout[line_count].add_text(text_ptr, font_bold, CL_Colorf::yellow); } else { layout[line_count].add_text(text_ptr, font_normal, CL_Colorf::yellow); } layout[line_count].layout(gc, texture_text.get_width() - 60); ypos += layout[line_count].get_size().height; } // Run until someone presses escape while (!quit) { int start_time = CL_System::get_time(); gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left)); // Draw a nice blue gradient in the background CL_Draw::gradient_fill(gc, window.get_viewport(), CL_Gradient(CL_Colorf::lightblue, CL_Colorf::lightblue, CL_Colorf::darkblue, CL_Colorf::darkblue)); // Draw the text into the frame buffer update_text(gc, fb_text, font_normal, layout); angle += 0.5f; if (angle >= 360.0f) angle -= 360.0f; // Draw the text draw_text(gc, texture_text, CL_Angle(angle, cl_degrees)); last_fps = 1000.0f / (CL_System::get_time()-start_time); // Flip the display, showing on the screen what we have drawn window.flip(1); // This call updates input and performs other "housekeeping" call this each frame CL_KeepAlive::process(); } return 0; }
void Model_Impl::Load(CL_DomDocument &doc, const char *geometry_name, std::vector<CL_Collada_Image> &library_images) { CL_Collada object; object = CL_Collada(doc, library_images); insert_object(object, geometry_name, library_images, CL_Angle(89.53f, cl_degrees)); }
void CL_Sprite_Impl::init(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources, const CL_ImageImportDescription &import_desc) { // bool pack_texture = resource.get_element().get_attribute("pack_texture", "yes") == "yes"; CL_Resource resource = resources->get_resource(resource_id); // Create sprite from sprite description CL_SpriteDescription desc(gc, resource_id, resources, import_desc ); create_textures(gc, desc); // Load base angle float work_angle = CL_StringHelp::text_to_float(resource.get_element().get_attribute("base_angle", "0")); base_angle= CL_Angle(work_angle, cl_degrees); // Load id id = CL_StringHelp::text_to_int(resource.get_element().get_attribute("id", "0")); // Load play options CL_DomNode cur_node = resource.get_element().get_first_child(); while (!cur_node.is_null()) { if (!cur_node.is_element()) continue; CL_DomElement cur_element = cur_node.to_element(); CL_String tag_name = cur_element.get_tag_name(); // <color red="float" green="float" blue="float" alpha="float" /> if (tag_name == "color") { color.r = (float)CL_StringHelp::text_to_float(cur_element.get_attribute("red", "1.0")); color.g = (float)CL_StringHelp::text_to_float(cur_element.get_attribute("green", "1.0")); color.b = (float)CL_StringHelp::text_to_float(cur_element.get_attribute("blue", "1.0")); color.a = (float)CL_StringHelp::text_to_float(cur_element.get_attribute("alpha", "1.0")); } // <animation speed="integer" loop="[yes,no]" pingpong="[yes,no]" direction="[backward,forward]" on_finish="[blank,last_frame,first_frame]"/> else if (tag_name == "animation") { int delay_ms = CL_StringHelp::text_to_int(cur_element.get_attribute("speed", "60")); int frame_count = frames.size(); for(int i=0; i<frame_count; ++i) get_frame(i)->delay_ms = delay_ms; play_loop = ((cur_element.get_attribute("loop", "yes")) == "yes"); play_pingpong = ((cur_element.get_attribute("pingpong", "no")) == "yes"); play_backward = ((cur_element.get_attribute("direction", "forward")) == "backward"); CL_String on_finish = cur_element.get_attribute("on_finish", "blank"); if (on_finish == "first_frame") show_on_finish = CL_Sprite::show_first_frame; else if(on_finish == "last_frame") show_on_finish = CL_Sprite::show_last_frame; else show_on_finish = CL_Sprite::show_blank; } // <scale x="float" y="float /> else if (tag_name == "scale") { scale_x = CL_StringHelp::text_to_float(cur_element.get_attribute("x", "1.0")); scale_y = CL_StringHelp::text_to_float(cur_element.get_attribute("y", "1.0")); } // <translation origin="string" x="integer" y="integer" /> else if (tag_name == "translation") { CL_String hotspot = cur_element.get_attribute("origin", "top_left"); CL_Origin origin; if(hotspot == "center") origin = origin_center; else if(hotspot == "top_center") origin = origin_top_center; else if(hotspot == "top_right") origin = origin_top_right; else if(hotspot == "center_left") origin = origin_center_left; else if(hotspot == "center_right") origin = origin_center_right; else if(hotspot == "bottom_left") origin = origin_bottom_left; else if(hotspot == "bottom_center") origin = origin_bottom_center; else if(hotspot == "bottom_right") origin = origin_bottom_right; else origin = origin_top_left; int xoffset = CL_StringHelp::text_to_int(cur_element.get_attribute("x", "0")); int yoffset = CL_StringHelp::text_to_int(cur_element.get_attribute("y", "0")); translation_origin = origin; translation_hotspot.x = xoffset; translation_hotspot.y = yoffset; } // <rotation origin="string" x="integer" y="integer" /> else if (tag_name == "rotation") { CL_String hotspot = cur_element.get_attribute("origin", "center"); CL_Origin origin; if(hotspot == "top_left") origin = origin_top_left; else if(hotspot == "top_center") origin = origin_top_center; else if(hotspot == "top_right") origin = origin_top_right; else if(hotspot == "center_left") origin = origin_center_left; else if(hotspot == "center_right") origin = origin_center_right; else if(hotspot == "bottom_left") origin = origin_bottom_left; else if(hotspot == "bottom_center") origin = origin_bottom_center; else if(hotspot == "bottom_right") origin = origin_bottom_right; else origin = origin_center; int xoffset = CL_StringHelp::text_to_int(cur_element.get_attribute("x", "0")); int yoffset = CL_StringHelp::text_to_int(cur_element.get_attribute("y", "0")); rotation_origin = origin; rotation_hotspot.x = xoffset; rotation_hotspot.y = yoffset; } // <frame nr="integer" speed="integer" x="integer" y="integer" /> else if (tag_name == "frame") { int nr = CL_StringHelp::text_to_int(cur_element.get_attribute("nr", "0")); int yoffset = CL_StringHelp::text_to_int(cur_element.get_attribute("y", "0")); int xoffset = CL_StringHelp::text_to_int(cur_element.get_attribute("x", "0")); SpriteFrame *sptr = get_frame(nr); if (sptr == NULL) { throw CL_Exception("Invalid sprite frame index specified"); } if (cur_element.has_attribute("speed")) { sptr->delay_ms = CL_StringHelp::text_to_int(cur_element.get_attribute("speed", "60")); } sptr->offset = CL_Point(xoffset, yoffset); } cur_node = cur_node.get_next_sibling(); } }
// The start of the Application int App::start(const std::vector<CL_String> &args) { quit = false; CL_GL1WindowDescription desc; desc.set_title("ClanLib Object 3D Example"); desc.set_size(CL_Size(640, 480), true); desc.set_multisampling(4); desc.set_depth_size(16); CL_DisplayWindow window(desc); #ifdef _DEBUG //struct aiLogStream stream; //stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL); //aiAttachLogStream(&stream); //stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt"); //aiAttachLogStream(&stream); #endif // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); // Connect a keyboard handler to on_key_up() CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); // Get the graphic context CL_GraphicContext gc = window.get_gc(); #ifdef USE_OPENGL_1 CL_GraphicContext_GL1 gc_gl1 = gc; #endif // Prepare the display gc.set_map_mode(cl_user_projection); CL_PolygonRasterizer polygon_rasterizer; polygon_rasterizer.set_culled(true); polygon_rasterizer.set_face_cull_mode(cl_cull_back); polygon_rasterizer.set_front_face(cl_face_side_clockwise); gc.set_polygon_rasterizer(polygon_rasterizer); CL_BufferControl buffer_control; buffer_control.enable_depth_test(true); buffer_control.set_depth_compare_function(cl_comparefunc_lequal); buffer_control.enable_depth_write(true); gc.set_buffer_control(buffer_control); #ifdef USE_OPENGL_1 // Set the lights CL_LightModel_GL1 light_model; light_model.enable_lighting(true); light_model.set_flat_shading(false); light_model.set_scene_ambient_light(CL_Colorf(0.2f, 0.2f, 0.2f, 1.0f)); gc_gl1.set_light_model(light_model); CL_LightSource_GL1 light_distant; light_distant.set_spot_cutoff(180.0f); light_distant.set_diffuse_intensity(CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); light_distant.set_position(CL_Vec4f(0.0f, -2.0f, 30.0f, 0.0f).normalize3()); gc_gl1.set_light(0, light_distant); cl1Enable(GL_NORMALIZE); #endif #ifdef USE_OPENGL_2 Shader shader(gc); #endif // Create the objects aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,89.53f); const struct aiScene* scene_teapot = aiImportFile("../Clan3D/Resources/teapot.dae",aiProcessPreset_TargetRealtime_MaxQuality); if (!scene_teapot) throw CL_Exception("Cannot load the teapot model"); const struct aiScene* scene_clanlib = aiImportFile("../Clan3D/Resources/clanlib.dae",aiProcessPreset_TargetRealtime_MaxQuality); if (!scene_clanlib) throw CL_Exception("Cannot load the clanlib model"); const struct aiScene* scene_tuxball = aiImportFile("../Clan3D/Resources/tux_ball.dae",aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_FlipUVs); if (!scene_tuxball) throw CL_Exception("Cannot load the tux ball model"); // Load the texture CL_Texture tux(gc, "../Clan3D/Resources/tux.png"); float angle = 0.0f; // Run until someone presses escape while (!quit) { CL_Mat4f perp = CL_Mat4f::perspective(45.0f, ((float) gc.get_width()) / ((float) gc.get_height()), 0.1f, 1000.0f); gc.set_projection(perp); gc.clear(CL_Colorf::black); gc.clear_depth(1.0f); angle += 1.0f; if (angle >= 360.0f) angle -= 360.0f; #ifdef USE_OPENGL_2 shader.Set(gc); shader.Use(gc); #else gc.set_program_object(cl_program_color_only); #endif CL_PrimitivesArray prim_array(gc); gc.set_modelview(CL_Mat4f::identity()); gc.mult_scale(1.0f,1.0f, -1.0f); // So +'ve Z goes into the screen gc.mult_translate(0.0f, 0.0f, 2.0f); gc.mult_rotate(CL_Angle(angle, cl_degrees), 0.0f, 1.0f, 0.0f, false); gc.push_modelview(); recursive_render(gc, scene_teapot, scene_teapot->mRootNode, false); gc.pop_modelview(); gc.push_modelview(); gc.mult_scale(0.5f, 0.5f, 0.5f); gc.mult_translate(0.0f, -0.5f, 0.0f); recursive_render(gc, scene_clanlib, scene_clanlib->mRootNode, false); gc.pop_modelview(); #ifdef USE_OPENGL_2 shader.Set(gc, 0); shader.Use(gc); #else gc.set_program_object(cl_program_single_texture); #endif gc.set_texture(0, tux); gc.set_modelview(CL_Mat4f::identity()); gc.mult_scale(1.0f,1.0f, -1.0f); // So +'ve Z goes into the screen gc.mult_translate(0.7f, 0.5f, 2.0f); gc.mult_scale(0.05f, 0.05f, 0.05f); gc.mult_rotate(CL_Angle(angle * 4.0f, cl_degrees), 0.0f, 1.0f, 0.0f, false); recursive_render(gc, scene_tuxball, scene_tuxball->mRootNode, true); gc.reset_texture(0); gc.reset_program_object(); // Flip the display, showing on the screen what we have drawed // since last call to flip() window.flip(1); // This call processes user input and other events CL_KeepAlive::process(); } aiReleaseImport(scene_tuxball); aiReleaseImport(scene_clanlib); aiReleaseImport(scene_teapot); aiDetachAllLogStreams(); return 0; }
// The start of the Application int App::start(const std::vector<CL_String> &args) { quit = false; // Create a console window for text-output if not available CL_ConsoleWindow console("Console", 80, 200); try { // Set the window // This opens a 640 x 480 window, including the frame size // If you want more control over the window, pass CL_DisplayWindowDescription to CL_DisplayWindow // (This is useful to create a borderless window of a specific size) // If you require target specific control over the window, use the derived CL_OpenGLWindowDescription // (This contains the multisampling options) #ifdef USE_SWRENDER CL_DisplayWindowDescription desc; #else CL_OpenGLWindowDescription desc; // desc.set_multisampling(4); #endif desc.set_title("ClanLib 2D Test"); desc.set_size(CL_Size(800, 600), true); CL_DisplayWindow window(desc); // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); // Connect a keyboard handler to on_key_up() CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); // Get the graphic context CL_GraphicContext gc = window.get_gc(); CL_Texture texture_image(gc, "tux.png"); texture_image.set_wrap_mode(cl_wrap_repeat, cl_wrap_repeat, cl_wrap_repeat); texture_image.set_min_filter(cl_filter_linear); texture_image.set_mag_filter(cl_filter_linear); CL_ResourceManager resources("resources.xml"); CL_Sprite sprite(gc, "test", &resources); //sprite.set_linear_filter(true); CL_Font small_font = CL_Font(gc, "Tahoma", 12); float test_base_angle = 0.0f; float test_angle = 0.0f; float test_angle_pitch = 0.0f; float test_angle_yaw = 0.0f; float test_scale = 1.0f; bool test_scale_dir = false; // Run until someone presses escape while (!quit) { gc.clear(CL_Colorf(0.0f,0.0f,0.2f)); gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left)); // CL_Draw::point() for (int xcnt=0; xcnt<8; xcnt++) { for (int ycnt=0; ycnt<6; ycnt++) { CL_Draw::point(gc, xcnt*2, ycnt*2, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); } } small_font.draw_text(gc, 32, 10, "8*6 Points (0 + 2x), (0 + 2y)"); // CL_Draw::line() for (int xcnt=0; xcnt<4; xcnt++) { for (int ycnt=0; ycnt<3; ycnt++) { const int offset_y = 16; const int line_length = 6; const int spacing = 8; CL_Draw::line(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); } } small_font.draw_text(gc, 48, 30, "4*3 Lines (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)"); // CL_Draw::box() for (int xcnt=0; xcnt<4; xcnt++) { for (int ycnt=0; ycnt<3; ycnt++) { const int offset_y = 48; const int line_length = 6; const int spacing = 8; CL_Draw::box(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); } } small_font.draw_text(gc, 48, 66, "4*3 Box (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)"); // CL_Draw::fill() for (int xcnt=0; xcnt<4; xcnt++) { for (int ycnt=0; ycnt<3; ycnt++) { const int offset_y = 80; const int line_length = 6; const int spacing = 8; CL_Draw::fill(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); } } small_font.draw_text(gc, 48, 90, "4*3 Fill (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)"); // CL_Draw::gradient_fill() CL_Gradient gradient; gradient.top_left = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f); gradient.top_right = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f); gradient.bottom_left = CL_Colorf(0.0f, 0.0f, 1.0f, 1.0f); gradient.bottom_right = CL_Colorf(0.0f, 1.0f, 0.0f, 1.0f); for (int xcnt=0; xcnt<4; xcnt++) { for (int ycnt=0; ycnt<3; ycnt++) { const int offset_y = 110; const int line_length = 6; const int spacing = 8; CL_Draw::gradient_fill(gc, xcnt*spacing, (ycnt*spacing) + offset_y, line_length + (xcnt*spacing), (line_length + (ycnt*spacing)) + offset_y, gradient); } } small_font.draw_text(gc, 48, 115, "4*3 GradientFill (0 + 8x), (32 + 8y), (6 + 8x), (38 + 8y)"); small_font.draw_text(gc, 48, 125, "top left = white. top right = red"); small_font.draw_text(gc, 48, 135, "bottom left = blue. bottom right = green"); // CL_Draw::circle() { const int offset_y = 140; int radius = 5; CL_Draw::circle(gc, radius, offset_y + radius, radius, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); const int offset_x = 16; radius = 16; CL_Draw::circle(gc, offset_x + radius, offset_y + radius, radius, CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); } small_font.draw_text(gc, 54, 149, "Circle (5, 145) Radius = 5"); small_font.draw_text(gc, 54, 159, "Circle (32, 156) Radius = 16"); // CL_Draw::gradient_circle() { CL_Gradient gradient; gradient.top_left = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f); gradient.top_right = CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f); gradient.bottom_left = CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f); gradient.bottom_right = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f); const int offset_y = 180; float radius = 17.0; float xpos = radius; float ypos = offset_y + radius; CL_Draw::gradient_circle(gc, CL_Pointf( xpos, ypos ), CL_Pointf(radius/2.0, 0.0f), radius, gradient); const int offset_x = 40; radius = 17.0; xpos = offset_x + radius; ypos = offset_y + radius; CL_Draw::gradient_circle(gc, CL_Pointf( xpos, ypos), CL_Pointf(0.0f, radius/2.0), radius, gradient); } small_font.draw_text(gc, 80, 189, "Gradient Circle (16, 196) Radius = 17. Gradient right"); small_font.draw_text(gc, 80, 199, "Gradient Circle (56, 196) Radius = 17. Gradient up"); small_font.draw_text(gc, 80, 209, "centre = white, outer = red"); // CL_Draw::triangle() { const float offset_y = 220.0f; const float size = 12.0f; CL_Draw::triangle(gc, CL_Pointf(0.0f, offset_y), CL_Pointf(0.0f, offset_y + size), CL_Pointf(size, offset_y + size), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); float offset_x = 16.0f; CL_Draw::triangle(gc, CL_Pointf(offset_x + 0.0f, offset_y + size), CL_Pointf(offset_x + size, offset_y + size), CL_Pointf(offset_x + 0.0f, offset_y), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); offset_x = 32.0f; CL_Draw::triangle(gc, CL_Pointf(offset_x + size, offset_y + size), CL_Pointf(offset_x + 0.0f, offset_y), CL_Pointf(offset_x + 0.0f, offset_y + size), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f)); } small_font.draw_text(gc, 48, 229, "3 Triangles (12 pixel size) (Left vertical edge)."); small_font.draw_text(gc, 48, 239, "Top Left: (0,220) (16,220) (32,220)"); // CL_Draw::texture() gc.set_texture(0, texture_image); { float offset_x = 0.0f; float offset_y = 250.0f; CL_Rectf src_rect(offset_x, offset_y, CL_Sizef(31, 47)); CL_Rectf texture_coords(0.0, 0.0, 1.0f, 1.0f); CL_Colorf color(1.0f, 1.0f, 1.0f, 1.0f); CL_Draw::texture(gc, src_rect, color, texture_coords); offset_x = 33.0f; src_rect = CL_Rectf(offset_x, offset_y, CL_Sizef(31, 47)); texture_coords = CL_Rectf(0.25f, 0.25f, 0.75f, 0.75f); color = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f); CL_Draw::texture(gc, src_rect, color, texture_coords); } gc.reset_texture(0); small_font.draw_text(gc, 76, 260, "Texture (0, 250) size=(31,47)"); small_font.draw_text(gc, 76, 275, "Texture (33, 250) size=(31,47) (red, magnify*2)"); // CL_RoundedRect { CL_RoundedRect roundedrect(CL_Sizef(64.0f, 32.0f), 15.0f); float offset_x = 0.0f; float offset_y = 300.0f; CL_Origin origin = origin_top_left; roundedrect.draw(gc, CL_Pointf(offset_x, offset_y), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f), origin); offset_y = 340.0f; roundedrect.fill(gc, CL_Pointf(offset_x, offset_y), CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f), origin); offset_y = 380.0f; CL_Gradient gradient; gradient.top_left = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f); gradient.top_right = CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f); gradient.bottom_left = CL_Colorf(0.0f, 0.0f, 1.0f, 1.0f); gradient.bottom_right = CL_Colorf(0.0f, 1.0f, 0.0f, 1.0f); roundedrect.fill(gc, CL_Pointf(offset_x, offset_y), gradient, origin); offset_y = 420.0f; roundedrect.set_control_point_bl(CL_Pointf(0.4f, 0.8f)); roundedrect.set_rounding_bottom_left(CL_Sizef(0.2f, 0.6f)); roundedrect.set_control_point_tl(CL_Pointf(0.2f, 0.4f)); roundedrect.set_rounding_top_left(CL_Sizef(0.4f, 0.2f)); roundedrect.set_control_point_tr(CL_Pointf(0.6f, 0.2f)); roundedrect.set_rounding_top_right(CL_Sizef(0.8f, 0.4f)); roundedrect.set_control_point_br(CL_Pointf(0.6f, 0.8f)); roundedrect.set_rounding_bottom_right(CL_Sizef(0.8f, 0.6f)); roundedrect.fill(gc, CL_Pointf(offset_x, offset_y), gradient, origin); } small_font.draw_text(gc, 76, 310, "RoundedRect - draw (0, 300) size=(64,32)"); small_font.draw_text(gc, 76, 325, "(RoundedRect - draw gradient - is not implemented)"); small_font.draw_text(gc, 76, 350, "RoundedRect - fill (0, 340) size=(64,32)"); small_font.draw_text(gc, 76, 390, "RoundedRect - fill gradient (0, 380) size=(64,32)"); small_font.draw_text(gc, 76, 400, "top left = white. top right = red"); small_font.draw_text(gc, 76, 410, "bottom left = blue. bottom right = green"); small_font.draw_text(gc, 76, 430, "RoundedRect - fill gradient (0, 420) size=(64,32)"); small_font.draw_text(gc, 76, 440, "Controling control / rounding points"); // CL_Sprite { test_base_angle+=5.0f; if (test_base_angle >= 360.0f) { test_base_angle = 0.0f; } #ifndef USE_SWRENDER clEnable(GL_MULTISAMPLE); #endif sprite.set_base_angle(CL_Angle(test_base_angle, cl_degrees)); sprite.draw(gc, 350, 20); sprite.set_base_angle(CL_Angle(0, cl_degrees)); #ifndef USE_SWRENDER clDisable(GL_MULTISAMPLE); #endif } small_font.draw_text(gc, 370, 20, "Sprite - Base angle"); small_font.draw_text(gc, 370, 35, "Multisampling enabled"); { test_angle+=5.0f; if (test_angle >= 360.0f) { test_angle = 0.0f; } sprite.set_angle(CL_Angle(test_angle, cl_degrees)); sprite.draw(gc, 350, 60); sprite.set_angle(CL_Angle(0, cl_degrees)); } small_font.draw_text(gc, 370, 60, "Sprite - Angle"); { test_angle_pitch+=5.0f; if (test_angle_pitch >= 360.0f) { test_angle_pitch = 0.0f; } sprite.set_angle_pitch(CL_Angle(test_angle_pitch, cl_degrees)); sprite.draw(gc, 350, 100); sprite.set_angle_pitch(CL_Angle(0, cl_degrees)); } small_font.draw_text(gc, 370, 100, "Sprite - Angle Pitch"); { test_angle_yaw+=5.0f; if (test_angle_yaw >= 360.0f) { test_angle_yaw = 0.0f; } sprite.set_angle_yaw(CL_Angle(test_angle_yaw, cl_degrees)); sprite.draw(gc, 350, 140); sprite.set_angle_yaw(CL_Angle(0, cl_degrees)); } small_font.draw_text(gc, 370, 140, "Sprite - Angle Yaw"); { if (test_scale_dir) { test_scale += 0.1f; if (test_scale >= 2.0f) { test_scale = 2.0f; test_scale_dir = false; } }else { test_scale -= 0.1f; if (test_scale <= -2.0f) { test_scale = -2.0f; test_scale_dir = true; } } sprite.set_scale(test_scale, 1.0f); sprite.draw(gc, 350, 180); sprite.set_scale(1.0f, test_scale); sprite.draw(gc, 390, 180); sprite.set_scale(1.0f, 1.0f); } small_font.draw_text(gc, 420, 180, "Sprite - Set Scale (x), (y)"); // Flip the display, showing on the screen what we have drawed // since last call to flip() window.flip(1); // This call processes user input and other events CL_KeepAlive::process(); } small_font = CL_Font(); } catch(CL_Exception& exception) { CL_Console::write_line("Exception caught:"); CL_Console::write_line(exception.message); // Display the stack trace (if available) std::vector<CL_String> stacktrace = exception.get_stack_trace(); int size = stacktrace.size(); if (size > 0) { CL_Console::write_line("Stack Trace:"); for (int cnt=0; cnt < size; cnt++) { CL_Console::write_line(stacktrace[cnt]); } } console.display_close_message(); return -1; } 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("Vertex Buffer Object Example"); win_desc.set_depth_size(16); win_desc.set_size(CL_Size( 800, 600 ), 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_GraphicContext gc = window.get_gc(); Shader shader(gc); // Prepare the display gc.set_map_mode(cl_user_projection); CL_PolygonRasterizer polygon_rasterizer; polygon_rasterizer.set_culled(true); polygon_rasterizer.set_face_cull_mode(cl_cull_back); polygon_rasterizer.set_front_face(cl_face_side_clockwise); gc.set_polygon_rasterizer(polygon_rasterizer); CL_BufferControl buffer_control; buffer_control.enable_depth_test(true); buffer_control.set_depth_compare_function(cl_comparefunc_lequal); buffer_control.enable_depth_write(true); gc.set_buffer_control(buffer_control); std::vector<CL_Vec3f> object_positions; std::vector<CL_Vec3f> object_normals; std::vector<CL_Vec4f> object_material_ambient; const int num_cubes = 20000; object_positions.reserve(num_cubes * 6 * 6); // 6 faces, and 6 vertices per face object_normals.reserve(num_cubes * 6 * 6); object_material_ambient.reserve(num_cubes * 6 * 6); for (int cnt=0; cnt < num_cubes; cnt++) { create_cube(object_positions, object_normals, object_material_ambient); } CL_VertexArrayBuffer vb_positions(gc, &object_positions[0], sizeof(CL_Vec3f) * object_positions.size()); CL_VertexArrayBuffer vb_normals(gc, &object_normals[0], sizeof(CL_Vec3f) * object_normals.size()); CL_VertexArrayBuffer vb_material_ambient(gc, &object_material_ambient[0], sizeof(CL_Vec4f) * object_material_ambient.size()); // ** Note, at this point "object_positions, object_normals and object_material_ambient" // ** can be destroyed. But for the purpose of this example, is it kept CL_Font fps_font(gc, "tahoma", 20); FramerateCounter frameratecounter; unsigned int time_last = CL_System::get_time(); float angle = 0.0f; is_vertex_buffer_on = true; while (!quit) { unsigned int time_now = CL_System::get_time(); float time_diff = (float) (time_now - time_last); time_last = time_now; gc.clear(CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f)); gc.clear_depth(1.0f); gc.set_map_mode(cl_map_2d_upper_left); CL_String fps = cl_format("%1 fps", frameratecounter.get_framerate()); fps_font.draw_text(gc, gc.get_width() - 100, 30, fps); CL_String info = cl_format("%1 vertices", (int) object_positions.size()); fps_font.draw_text(gc, 30, 30, info); fps_font.draw_text(gc, 30, gc.get_height() - 8, "Press any key to toggle the Vertex Buffer option"); if (is_vertex_buffer_on) { fps_font.draw_text(gc, 200, 30, "Vertex Buffer = ON"); } else { fps_font.draw_text(gc, 200, 30, "Vertex Buffer = OFF"); } gc.set_map_mode(cl_user_projection); CL_Mat4f perp = CL_Mat4f::perspective(45.0f, ((float) gc.get_width()) / ((float) gc.get_height()), 0.1f, 100000.0f); gc.set_projection(perp); angle += time_diff / 20.0f; if (angle >= 360.0f) angle -= 360.0f; gc.push_modelview(); gc.set_modelview(CL_Mat4f::identity()); gc.mult_scale(1.0f,1.0f, -1.0f); // So +'ve Z goes into the screen gc.mult_translate(0.0f, 0.0f, 800.0f); gc.mult_rotate(CL_Angle(angle*2.0f, cl_degrees), 0.0f, 1.0f, 0.0f, false); gc.mult_rotate(CL_Angle(angle, cl_degrees), 1.0f, 0.0f, 0.0f, false); shader.Set(gc); shader.Use(gc); CL_PrimitivesArray prim_array(gc); if (is_vertex_buffer_on) { prim_array.set_attributes(0, vb_positions, 3, cl_type_float, (void *) 0); prim_array.set_attributes(1, vb_normals, 3, cl_type_float, (void *) 0); prim_array.set_attributes(2, vb_material_ambient, 4, cl_type_float, (void *) 0); } else { prim_array.set_attributes(0, &object_positions[0]); prim_array.set_attributes(1, &object_normals[0]); prim_array.set_attributes(2, &object_material_ambient[0]); } gc.draw_primitives(cl_triangles, object_positions.size(), prim_array); gc.pop_modelview(); gc.reset_program_object(); window.flip(0); frameratecounter.frame_shown(); CL_KeepAlive::process(); } return 0; }
void Powerup::setAngulo(float _angulo) { angulo = _angulo; sprite->set_angle(CL_Angle(angulo, cl_degrees)); collisionPowerup->set_angle(CL_Angle(angulo, cl_degrees)); }
CL_Angle CL_Vec2<Type>::angle(const CL_Vec2<Type>& v) const { return CL_Angle((float)acosf(float(dot(v)/(length()*v.length()))), cl_radians); }
// The start of the Application int App::start(const std::vector<CL_String> &args) { // Setup the window CL_DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("3D GUI Example"); win_desc.set_size(CL_Size( 700, 700 ), false); window = CL_DisplayWindow(win_desc); // Connect the slots that we require CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); CL_Slot slot_input_down = (window.get_ic().get_keyboard()).sig_key_down().connect(this, &App::on_input_down); CL_GraphicContext gc = window.get_gc(); CL_Font font = CL_Font(gc, "tahoma", 16); // Initialise the GUI system GUI gui(this); // NOTE: The GUI component positions are still in 2D world, therefore // be careful not to overlap windows, else unpredicted results may occur! window1 = new Window1(gui, CL_Rect(0,0, CL_Size(256, 256))); slider_1_xrotation = new Slider(gui, CL_Rect(0, 512, CL_Size(200, 17))); slider_1_xrotation->object_matrix.translate_self(0.0f, 0.8f, 3.0f); slider_1_xrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_yrotation = new Slider(gui, CL_Rect(256*1, 512, CL_Size(200, 17))); slider_1_yrotation->object_matrix.translate_self(0.0f, 0.7f, 3.0f); slider_1_yrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_zrotation = new Slider(gui, CL_Rect(256*2, 512, CL_Size(200, 17))); slider_1_zrotation->object_matrix.translate_self(0.0f, 0.6f, 3.0f); slider_1_zrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_xtranslation = new Slider(gui, CL_Rect(256*3, 512, CL_Size(200, 17))); slider_1_xtranslation->object_matrix.translate_self(0.0f, 0.5f, 3.0f); slider_1_xtranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_xtranslation->component->set_position(500); slider_1_ytranslation = new Slider(gui, CL_Rect(256*4, 512, CL_Size(200, 17))); slider_1_ytranslation->object_matrix.translate_self(0.0f, 0.4f, 3.0f); slider_1_ytranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_ytranslation->component->set_position(500); slider_1_ztranslation = new Slider(gui, CL_Rect(256*5, 512, CL_Size(200, 17))); slider_1_ztranslation->object_matrix.translate_self(0.0f, 0.3f, 3.0f); slider_1_ztranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_ztranslation->component->set_position(500); while(!quit) { calculate_matrix(); gc.set_modelview(CL_Mat4f::identity()); gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left)); // Draw the gradient CL_Draw::gradient_fill(gc, CL_Rect(0, 0, gc.get_width(), gc.get_height()/2), CL_Gradient(CL_Colorf(0.2f, 0.2f, 0.8f, 1.0f), CL_Colorf(0.0f, 0.0f, 0.2f, 1.0f))); CL_Draw::gradient_fill(gc, CL_Rect(0, gc.get_height()/2, gc.get_width(), gc.get_height()), CL_Gradient(CL_Colorf(0.0f, 0.0f, 0.2f, 1.0f), CL_Colorf(0.2f, 0.2f, 0.8f, 1.0f))); font.draw_text(gc, 8, 20, "GUI3D"); int xoffset = 160; int yoffset = 70; const int ygap = 35; font.draw_text(gc, xoffset, yoffset, "X Rotation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Y Rotation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Z Rotation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "X Translation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Y Translation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Z Translation"); yoffset += ygap; if (!gui.run()) break; gc.set_map_mode(cl_user_projection); gc.set_projection(projection_matrix); gc.set_modelview(modelview_matrix); control_window(); gui.draw(); window.flip(1); CL_KeepAlive::process(); } return 0; }
void setup_perspective( const player &camera ) { glMatrixMode(GL_PROJECTION); //hello { CL_Mat4f proj = CL_Mat4f::perspective( 60, 1.5, 0.2, 500 ); // CL_Mat4f proj = CL_Mat4f::ortho( -20.0 * pump_factor_, 20.0 * pump_factor_, -15.0 * pump_factor_, 15.0 * pump_factor_, 0, 200 ); //CL_Mat4f proj = CL_Mat4f::ortho( -40, 40, -30, 30, 0, 200 ); glLoadMatrixf( proj.matrix ); } // std::cout << "pos: " << player_pos << "\n"; glMatrixMode( GL_MODELVIEW ); { const vec3f &player_pos = camera.pos(); CL_Mat4f proj = CL_Mat4f::translate(-player_pos.x, -player_pos.y, -player_pos.z) * CL_Mat4f::rotate(CL_Angle(-camera.rot_x(), cl_degrees),CL_Angle(-camera.rot_y(),cl_degrees),CL_Angle(), cl_XYZ); glLoadMatrixf(proj.matrix); } }
void App::create_scene(CL_GraphicContext &gc) { Model model_teapot(gc, "../Clan3D/Resources/teapot.dae", true); Model model_landscape(gc, "Resources/land.dae", false); Model model_tree(gc, "Resources/tree.dae", false); Model model_gear(gc, "../Clan3D/Resources/gear.dae", false); model_teapot.SetMaterial( 32.0f, // shininess CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f), // emission CL_Vec4f(1.5f, 1.5f, 0.5f, 1.0f), // ambient CL_Vec4f(0.5f, 0.5f, 0.5f, 1.0f) ); // specular camera = new SceneObject(scene, scene.base); camera->position = CL_Vec3f(0.0f, 50.0f, -20.0f); camera->rotation_y = CL_Angle(0.0f, cl_degrees); camera->scale = CL_Vec3f(1.0f, 1.0f, 1.0f); light = new SceneObject(scene, scene.base); light->position = CL_Vec3f(-20.4732f, 48.7872f, -20.5439f); light->rotation_y = CL_Angle(45.0f, cl_degrees); light->rotation_x = CL_Angle(35.0f, cl_degrees); light->scale = CL_Vec3f(1.0f, 1.0f, 1.0f); SceneObject *object_landscape = new SceneObject(scene, scene.base); object_landscape->model = model_landscape; object_landscape->position = CL_Vec3f(0.0f, 0.0f, 0.0f); object_teapot1 = new SceneObject(scene, object_landscape); object_teapot1->model = model_teapot; object_teapot1->position = CL_Vec3f(-8.2f, 37.3f, 8.0f); object_teapot1->scale = CL_Vec3f(8.0f, 8.0f, 8.0f); object_teapot2 = new SceneObject(scene, object_landscape); object_teapot2->model = model_teapot; object_teapot2->position = CL_Vec3f(2.0f, 40.0f, 1.0f); object_teapot2->scale = CL_Vec3f(8.0f, 8.0f, 8.0f); SceneObject *object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(-7.2701f, 25.58f, -9.0932f); object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(-11.829f, 25.8125f, 0.0f); object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(-5.0f, 27.6963f, 0.0f); object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(0.0f, 29.4237f, 0.0f); object_gear = new SceneObject(scene, object_landscape); object_gear->model = model_gear; object_gear->position = CL_Vec3f(10.0f, 40.58f, 10.0); object_gear->scale = CL_Vec3f(3.0f, 3.0f, 3.0f); scene.gs->LoadImages(gc); }
CL_Angle CL_Vec4<Type>::angle3(const CL_Vec4<Type>& v) const { return CL_Angle(acosf(float(dot3(v)/(length3()*v.length3()))), cl_radians); }