Exemplo n.º 1
0
void Input::ReloadDevices(){
	try { 
		Device* keyboard = new Keyboard();
		keyboard->Init(Game::GetInstance()->hwnd, directInput_);
		devices_.push_back(keyboard);
		hasKeyboard_ = true;	
	}	catch (runtime_error) {
		hasKeyboard_ = false;
	}
	try { 
		nGamepads_ = 0;
		while(nGamepads_<4){
			Gamepad* gamepad = new Gamepad(nGamepads_);
			gamepad->Init(Game::GetInstance()->hwnd, directInput_);
			devices_.push_back(gamepad);
			nGamepads_++;
		}
	}	catch (runtime_error) {
		if(devices_.size()<1)
			throw runtime_error("Fatal error: Neither keyboard, nor gamepad found!");
	}

	try {
		Device* mouse = new Mouse();
		mouse->Init(Game::GetInstance()->hwnd, directInput_);
		devices_.push_back(mouse);
		hasMouse_ = true;
	}	
	catch (runtime_error) {
		hasMouse_ = false;
	}
}
Exemplo n.º 2
0
///
//	main() for HelloBinaryWorld example
//
int ImageFilter2D()
{
    cl_kernel kernel = 0;
    cl_mem imageObjects[2] = { 0, 0 };
    cl_sampler sampler = 0;
    cl_int err;
	char *file_in = "image_Lena512rgb.bmp";
	char *file_out = "image_Lena512rgb_out.bmp";

	//! Setup device
	Device clDevice;
	clDevice.Init();

    //! Make sure the device supports images, otherwise exit
    cl_bool imageSupport = CL_FALSE;
	clGetDeviceInfo(clDevice.DeviceIDs[0], CL_DEVICE_IMAGE_SUPPORT, sizeof(cl_bool),
                    &imageSupport, NULL);
    if (imageSupport != CL_TRUE)
    {
        std::cerr << "OpenCL device does not support images." << std::endl;
        
        return 1;
    }

    //! Init data
    int width, height;	
	imageObjects[0] = LoadImage(clDevice.Context, file_in, width, height);
    if (imageObjects[0] == 0)
    {
        std::cerr << "Error loading: " << std::string(file_in) << std::endl;
        return 1;
    }

    // Create ouput image object
    cl_image_format clImageFormat;
    clImageFormat.image_channel_order = CL_RGBA;
    clImageFormat.image_channel_data_type = CL_UNORM_INT8;
    imageObjects[1] = clCreateImage2D(clDevice.Context,
                                       CL_MEM_WRITE_ONLY,
                                       &clImageFormat,
                                       width,
                                       height,
                                       0,
                                       NULL,
                                       &err);

    if (err != CL_SUCCESS)
    {
        std::cerr << "Error creating CL output image object." << std::endl;
        return 1;
    }


    //! Create sampler for sampling image object
    sampler = clCreateSampler(clDevice.Context,
                              CL_FALSE, // Non-normalized coordinates
                              CL_ADDRESS_CLAMP_TO_EDGE, // Set the color outside edge to color on edge
                              CL_FILTER_NEAREST,
                              &err);

    if (err != CL_SUCCESS)
    {
        std::cerr << "Error creating CL sampler object." << std::endl;
        return 1;
    }


	//! Get kernel
	std::string kernel_name = "gaussian_filter";
	kernel = clDevice.GetKernel(kernel_name);
    if (kernel == NULL)
    {
        std::cerr << "Failed to create kernel" << std::endl;
        return 1;
    }

    //! Set the kernel arguments
    err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &imageObjects[0]);
    err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &imageObjects[1]);
    err |= clSetKernelArg(kernel, 2, sizeof(cl_sampler), &sampler);
    err |= clSetKernelArg(kernel, 3, sizeof(cl_int), &width);
    err |= clSetKernelArg(kernel, 4, sizeof(cl_int), &height);
    if (err != CL_SUCCESS)
    {
        std::cerr << "Error setting kernel arguments." << std::endl;
        return 1;
    }

	//! Set global and local work size
    size_t localWorkSize[2] = { 16, 16 };
    size_t globalWorkSize[2] = { roundUp(localWorkSize[0], width),
                                 roundUp(localWorkSize[1], height) };

    //! Excute kernel
	err = clEnqueueNDRangeKernel(clDevice.CommandQueue, kernel, 2, NULL,
                                    globalWorkSize, localWorkSize,
                                    0, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        std::cerr << "Error queuing kernel for execution." << std::endl;
        return 1;
    }

    //! Get outputs to host
    char *buffer = new char [width * height * 4];
    size_t origin[3] = { 0, 0, 0 };
    size_t region[3] = { width, height, 1};
	err = clEnqueueReadImage(clDevice.CommandQueue, imageObjects[1], CL_TRUE,
                                origin, region, 0, 0, buffer,
                                0, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        std::cerr << "Error reading result buffer." << std::endl;
        return 1;
    }

    std::cout << std::endl;
    std::cout << "Executed program succesfully." << std::endl;

    //! Save the image out to disk
	if (!SaveImage(file_out, buffer, width, height))
    {
        std::cerr << "Error writing output image: " << file_out << std::endl;
        delete [] buffer;
        return 1;
    }

    delete [] buffer;

    return 0;
}
Exemplo n.º 3
0
// Return 0 for no error
int	WindowInit()
{
	gs_WindowInfos.hInstance = GetModuleHandle( NULL );

	#ifndef _WIN64
		//////////////////////////////////////////////////////////////////////////
		// Initialize rounding mode once since we disabled f*****g _ftol2 link error by adding a deprecated compile flag named /QIfist
		// (always following the advice from http://www.benshoof.org/blog/minicrt/)
		static U16	CW;
		__asm
		{
			fstcw	CW							// store fpu control word  
			mov		dx, word ptr [CW]  
			or		dx, 0x0C00                  // rounding: truncate (default)
			mov		CW, dx 
			fldcw	CW							// load modfied control word  
		}  
	#endif

	//////////////////////////////////////////////////////////////////////////
	// Register the new window class
	WNDCLASSA	wc;
	memset( &wc, 0, sizeof(WNDCLASSA) );
	wc.style		 = CS_OWNDC;
	wc.lpfnWndProc   = WndProc;
	wc.hInstance	 = gs_WindowInfos.hInstance;
	wc.lpszClassName = pWindowClass;

	if( !RegisterClass( (WNDCLASSA*) &wc ) )
		return ERR_REGISTER_CLASS;

	//////////////////////////////////////////////////////////////////////////
	// Create the window
	U32	dwExStyle, dwStyle;
	if ( gs_WindowInfos.bFullscreen )
	{
		if ( ChangeDisplaySettings( &ScreenSettings, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
			return ERR_CHANGE_DISPLAY_SETTINGS;

		dwExStyle = WS_EX_APPWINDOW;
		dwStyle   = WS_VISIBLE | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
		ShowCursor( 0 );
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW;// | WS_EX_WINDOWEDGE;
		dwStyle   = WS_VISIBLE | WS_CAPTION | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU;
	}

	RECT	WindowRect;
	WindowRect.left		= 0;
	WindowRect.top		= 0;
	WindowRect.right	= RESX;
	WindowRect.bottom	= RESY;

#ifdef ALLOW_WINDOWED
	AdjustWindowRect( &WindowRect, dwStyle, false );
	gs_WindowInfos.hWnd = CreateWindowEx( dwExStyle, wc.lpszClassName, wc.lpszClassName, dwStyle,
							   (GetSystemMetrics(SM_CXSCREEN)-WindowRect.right+WindowRect.left)>>1,
							   (GetSystemMetrics(SM_CYSCREEN)-WindowRect.bottom+WindowRect.top)>>1,
							   WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, 0, 0, gs_WindowInfos.hInstance, 0 );
#else
	gs_WindowInfos.hWnd = CreateWindowEx( dwExStyle, wc.lpszClassName, wc.lpszClassName, dwStyle, 0, 0, 
								 WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, 0, 0, gs_WindowInfos.hInstance, 0 );
#endif
	if( gs_WindowInfos.hWnd == NULL )
		return ERR_CREATE_WINDOW;

	if( (gs_WindowInfos.hDC = GetDC( gs_WindowInfos.hWnd )) == NULL )
		return ERR_RETRIEVE_DC;
	
	SetForegroundWindow( gs_WindowInfos.hWnd );
	SetFocus( gs_WindowInfos.hWnd );


	//////////////////////////////////////////////////////////////////////////
	// Initialize DirectX Device
// 
// 	Video	Test( *((Device*) NULL), gs_WindowInfos.hWnd );
// 
	gs_Device.Init( RESX, RESY, gs_WindowInfos.hWnd, gs_WindowInfos.bFullscreen, true );
	if ( !gs_Device.IsInitialized() )
		return ERR_DX_INIT_DEVICE;	// Oopsy daisy shit f**k hell !


	//////////////////////////////////////////////////////////////////////////
	// Initialize sound player
#ifdef MUSIC
	gs_Music.Init();

	int	WorkMemSize = synthGetSize();
	gs_pMusicPlayerWorkMem = new U8[WorkMemSize];

	U32			TuneSize = 0;
	const U8*	pTheTune = LoadResourceBinary( IDR_MUSIC, "MUSIC", &TuneSize );
	if ( pTheTune == NULL )
		return ERR_MUSIC_RESOURCE_NOT_FOUND;
	if ( !gs_Music.Open( pTheTune ) )
		return ERR_MUSIC_INIT;

	dsInit( gs_Music.RenderProxy, &gs_Music, gs_WindowInfos.hWnd );

// Readback positions
// sS32*	pPositions = NULL;
// U32		PositionsCount = gs_Music.CalcPositions( &pPositions );
// delete[] pPositions;

#endif

	//////////////////////////////////////////////////////////////////////////
	// Initialize other static fields

	return 0;
}