Esempio n. 1
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)));
	}
}
Esempio n. 2
0
VideoWindow::VideoWindow(OpenNi *kinect)
{
   cout << "videoWindow" << endl;
   this->kinect = kinect;
   CL_DisplayWindowDescription window_desc;

   window_desc.set_size(CL_Size(640, 480), true);
   window_desc.set_title("MagnetoPong!!!11einself - Video - mouseklick = start/stop");
   window_desc.set_visible(true);
   window_desc.set_position(CL_Rect(1,1,CL_Size(640, 480)),true);

   window = CL_DisplayWindow(window_desc);

   CL_Slot slot_quit = window.sig_window_close().connect(this, &VideoWindow::on_window_close);
   graphicContext = window.get_gc();
   graphicContext.clear(CL_Colorf::white); //Fenster mit Weiß löschen
   window.show();
   window.flip();
   window.set_visible(true, false);
   window_open = true;
   show_video  = true;
   mouse_down  = false;

   mouse = new CL_InputDevice();
   *mouse = window.get_ic().get_mouse(0);
   timepast = 42; //24fps;
}
CL_DisplayWindow CL_GUIWindowManagerProvider_System::get_display_window(CL_GUITopLevelWindow *handle) const
{
	std::map<CL_GUITopLevelWindow *, CL_GUITopLevelWindowSystem *>::const_iterator it = window_map.find(handle);
	if (it != window_map.end())
		return it->second->window;
	else
		return CL_DisplayWindow();
}
Esempio n. 4
0
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();
}
Esempio n. 5
0
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);
}
void CL_GUIWindowManagerProvider_System::create_window(
	CL_GUITopLevelWindow *handle,
	CL_GUITopLevelWindow *owner,
	CL_GUIComponent *component,
	CL_GUITopLevelDescription description)
{
	CL_GUITopLevelWindowSystem *owner_window = 0;
	if (owner)
	{
		owner_window = window_map[owner];
		description.set_owner_window(owner_window->window);
	}

	CL_GUITopLevelWindowSystem *top_level_window;

#ifdef WIN32	// Cached windows do not work on Linux
	if (description.get_using_gui_window_cache())
	{
		used_cached_windows++;

		if (used_cached_windows <= cached_windows.size())
		{
			top_level_window = cached_windows[used_cached_windows-1];
			top_level_window->slots = CL_SlotContainer();
			cache_window_handles[handle] = top_level_window->window.get_hwnd();
		}
		else
		{
			top_level_window = new CL_GUITopLevelWindowSystem;
			top_level_window->window = CL_DisplayWindow(description);
			cached_windows.push_back(top_level_window);
			cache_window_handles[handle] = top_level_window->window.get_hwnd();
		}
	}
	else
#endif
	{
		top_level_window = new CL_GUITopLevelWindowSystem;
		top_level_window->window = CL_DisplayWindow(description);
	}

	top_level_window->window.get_gc().set_map_mode(cl_map_2d_upper_left);

	top_level_window->slots.connect(top_level_window->window.sig_lost_focus(), this, &CL_GUIWindowManagerProvider_System::on_displaywindow_lost_focus, handle);
	top_level_window->slots.connect(top_level_window->window.sig_got_focus(), this, &CL_GUIWindowManagerProvider_System::on_displaywindow_got_focus, handle);
	top_level_window->slots.connect(top_level_window->window.sig_resize(), this, &CL_GUIWindowManagerProvider_System::on_displaywindow_resize, handle);
	top_level_window->slots.connect(top_level_window->window.sig_paint(), this, &CL_GUIWindowManagerProvider_System::on_displaywindow_paint, handle);
	top_level_window->slots.connect(top_level_window->window.sig_window_close(), this, &CL_GUIWindowManagerProvider_System::on_displaywindow_window_close, handle);
	top_level_window->slots.connect(top_level_window->window.sig_window_destroy(), this, &CL_GUIWindowManagerProvider_System::on_displaywindow_window_destroy, handle);

	CL_InputContext& ic = top_level_window->window.get_ic();
	top_level_window->slots.connect(ic.get_mouse().sig_key_up(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
	top_level_window->slots.connect(ic.get_mouse().sig_key_down(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
	top_level_window->slots.connect(ic.get_mouse().sig_key_dblclk(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
	top_level_window->slots.connect(ic.get_mouse().sig_pointer_move(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
	top_level_window->slots.connect(ic.get_keyboard().sig_key_up(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
	top_level_window->slots.connect(ic.get_keyboard().sig_key_down(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);

	for (int i = 0; i < ic.get_tablet_count(); ++i)
	{
		top_level_window->slots.connect(ic.get_tablet(i).sig_axis_move(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
		top_level_window->slots.connect(ic.get_tablet(i).sig_key_down(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
		top_level_window->slots.connect(ic.get_tablet(i).sig_key_dblclk(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
		top_level_window->slots.connect(ic.get_tablet(i).sig_key_up(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
		top_level_window->slots.connect(ic.get_tablet(i).sig_proximity_change(), this, &CL_GUIWindowManagerProvider_System::on_input, handle);
	}

	window_map[handle] = top_level_window;
}
Esempio n. 7
0
// 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("Input 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_Slot slot_mouse_down = (window.get_ic().get_mouse()).sig_key_down().connect(this, &App::on_mouse_down);
	CL_Slot slot_mouse_dblclick = (window.get_ic().get_mouse()).sig_key_dblclk().connect(this, &App::on_mouse_down);

	std::vector<CL_Slot> slot_joystick;
	int max_joysticks = window.get_ic().get_joystick_count();
	for (int joystick_number=0; joystick_number < max_joysticks; joystick_number++)
	{
		CL_Slot current_joystick = window.get_ic().get_joystick(joystick_number).sig_key_down().connect(this, &App::on_joystick_down, joystick_number);
		slot_joystick.push_back(current_joystick);
	}

	CL_GraphicContext gc = window.get_gc();

	font = CL_Font(gc, "tahoma", 16);
	vector_font = CL_Font_Vector("../../Game/DiceWar/Resources/bitstream_vera_sans/VeraBd.ttf", 256);

	calculate_matrix(gc);

	while(!quit)
	{
		gc.set_map_mode(cl_map_2d_upper_left);

		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, "Press any key, mouse button or joystick button to fire text. Use mouse to control direction.");

		int yoffset = gc.get_height() - 20;
		const int y_gap = 20;

		// Draw Keyboard Information
		draw_keyboard_state(gc, yoffset);
		yoffset -= y_gap;

		// Draw Mouse Information
		draw_mouse_state(gc, yoffset);
		yoffset -= y_gap;
	
		// Draw Joysticks Information
		for (int joystick_number=0; joystick_number < max_joysticks; joystick_number++)
		{
			draw_joystick_state(gc, joystick_number, yoffset);
			yoffset -= y_gap;
		}

		// Draw Tablet Information
		int max_tablets = window.get_ic().get_tablet_count();
		for (int tablet_number=0; tablet_number < max_tablets; tablet_number++)
		{
			draw_tablet_state(gc, tablet_number, yoffset);
			yoffset -= y_gap;
		}

		gc.set_map_mode(cl_user_projection);
		gc.set_projection(projection_matrix);
		gc.set_modelview(modelview_matrix);

		draw_text_shooter(gc);

		window.flip(1);

		CL_KeepAlive::process();
	}

	return 0;
}
Esempio n. 8
0
// 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;
}
Esempio n. 9
0
    ortho() :
      pump_factor_(4) 
    {

//         glVertexPointer(4, GL_FLOAT, 0, ptr);
        //glEnableClientState( GL_VERTEX_ARRAY );
//         glColorPointer(

        //std::ifstream is( "cryistal-castle-hidden-ramp.txt" );
//         std::ifstream is( "house1.txt" );
        //std::ifstream is( "cryistal-castle-tree-wave.txt" );

//         assert( is.good() );
//         height_fields_ = crystal_bits::load_crystal(is, pump_factor_);
//         std::cout << "hf: " << height_fields_.size() << "\n";
//         
//         
//         
//         scene_static_.init_solid(height_fields_);
//         
        
//         scene_static_.init_solid_from_crystal(is, pump_factor_);
        

//         scene_static_.init_planes();

//         uint64_t scene_hash = scene_static_.hash();
//         
//         try {
//             std::ifstream is( "ff.bin" );
//             
//             
//             light_static_ = light_static( is, scene_hash );
//         } catch( std::runtime_error x ) {
//             
//             std::cerr << "load failed. recreating. error:\n" << x.what() << std::endl;
//             
//             light_static_ = setup_formfactors(scene_static_.planes(), scene_static_.solid());    
//         }
//         
//         if( !false ) {
//             std::ofstream os( "ff.bin" );
//             light_static_.write(os, scene_hash);
//         }
//         
//         
//         light_dynamic_ = light_dynamic(scene_static_.planes().size() );
        
        CL_OpenGLWindowDescription desc;
        desc.set_size( CL_Size( 1024, 768 ), true );

        desc.set_depth_size(16);
        //std::cout << "depth: " << desc.get_depth_size();
        
        wnd_ = CL_DisplayWindow(desc);

        CL_GraphicContext_GL gc = wnd_.get_gc();
//      //CL_Mat4f proj = CL_Mat4f::ortho( 0, 1024, 0, 768, 100, -100 );


        gc.set_active();
#ifdef TEST_OPENCL
        try {
            init_opencl();
        } catch( cl::Error x ) {
            
//             std::array<void*, 256> bt;
//             //void *bt[256];
//             
//             size_t size = backtrace( bt.data(), bt.size() );
//             char **strings = backtrace_symbols( bt.data(), size );
//             std::cout << "backtrace: " << size << "\n";
//             for( size_t i = 0; i < size; ++i ) {
//                 std::cout << i << " " << strings[i] << "\n";
//             }
//             free( strings );
            
            std::cerr << "opencl initialization failed\ncall: " << x.what() << "\nerror code: " << cl_str_error( x.err() ) << "\n";            
            throw;
        }
#endif
      //  throw 0;
        
        glMatrixMode(GL_PROJECTION);                        //hello

        
        

        CL_Mat4f proj = CL_Mat4f::perspective( 60, 1.5, 2, 200 );
//      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 );


        //CL_Texture tex(gc, 64, 64 );


        struct texel {
            GLubyte col[3];
            GLubyte alpha;

            texel() {
                col[0] = 128;
                col[1] = 128;
                col[2] = 128;
                alpha = 255;

            }
        };

        std::array<texel,64 * 64> tex_data;

        glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0);
//      glGenTextures(1, &texName);
//      glBindTexture(GL_TEXTURE_2D, texName);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data.data());


//      gc.set_map_mode(cl_user_projection);
//      gc.set_projection(proj);
//
//      gc.flush_batcher();
//      glMatrixMode(GL_PROJECTION);


        glMatrixMode(GL_MODELVIEW);


        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);
        glDepthFunc(GL_LESS);
        
        glEnable(GL_TEXTURE_2D);
        glShadeModel(GL_FLAT);
    }