void run() { quit = false; CL_DisplayWindowDescription window_desc; window_desc.set_size(CL_Size(sizex, sizey), true); window_desc.set_title("Chess"); window_desc.set_allow_resize(true); CL_DisplayWindow window(window_desc); CL_Slot slot_quit = window.sig_window_close().connect(this, &SpritesExample::on_window_close); window.func_window_resize().set(this, &SpritesExample::resize); CL_GraphicContext gc = window.get_gc(); CL_InputDevice keyboard = window.get_ic().get_keyboard(); CL_ResourceManager resources("resources.xml"); CL_Image lol(gc,"Board",&resources); CEGUI::OpenGLRenderer & myRenderer = CEGUI::OpenGLRenderer::bootstrapSystem(); CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton(); CEGUI::DefaultWindow* root = (CEGUI::DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root"); CEGUI::SchemeManager::getSingleton().create("TaharezLook.scheme"); CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow"); CEGUI::FrameWindow* wnd = (CEGUI::FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window"); root->addChildWindow(wnd); wnd->setPosition(CEGUI::UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f))); wnd->setSize(CEGUI::UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f))); // now we set the maximum and minum sizes for the new window. These are // specified using relative co-ordinates, but the important thing to note // is that these settings are aways relative to the display rather than the // parent window. // // here we set a maximum size for the FrameWindow which is equal to the size // of the display, and a minimum size of one tenth of the display. wnd->setMaxSize(CEGUI::UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f))); wnd->setMinSize(CEGUI::UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f))); // As a final step in the initialisation of our sample window, we set the window's // text to "Hello World!", so that this text will appear as the caption in the // FrameWindow's titlebar. wnd->setText("Hello World!"); CEGUI::System::getSingleton().renderGUI(); window.flip(); while (!quit) { if(keyboard.get_keycode(CL_KEY_ESCAPE) == true) quit = true; CL_Colorf red(155/255.0f, 60/255.0f, 68/255.0f); //CL_Draw::fill(gc, CL_Rectf(0, sizey, sizex, 0), red); //lol.draw(gc,CL_Rectf(0,sizey,sizex,0)); //CEGUI::System::getSingleton().renderGUI(); //window.flip(); CL_KeepAlive::process(); CL_System::sleep(10); } }
void CL_InputBuffer::add_device(CL_InputDevice &device) { impl->slots.connect(device.sig_key_down(), impl, &CL_InputBuffer_Generic::on_key_down); impl->slots.connect(device.sig_key_up(), impl, &CL_InputBuffer_Generic::on_key_up); }
void run() { quit = false; CL_DisplayWindowDescription window_desc; window_desc.set_size(CL_Size(1920, 1080), true); window_desc.set_title("Luna"); CL_DisplayWindow window(window_desc); CL_Slot slot_quit = window.sig_window_close().connect(this, &RootWindow::on_window_close); CL_GraphicContext gc = window.get_gc(); CL_InputDevice keyboard = window.get_ic().get_keyboard(); CL_FontDescription font_desc; font_desc.set_typeface_name("Monospace"); font_desc.set_height(16); CL_Font_System font(gc, font_desc); CL_FontMetrics fmetrics = font.get_font_metrics(); int fntWidth = fmetrics.get_max_character_width(); CL_SpriteDescription spr_desc; spr_desc.add_frame(CL_ImageProviderFactory::load("spaceship.png")); CL_Sprite node(gc, spr_desc); node.set_play_loop(true); node.set_play_pingpong(false); node.set_frame(0); CL_Image pict(gc,"stars.jpg"); x = gc.get_width() / 2 ; y = gc.get_height() / 2 ; U = 0; W = 0; V = 0; H = 0; step = 0.2; while (!quit) { if(keyboard.get_keycode(CL_KEY_ESCAPE) == true) quit = true; if(keyboard.get_keycode(CL_KEY_LEFT) == true) U -= step ; if(keyboard.get_keycode(CL_KEY_RIGHT) == true) U += step ; if(keyboard.get_keycode(CL_KEY_UP) == true) V -= step ; if(keyboard.get_keycode(CL_KEY_DOWN) == true) V += step ; if(x < -node.get_width()) { x = gc.get_width(); } else if(x > gc.get_width()) { x = -node.get_width(); } else x += U ; if(y < step) { y = step; V = 0; } else if(y > gc.get_height()-node.get_height()) { y = gc.get_height()-node.get_height(); V = 0; } else y += V; gc.clear(); pict.draw(gc,W,H); pict.draw(gc,W,H-gc.get_height() ); pict.draw(gc,W-gc.get_width(),H ); H++ ; if( H > gc.get_height() ) H = 0; node.draw(gc, x, y); CL_String velocity = cl_format("Velocity U[%1] V[%2] --- Coordinate X[%3] Y[%4] --- Origin W[%5] H[%6]",U,V,x,y,W,H); font.draw_text(gc, gc.get_width()/2 - (velocity.length() * fntWidth)/2, 16, velocity); window.flip(); CL_KeepAlive::process(); CL_System::sleep(10); } }
int App::start(const std::vector<CL_String> &args) { CL_OpenGLWindowDescription description; description.set_title("GLSL Test"); description.set_size(CL_Size(1024, 768), true); CL_DisplayWindow window(description); CL_InputDevice keyboard = window.get_ic().get_keyboard(); CL_GraphicContext gc = window.get_gc(); CL_Slot slot_window_close = window.sig_window_close().connect(this, &App::window_close); // Load and link shaders CL_ProgramObject shader = CL_ProgramObject::load(gc, "Resources/vertex_shader.glsl", "Resources/fragment_shader.glsl"); shader.bind_attribute_location(0, "Position"); if (!shader.link()) throw CL_Exception("Unable to link shader program: Error:" + shader.get_info_log()); quit = false; while (!keyboard.get_keycode(CL_KEY_ESCAPE) && !quit ) { gc.clear(); gc.set_program_object(shader, cl_program_matrix_modelview_projection); //shader.set_uniform1i("SourceTexture", 0); int xpos = 0; int size = 16; int gap = size + 2; //-------- Test 1 CL_Mat2f matrix2_a = CL_Mat2f(3, 1, 2, 4); CL_Mat2f matrix2_b = CL_Mat2f(-3, 7, 2, 5); CL_Mat2f matrix2_result = CL_Mat2f::multiply(matrix2_a, matrix2_b); CL_Mat2f matrix2_a_temp = matrix2_a; if (CL_Mat2i(matrix2_result) != CL_Mat2i(matrix2_a * matrix2_b)) throw CL_Exception("Failure"); shader.set_uniform1i("test_id", 1); shader.set_uniform_matrix("matrix2_a", matrix2_a); shader.set_uniform_matrix("matrix2_b", matrix2_b); shader.set_uniform_matrix("matrix2_result", matrix2_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 2 CL_Mat3f matrix3_a = CL_Mat3f(3, 1, 2, 4, 5 ,6, 4, 2, 1); CL_Mat3f matrix3_b = CL_Mat3f(4, 7, 2, 5, 3, 5, 2, 9, 3); CL_Mat3f matrix3_result = CL_Mat3f::multiply(matrix3_a, matrix3_b); CL_Mat3f matrix3_a_temp = matrix3_a; if (CL_Mat3i(matrix3_result) != CL_Mat3i(matrix3_a * matrix3_b)) throw CL_Exception("Failure"); shader.set_uniform1i("test_id", 2); shader.set_uniform_matrix("matrix3_a", matrix3_a); shader.set_uniform_matrix("matrix3_b", matrix3_b); shader.set_uniform_matrix("matrix3_result", matrix3_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 3 static float test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2}; static float test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2}; CL_Mat4f matrix4_a = CL_Mat4f(test_a_values); CL_Mat4f matrix4_b = CL_Mat4f(test_b_values); CL_Mat4f matrix4_result = CL_Mat4f::multiply(matrix4_a, matrix4_b); CL_Mat4f matrix4_a_temp = matrix4_a; if (CL_Mat4i(matrix4_result) != CL_Mat4i(matrix4_a * matrix4_b)) throw CL_Exception("Failure"); shader.set_uniform1i("test_id", 3); shader.set_uniform_matrix("matrix4_a", matrix4_a); shader.set_uniform_matrix("matrix4_b", matrix4_b); shader.set_uniform_matrix("matrix4_result", matrix4_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 4 matrix2_result = CL_Mat2f::subtract(matrix2_a, matrix2_b); matrix2_a_temp = matrix2_a; if (CL_Mat2i(matrix2_result) != CL_Mat2i(matrix2_a - matrix2_b)) throw CL_Exception("Failure"); shader.set_uniform1i("test_id", 4); shader.set_uniform_matrix("matrix2_a", matrix2_a); shader.set_uniform_matrix("matrix2_b", matrix2_b); shader.set_uniform_matrix("matrix2_result", matrix2_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 5 matrix3_result = CL_Mat3f::subtract(matrix3_a, matrix3_b); matrix3_a_temp = matrix3_a; if (CL_Mat3i(matrix3_result) != CL_Mat3i(matrix3_a - matrix3_b)) throw CL_Exception("Failure"); shader.set_uniform1i("test_id", 5); shader.set_uniform_matrix("matrix3_a", matrix3_a); shader.set_uniform_matrix("matrix3_b", matrix3_b); shader.set_uniform_matrix("matrix3_result", matrix3_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 6 matrix4_result = CL_Mat4f::subtract(matrix4_a, matrix4_b); matrix4_a_temp = matrix4_a; if (CL_Mat4i(matrix4_result) != CL_Mat4i(matrix4_a - matrix4_b)) throw CL_Exception("Failure"); shader.set_uniform1i("test_id", 6); shader.set_uniform_matrix("matrix4_a", matrix4_a); shader.set_uniform_matrix("matrix4_b", matrix4_b); shader.set_uniform_matrix("matrix4_result", matrix4_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 7 CL_Vec2f vector2_a(2,3); CL_Vec2f vector2_result = vector2_a * matrix2_a; shader.set_uniform1i("test_id", 7); shader.set_uniform_matrix("matrix2_a", matrix2_a); shader.set_uniform2f("vector2_a", vector2_a); shader.set_uniform2f("vector2_result", vector2_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 8 vector2_result = matrix2_a * vector2_a; shader.set_uniform1i("test_id", 8); shader.set_uniform_matrix("matrix2_a", matrix2_a); shader.set_uniform2f("vector2_a", vector2_a); shader.set_uniform2f("vector2_result", vector2_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 9 CL_Vec3f vector3_a(3,5,6); CL_Vec3f vector3_result = vector3_a * matrix3_a; shader.set_uniform1i("test_id", 9); shader.set_uniform_matrix("matrix3_a", matrix3_a); shader.set_uniform3f("vector3_a", vector3_a); shader.set_uniform3f("vector3_result", vector3_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 10 vector3_result = matrix3_a * vector3_a; shader.set_uniform1i("test_id", 10); shader.set_uniform_matrix("matrix3_a", matrix3_a); shader.set_uniform3f("vector3_a", vector3_a); shader.set_uniform3f("vector3_result", vector3_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 11 CL_Vec4f vector4_a(4,3,5,6); CL_Vec4f vector4_result = vector4_a * matrix4_a; shader.set_uniform1i("test_id", 11); shader.set_uniform_matrix("matrix4_a", matrix4_a); shader.set_uniform4f("vector4_a", vector4_a); shader.set_uniform4f("vector4_result", vector4_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; //-------- Test 12 vector4_result = matrix4_a * vector4_a; shader.set_uniform1i("test_id", 12); shader.set_uniform_matrix("matrix4_a", matrix4_a); shader.set_uniform4f("vector4_a", vector4_a); shader.set_uniform4f("vector4_result", vector4_result); draw(gc, CL_Rect(xpos, 0, CL_Size(size, size))); xpos+=gap; gc.reset_program_object(); window.flip(); CL_System::sleep(10); CL_KeepAlive::process(); } return 0; }