int Application::main(const std::vector<CL_String> &args) { try { // Create a window CL_DisplayWindowDescription desc; desc.set_title("PacMan"); desc.set_allow_resize(true); desc.set_size(CL_Size(800, 600), true); CL_DisplayWindow window(desc); CL_GraphicContext gc = window.get_gc(); // Create world World world(window); world.run(); } catch(CL_Exception &exception) { // Create a console window for text-output if not available CL_ConsoleWindow console("Console", 80, 160); CL_Console::write_line("Exception caught: " + exception.get_message_and_stack_trace()); console.display_close_message(); return -1; } return 0; }
void Game::Initialize() { //Setup game window CL_DisplayWindowDescription desc; desc.set_title("SUPER MEGA AWESOME GAME by R&D Intercative"); desc.set_size(CL_Size(RESOLUTION_X, RESOLUTION_Y), true); desc.set_allow_resize(false); m_window = CL_DisplayWindow(desc); //Setup input device and graphic context m_gc = m_window.get_gc(); //Initialize resource manager and quit slot m_resources = CL_ResourceManager("resources.xml"); m_quitSlot = m_window.sig_window_close().connect(this, &Game::OnQuit); m_keyDownSlot = m_window.get_ic().get_keyboard().sig_key_down().connect(this, &Game::OnKeyDown); XmlParser parser("settings/PlayerClasses.xml"); s32 playerTypeCount = parser.ReadIntAttr("/PlayerClasses", "count"); for (s32 i = 0; i < playerTypeCount; i++) { s8 node[64] = "/PlayerClasses/Class"; s8 temp[5]; itoa(i + 1, temp, 10); strcat(node, temp); s8 playerClass[32]; parser.ReadText(node, playerClass, sizeof(playerClass)); m_playerTypes.insert(std::pair<PlayerType, string>((PlayerType)i, string(playerClass))); } }
void WorkerGC::worker_thread_loop() { CL_DisplayWindowDescription desc; desc.set_title("ClanLib Worker Thread"); desc.set_size(CL_Size(320, 320), true); //desc.set_visible(false); window = CL_DisplayWindow(desc); while (true) { int wakeup_reason = CL_Event::wait(event_start, event_stop); if (wakeup_reason != 0) break; event_start.reset(); try { CL_GraphicContext gc = window.get_gc(); // Test code unsigned int time_ms = CL_System::get_time(); while((CL_System::get_time() - time_ms) < 2000) { gc.clear(CL_Colorf(1.0f,0.0f,0.2f)); CL_KeepAlive::process(); window.flip(0); } window.set_visible(false, false); retrieved_sprite = CL_Sprite(gc, sprite_name); CL_OpenGL::set_active(gc); glFlush(); } catch (CL_Exception &error) { exception_set = true; exception = error; } event_completed.set(); } window = CL_DisplayWindow(); }
Graphics::Graphics(Profile &profile) : mMinAspect(0.0f), mMaxAspect(0.0f), mVSync(true), mFPSTime(0), mNumFrames(0), mFPS(0.0f), mBlendMode(BLEND_ALPHA) { // setup the graphics settings CL_DisplayWindowDescription desc; desc.set_title("Balance"); desc.set_size(CL_Size(profile.getInt("width", 1024), profile.getInt("height", 768)), true); desc.set_swap_interval(mVSync ? 1 : 0); if (profile.getBool("fullscreen", true)) { desc.set_decorations(false); desc.set_fullscreen(true); } else { desc.set_allow_resize(true); } mWindow = CL_DisplayWindow(desc); // make window visible while debugging under SciTE mWindow.show(); // connect window signals mSlots.connect(Application::getSingleton().getSigUpdate(), this, &Graphics::onUpdate); mSlots.connect(mWindow.get_ic().get_mouse().sig_key_down(), this, &Graphics::onMouseDown); mSlots.connect(mWindow.get_ic().get_mouse().sig_key_dblclk(), this, &Graphics::onMouseDown); mSlots.connect(mWindow.get_ic().get_mouse().sig_key_up(), this, &Graphics::onMouseUp); mSlots.connect(mWindow.sig_resize(), this, &Graphics::onResize); mSlots.connect(mWindow.sig_window_close(), this, &Graphics::onClose); // initialize the graphics settings mWindow.get_gc().set_map_mode(cl_user_projection); setScreenSize(1024.0f, 768.0f); setBlendMode(mBlendMode); // save the current settings profile.setBool("fullscreen", desc.is_fullscreen()); profile.setInt("width", desc.get_size().width); profile.setInt("height", desc.get_size().height); }
int main(const std::vector<CL_String> &args) { try { CL_DisplayWindowDescription desc; desc.set_title("Window"); desc.set_size(CL_Size(600, 600), true); CL_DisplayWindow displaywindow(desc); CL_Slot slot_window_close = displaywindow.sig_window_close().connect(this, &App::on_window_close); CL_ResourceManager resources("../../../Resources/GUIThemeAero/resources.xml"); CL_GUIThemeDefault theme; theme.set_resources(resources); CL_GUIWindowManagerTexture windowmanager(displaywindow); // CL_GUIWindowManagerSystem windowmanager; guimanager.set_window_manager(windowmanager); guimanager.set_theme(theme); guimanager.set_css_document("../../../Resources/GUIThemeAero/theme.css"); CL_GUIComponent *toplevelcomponent = new CL_GUIComponent(&guimanager, CL_GUITopLevelDescription(CL_Rect(50, 50, 500, 500), false)); CL_Window *window = new CL_Window(toplevelcomponent, CL_GUITopLevelDescription(CL_Rect(0, 0, 200, 200), false)); guimanager.exec(); } catch (CL_Exception e) { CL_ConsoleWindow console("Console"); CL_Console::write_line(e.message); console.display_close_message(); } return 0; }
// The start of the Application int App::start(const std::vector<CL_String> &args) { quit = false; // Set the window CL_DisplayWindowDescription desc; desc.set_title("ClanLib App Example"); desc.set_size(CL_Size(1200, 500), true); desc.set_allow_resize(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(); // Load a sprite from a png-file tux = CL_PixelBuffer("Resources/tux.png"); tux_original = CL_Image(gc, tux, tux.get_size()); current_format = cl_rgba8; //current_format = cl_rgba8; //current_format = cl_rgb8; //current_format = cl_bgra8; //current_format = cl_bgr8; //current_format = cl_r8; //current_format = cl_r8_snorm; //current_format = cl_r16; //current_format = cl_r16_snorm; //current_format = cl_rg8; //current_format = cl_rg8_snorm; //current_format = cl_rg16; //current_format = cl_rg16_snorm; //current_format = cl_r3_g3_b2; //current_format = cl_rgb4; //current_format = cl_rgb5; //current_format = cl_rgb8_snorm; //current_format = cl_rgb10; //current_format = cl_rgb12; // XX //current_format = cl_rgb16; //current_format = cl_rgb16_snorm; //current_format = cl_rgba2; // XX //current_format = cl_rgba4; //current_format = cl_rgb5_a1; //current_format = cl_rgba8_snorm; //current_format = cl_rgb10_a2; //current_format = cl_rgba12; // X //current_format = cl_rgba16; //current_format = cl_rgba16_snorm; //current_format = cl_srgb8; //current_format = cl_srgb8_alpha8; //current_format = cl_r16f; //current_format = cl_rg16f; //current_format = cl_rgb16f; //current_format = cl_rgba16f; //current_format = cl_r32f; current_format = cl_rg32f; //current_format = cl_rgb32f; //current_format = cl_rgba32f; //current_format = cl_r11f_g11f_b10f; // X //current_format = cl_rgb9_e5; // X //current_format = cl_r8i; //current_format = cl_r8ui; //current_format = cl_r16i; //current_format = cl_r16ui; //current_format = cl_r32i; //current_format = cl_r32ui; //current_format = cl_rg8i; //current_format = cl_rg8ui; //current_format = cl_rg16i; //current_format = cl_rg16ui; //current_format = cl_rg32i; //current_format = cl_rg32ui; //current_format = cl_rgb8i; //current_format = cl_rgb8ui; //current_format = cl_rgb16i; //current_format = cl_rgb16ui; //current_format = cl_rgb32i; //current_format = cl_rgb32ui; //current_format = cl_rgba8i; //current_format = cl_rgba8ui; //current_format = cl_rgba16i; //current_format = cl_rgba16ui; //current_format = cl_rgba32i; //current_format = cl_rgba32ui; //current_format = cl_depth_component16; //current_format = cl_depth_component24; //current_format = cl_depth_component32; //current_format = cl_depth_component32f; //current_format = cl_depth24_stencil8; //current_format = cl_depth32f_stencil8; //current_format = cl_compressed_red; //current_format = cl_compressed_rg; //current_format = cl_compressed_rgb; //current_format = cl_compressed_rgba; //current_format = cl_compressed_srgb; //current_format = cl_compressed_srgb_alpha; //current_format = cl_compressed_red_rgtc1; //current_format = cl_compressed_signed_red_rgtc1; //current_format = cl_compressed_rg_rgtc2; //current_format = cl_compressed_signed_rg_rgtc2; //current_format = cl_compressed_rgb_s3tc_dxt1; //current_format = cl_compressed_rgba_s3tc_dxt1; //current_format = cl_compressed_rgba_s3tc_dxt3; //current_format = cl_compressed_rgba_s3tc_dxt5; //current_format = cl_compressed_srgb_s3tc_dxt1; //current_format = cl_compressed_srgb_alpha_s3tc_dxt1; //current_format = cl_compressed_srgb_alpha_s3tc_dxt3; //current_format = cl_compressed_srgb_alpha_s3tc_dxt5; display_gc = &gc; update_images(); CL_Font font(gc, "tahoma", 24); // Run until someone presses escape while (!quit) { gc.clear(CL_Colorf(0.0f,0.0f,0.2f)); tux_original.draw(gc, 0, 0); tux_convert.draw(gc, 400, 0); tux_unconvert.draw(gc, 800, 0); font.draw_text(gc, 10, 400, "cl_rgba8"); if (gl_supported) { font.draw_text(gc, 410, 400, "converted"); } else { font.draw_text(gc, 410, 400, "NOT SUPPORTED BY clanGL"); } font.draw_text(gc, 810, 400, "converted back to cl_rgba8"); window.flip(1); // This call processes user input and other events CL_KeepAlive::process(0); } return 0; }
int GameRunner::main(const std::vector<CL_String> &args) { // Initialise clanlib by instanciating these classes. // when the get destroyed after scope goes away, they clean // themselves up (I think) so no need to deinitialise. // We never actually use these variables again. CL_SetupCore setup_core; CL_SetupDisplay setup_display; std::vector<CL_String> my_args = args; CL_String device = "GL"; for(std::vector<CL_String>::iterator arg = my_args.begin(); arg != my_args.end(); ++arg) { CL_Console::write_line(*arg); if(*arg == "-d") { device = *++arg; } } CL_Console::write_line(device); // setup clanlib correctly (doesn't work) CL_SetupGL* setup_gl = 0; CL_SetupGL1* setup_gl1 = 0; CL_SetupSDL* setup_sdl = 0; CL_SetupGDI* setup_gdi = 0; if(device == "GL") { setup_gl = new CL_SetupGL(); } if(device == "GL1") { setup_gl1 = new CL_SetupGL1(); } if(device == "SDL") { setup_sdl = new CL_SetupSDL(); } if(device == "GDI") { setup_gdi = new CL_SetupGDI(); } // command line argument handling //CL_CommandLine argp; //argp.add_doc("Play Drillboy!"); //argp.add_option('d', "device", "DEVICE", "Choose a device from GL1, GL, SDL or GDI"); //argp.parse_args(args); //CL_SetupGL1 setup_gl1; // use gl1 as opengl2 target breaks for me // CL_SetupSDL setup_sdl; // use sdl as render target //CL_SetupGDI setup_gdi; // use gdi as render target //CL_SetupGL setup_gl; try { // Set the window description CL_DisplayWindowDescription desc; desc.set_title("Drillboy"); desc.set_size(CL_Size(800, 600), true); // Lets actually make a window now called Drillboy 800x600 CL_DisplayWindow window(desc); // Grab the graphics context so we have a handle to call // drawing functions on CL_GraphicContext graphics = window.get_gc(); // Grab the keyboard so we can ask it about key presses CL_InputDevice keyboard = window.get_ic().get_keyboard(); // Tell console (as in, text-based debug output) we are good to go CL_Console::write_line("ClanLib init complete..."); // Before game loop begins, set screen to black via graphics context graphics.clear(CL_Colorf::black); // shortcut for CL_Colorf c(0,0,0) GameEngine engine(window, graphics, keyboard); bool running = true; // infinite loop to run the game while(running) { // Run the game engine running = engine.run(); } if(setup_gl) delete setup_gl; if(setup_gl1) delete setup_gl1; if(setup_sdl) delete setup_sdl; if(setup_gdi) delete setup_gdi; // if we're this far, game finished running successfully, bye bye return 0; } catch(CL_Exception exception) { // output the exception's message CL_Console::write_line("ClanLib Exception caught:"); CL_Console::write_line(exception.message); // Display the stack trace associated with the exception (it's an array of strings) std::vector<CL_String> stacktrace = exception.get_stack_trace(); // if there is a stacktrace (because it has at least 1 line) // then iterate through the vector and output each line if (stacktrace.size() > 0) { CL_Console::write_line("Stack Trace:"); for(std::vector<CL_String>::iterator line = stacktrace.begin(); line != stacktrace.end(); ++line) { CL_Console::write_line(*line); } } return -1; } }
// The start of the Application int App::start(const std::vector<CL_String> &args) { quit = false; // Set the window CL_DisplayWindowDescription desc; desc.set_title("ClanLib Worker GC Example"); desc.set_size(CL_Size(640, 480), true); desc.set_allow_resize(true); CL_DisplayWindow window(desc); CL_OpenGL::set_active(NULL); // wglCreateContextAttribsARB will fail if the shared context is current in a different thread. WorkerGC worker_gc; CL_System::sleep(200); // Fixme // 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(); worker_gc.Start("../../../Examples/Game/DiceWar/Resources/lobby_background1.png"); CL_Sprite spr_logo; float sin_count = 0.0f; float ypos = 0.0f; float ydir = 0.3f; unsigned int last_time = CL_System::get_time(); // Run until someone presses escape while (!quit) { unsigned int current_time = CL_System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; if (!spr_logo.is_null()) { gc.clear(CL_Colorf(0.0f,0.0f,0.2f)); spr_logo.draw(gc, (float) gc.get_width()-spr_logo.get_width(), (float) gc.get_height()-spr_logo.get_height()); } else { gc.clear(CL_Colorf(0.5f,0.0f,0.0f)); } // Move the lines ypos += ydir * time_delta_ms; if (ydir > 0.0f) { if ((ypos+200.0f) >= gc.get_height()) { ypos = (float) (gc.get_height() - 200); ydir *= -1.0f; } } else { if (ypos <= 0.0f) { ypos = 0.0f; ydir *= -1.0f; } } CL_Draw::fill(gc, 0, ypos-1.0f, (float) gc.get_width(), ypos-8.0f,CL_Colorf(1.0f, 1.0f, 1.0f)); CL_Draw::fill(gc, 0, ypos+198.0f, (float) gc.get_width(), ypos+190.0f, CL_Colorf(1.0f, 1.0f, 1.0f)); // Flip the display, showing on the screen what we have drawed // since last call to flip() window.flip(1); if (worker_gc.IsReady()) { spr_logo = worker_gc.Get(); } // This call processes user input and other events CL_KeepAlive::process(0); } return 0; }
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; }
int Application::main(const std::vector<CL_String> &args) { try { #ifdef DEBUG // Crea una ventan en consola para la salida de texto si no está disponible CL_ConsoleWindow console("JATG", 80, 1000); // 1000 permite una barra vertical CL_ConsoleLogger logger; #endif // Crea la ventana CL_DisplayWindowDescription desc; desc.set_title("JATG"); desc.set_size(CL_Size(1024,768), true); // Usa esta resolución desc.set_fullscreen(true); desc.set_decorations(false); CL_DisplayWindow window(desc); CL_GraphicContext gc = window.get_gc(); CL_Mat4f matrix = CL_Mat4f::scale( (float) gc.get_width() / 1024.0f, (float) gc.get_height() / 768.0f, 1.0f); gc.set_modelview(matrix); CL_SoundOutput output(44100); //Inicializa Frecuencia // Crea el mundo Mundo mundo(window); // Corre el bucle del juego mundo.gameloop(); } catch (CL_Exception& exception) { CL_Console::write_line("Excepcion Tomada:"); CL_Console::write_line(exception.message); std::vector<CL_String> stacktrace = exception.get_stack_trace(); int tamaño = stacktrace.size(); if (tamaño > 0) { CL_Console::write_line("Stack Trace:"); for (int i=0; i < tamaño; i++) { CL_Console::write_line(stacktrace[i]); } } CL_Console::wait_for_key(); //Espera por una tecla } 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 Basic::start(const std::vector<CL_String> &args) { quit = false; // Set the window CL_DisplayWindowDescription desc; desc.set_title("ClanLib OpenCL Basic Example"); desc.set_size(CL_Size(640, 480), true); desc.set_allow_resize(true); CL_DisplayWindow window(desc); // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &Basic::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, &Basic::on_input_up); // Get the graphic context CL_GraphicContext gc = window.get_gc(); cl_int error; cl_platform_id platform; cl_uint platforms; error = clGetPlatformIDs(1, &platform, &platforms); if (error != CL_SUCCESS) throw CL_Exception("clGetPlatformIDs failed"); cl_device_id device; cl_uint devices; error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &devices); if (error != CL_SUCCESS) throw CL_Exception("clGetDeviceIDs failed"); cl_context_properties properties[]={CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0}; cl_context context; context = clCreateContext(properties, 1, &device, NULL, NULL, &error); if (error != CL_SUCCESS) throw CL_Exception("clCreateContext failed"); cl_command_queue cq; cq = clCreateCommandQueue(context, device, 0, &error); if (error != CL_SUCCESS) throw CL_Exception("clCreateCommandQueue failed"); static const char source_code[] = "" "__kernel void simple_test(__global float *vals)" "{" " const uint i = get_global_id(0);" "" "vals[i] = 1.23;" "}" ""; const char *src[] = {source_code}; cl_program prog; prog = clCreateProgramWithSource(context, 1, src, NULL, &error); if (error != CL_SUCCESS) throw CL_Exception("clCreateProgramWithSource failed"); error = clBuildProgram(prog, 0, NULL, "", NULL, NULL); if (error != CL_SUCCESS) throw CL_Exception("clBuildProgram failed"); cl_kernel k_simple_test; k_simple_test = clCreateKernel(prog, "simple_test", &error); if (error != CL_SUCCESS) throw CL_Exception("clCreateKernel failed"); static const int buffer_length = 64; cl_mem ref_buffer; ref_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * buffer_length, NULL, &error); if (error != CL_SUCCESS) throw CL_Exception("clCreateBuffer failed"); error = clSetKernelArg(k_simple_test, 0, sizeof(ref_buffer), &ref_buffer); if (error != CL_SUCCESS) throw CL_Exception("clSetKernelArg failed"); const size_t worksize = buffer_length; error = clEnqueueNDRangeKernel(cq, k_simple_test, 1, NULL, &worksize, NULL, 0, NULL, NULL); if (error != CL_SUCCESS) throw CL_Exception("clEnqueueNDRangeKernel failed"); error = clFinish(cq); if (error != CL_SUCCESS) throw CL_Exception("clFinish failed"); float ram_buffer[buffer_length]; error=clEnqueueReadBuffer(cq, ref_buffer, CL_TRUE, 0, sizeof(float) * buffer_length, ram_buffer, 0, NULL, NULL); if (error != CL_SUCCESS) throw CL_Exception("clEnqueueReadBuffer failed"); error=clFinish(cq); if (error != CL_SUCCESS) throw CL_Exception("clFinish failed"); // Clean up clReleaseKernel(k_simple_test); clReleaseProgram(prog); clReleaseCommandQueue(cq); clReleaseContext(context); clReleaseMemObject(ref_buffer); // Test output for (int cnt=0;cnt < buffer_length; cnt++) { if (ram_buffer[cnt] != 1.23f) throw CL_Exception("It did not work!"); } CL_Font font(gc, "tahoma", 24); // Run until someone presses escape while (!quit) { gc.clear(CL_Colorf(0.0f,0.0f,0.2f)); font.draw_text(gc, 32, 32, "Success"); window.flip(1); CL_KeepAlive::process(0); } return 0; }
// The start of the Application int Tetris::start(const std::vector<CL_String> &args) { quit = false; finish = false; // leftborderlist = new LeftBordeList(); // rightbordelist = new RightBordeList(); // Set the window CL_DisplayWindowDescription desc; desc.set_title("Tetris"); desc.set_size(CL_Size(320, 640), true); desc.set_allow_resize(true); CL_DisplayWindow window(desc); // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &Tetris::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, &Tetris::on_input_up); // Get the graphic context CL_GraphicContext gc = window.get_gc(); // Load a sprite from a png-file //CL_Sprite spr_logo(gc, "Resources/logo.png"); float sin_count = 0.0f; float ypos = 0.0f; float ydir = 0.3f; unsigned int last_time = CL_System::get_time(); CL_Font font(gc, "Utopia", 40); linesRemoved = 0; // Run until someone presses escape while (!quit) { unsigned int current_time = CL_System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; float shift = time_delta_ms/20; shift = 1.0f; //std::cout << "shift = " << shift << std::endl; // Clear the display in a dark blue nuance // The four arguments are red, green, blue and alpha gc.clear(CL_Colorf(25.0f,25.0f,25.0f)); std::string s; std::stringstream out; out << linesRemoved; s = out.str(); font.draw_text(gc, 250,40, s.c_str(), CL_Colorf::blue); int l = bottomborderlist.getLineNumberToDelete(); while (l != -1) { l = bottomborderlist.getLineNumberToDelete(); if (l!= -1) { if (!bottomborderlist.isFullHeight()) { linesRemoved++; } } bottomborderlist.removeLine(l); } if (!figlist.checkCollisionDown(bottomborderlist)) { figlist.moveDown(shift); } else { FigureList newfl = figlist; newfl.setStablePosition(); if (!finish) { bottomborderlist.addList(newfl.getFigureList()); if (figlist.checkCollisionDown(bottomborderlist)) { figlist.reset(); } else { figlist.reset(); figlist.clearFigureList(); } } if (figlist.checkCollisionDown(bottomborderlist)) { finish = true; } } leftborderlist.draw(gc); rightborderlist.draw(gc); bottomborderlist.draw(gc); if (finish == false && !figlist.checkCollisionDown(bottomborderlist)) { figlist.draw(gc); } else { if (linesRemoved < 5) { font.draw_text(gc, 10,40, "You Lost", CL_Colorf::black); } else { font.draw_text(gc, 10,40, "You Won", CL_Colorf::black); } } // 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(0); } return 0; }
void Game::run() { //_________________________________________________________________ // V I D E O S E T T I N G S screen_x_res = 640; screen_y_res = 480; CL_DisplayWindowDescription desc; desc.set_title("Roadgeddon"); desc.set_size(CL_Size(screen_x_res, screen_y_res), true); desc.set_allow_resize(false); CL_DisplayWindow window(desc); CL_Slot slot_quit = window.sig_window_close() .connect(this,&Game::on_quit); CL_Slot slot_keyboard_key_down = (window.get_ic().get_keyboard()).sig_key_down() .connect(this,&Game::on_key_down); CL_Slot slot_keyboard_key_up = (window.get_ic().get_keyboard()).sig_key_up() .connect(this,&Game::on_key_up); CL_Slot slot_mouse_moved = (window.get_ic().get_mouse()).sig_pointer_move() .connect(this,&Game::on_pointer_move); CL_Slot slot_mouse_down = (window.get_ic().get_mouse()).sig_key_down() .connect(this,&Game::on_pointer_down); CL_Slot slot_mouse_up = (window.get_ic().get_mouse()).sig_key_up() .connect(this,&Game::on_pointer_up); gc = window.get_gc(); CL_ResourceManager resources("resources.xml"); resources_=&resources; int time_elapsed_ms = 0; int lastTime = 0; int currentTime = 0; currentTime = CL_System::get_time(); lastTime = CL_System::get_time(); //________________________________________________________________ // S O U N D S total_channels=3; current_channel=1; CL_SoundBuffer music("Music1",&resources); music.set_volume(0.3f); sound_session1.play(); sound_session2.play(); sound_session3.play(); total_samples = 6; samples.resize(total_samples); samples[0] = CL_SoundBuffer("Explosion1",&resources); samples[1] = CL_SoundBuffer("Explosion2",&resources); samples[2] = CL_SoundBuffer("Hurt1",&resources); samples[3] = CL_SoundBuffer("Hurt2",&resources); samples[4] = CL_SoundBuffer("Powerup1",&resources); samples[5] = CL_SoundBuffer("Shoot1",&resources); for(int i = 0; i<total_samples; i++) { samples[i].set_volume(0.3f); } CL_SoundBuffer_Session music_session = music.prepare(); music_session_ = &music_session; music_session.set_looping(true); music_session.play(); is_music_muted = false; //________________________________________________________________ // G A M E P R E P Map map(*this); Player player(*this); mapP = ↦ playerP = &player; time_elapsed_since_last_enemy=0; //________________________________________________________________ // O T H E R srand(CL_System::get_time()); while (!quit) { currentTime = CL_System::get_time(); time_elapsed_ms = currentTime - lastTime; lastTime = currentTime; update_game(time_elapsed_ms); update_signal.invoke(time_elapsed_ms); map.drawBackground(); draw_signal.invoke(); // 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(0); // Sleep for a little while to avoid using too much of the CPU. CL_System::sleep(5); if(objects_for_deletion.size()>0) { std::list<Gameobject *>::iterator it; for(it=objects_for_deletion.begin(); it!= objects_for_deletion.end(); ++it) { delete (*it); } objects_for_deletion.clear(); } } }