コード例 #1
0
/// Command the specified window to close.
void WindowManager::GLFWCloseCallback( Window::Handle pHandle)
{
	Window *pWindow = static_cast<Window*>(glfwGetWindowUserPointer( pHandle ));
	HELIUM_ASSERT( pWindow );
	pWindow->Destroy();
	delete pWindow;
}
コード例 #2
0
/// Window message procedure callback.
///
/// @param[in] hWnd    Window handle.
/// @param[in] msg     Message ID.
/// @param[in] wParam  Additional message information (dependent on the message sent).
/// @param[in] lParam  Additional message information (dependent on the message sent).
///
/// @return  Result of the message processing (dependent on the message sent).
LRESULT CALLBACK WindowManager::WindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	HELIUM_ASSERT( hWnd );

	switch( msg )
	{
	case WM_CREATE:
		{
			// Window pointer is passed in the lpCreateParams member of the CREATESTRUCT structure provided in
			// lParam, so set it as the user data pointer in the window itself so we can easily retrieve it from any
			// future messages.
			CREATESTRUCT* pCreateStruct = reinterpret_cast< CREATESTRUCT* >( lParam );
			HELIUM_ASSERT( pCreateStruct );

			Window* pWindow = static_cast< Window* >( pCreateStruct->lpCreateParams );
			HELIUM_ASSERT( pWindow );

			SetWindowLongPtr( hWnd, GWLP_USERDATA, reinterpret_cast< LONG_PTR >( pWindow ) );

			return 0;
		}

	case WM_CLOSE:
		{
			Window* pWindow = reinterpret_cast< Window* >( GetWindowLongPtr( hWnd, GWLP_USERDATA ) );
			HELIUM_ASSERT( pWindow );

			pWindow->Destroy();

			return 0;
		}

	case WM_DESTROY:
		{
			// Window is being destroyed, so clear reference to Window object and destroy it.
			Window* pWindow = reinterpret_cast< Window* >( GetWindowLongPtr( hWnd, GWLP_USERDATA ) );
			HELIUM_ASSERT( pWindow );
			SetWindowLongPtr( hWnd, GWLP_USERDATA, 0 );

			const Delegate<Window*>& rOnDestroyed = pWindow->GetOnDestroyed();
			if( rOnDestroyed.Valid() )
			{
				rOnDestroyed.Invoke( pWindow );
			}

			delete pWindow;

			return 0;
		}
	}

	return DefWindowProc( hWnd, msg, wParam, lParam );
}
コード例 #3
0
ファイル: killerg_nc.cpp プロジェクト: killgxlin/killerg2d
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	Engine::Init();

	Input input;
	input.Init();

	Window window;
	window.Init(800, 600, "killerg2d");

	ResMgr resmgr;
	resmgr.Init();
	
	FrameRate framerate;
	framerate.Init(600);

	Timer timer;
	timer.Init();

	SpiritAnimate spirit;
	spirit.Init("abc.txt");


	int x = 100, y = 100;
	int model = 0;
	while( !input.IsKeyDown(SDLK_ESCAPE) )
	{
		timer.Update();

		input.Update();

		if( input.IsKeyDown(SDLK_LEFT) )
			x-=1;

		if( input.IsKeyDown(SDLK_RIGHT) )
			x+=1;

		if( input.IsKeyDown(SDLK_UP) )
			y-=1;

		if( input.IsKeyDown(SDLK_DOWN) )
			y+=1;

		if( input.IsKeyDown(SDLK_x) )
			spirit.Play();

		if( input.IsKeyDown(SDLK_y) )
			spirit.Stop();

		spirit.Update(timer.GetIntervalF());

		window.Clear();

		spirit.Draw(&window, x, y);

		window.Flush();

		framerate.WaitFrame();
	}

	timer.Destroy();

	framerate.Destroy();

	resmgr.Destroy();

	window.Destroy();

	input.Destroy();


	Engine::Destroy();


	
}
コード例 #4
0
ファイル: Context.cpp プロジェクト: anareboucas/nanook
VOID Context::Create( UINT ColorBits, UINT AlphaBits, UINT DepthBits, UINT MultiSample )
{
	Window W;
	W.Create( Window::m_pDefaultWindowClass, TEXT(""), 0, 0, Ptr<Window>::Null, 0, Point(0,0), Point(1,1) );

	m_hDeviceContext = GetDC(W.Handle());

	PIXELFORMATDESCRIPTOR PixelFormat;
	ZeroMemory( &PixelFormat, sizeof(PixelFormat) );
	
	PixelFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  PixelFormat.nVersion   = 1;
  PixelFormat.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION | PFD_SWAP_COPY;
  PixelFormat.iPixelType = PFD_TYPE_RGBA;
  PixelFormat.cColorBits = ColorBits + AlphaBits;
	PixelFormat.cDepthBits = DepthBits;

	INT PixelFormatIndex = ChoosePixelFormat( m_hDeviceContext, &PixelFormat );
	SetPixelFormat(m_hDeviceContext, PixelFormatIndex, &PixelFormat);

	m_hGLContext = wglCreateContext(m_hDeviceContext); 

	Activate();

	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
	
  if (wglChoosePixelFormatARB == 0)
    MultiSample = 0;

	while (MultiSample > 0)
	{
		INT PixelFormatAttributes[] = 
		{
			WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
			WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
			WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
			WGL_COLOR_BITS_ARB, ColorBits,
			WGL_ALPHA_BITS_ARB, AlphaBits,
			WGL_DEPTH_BITS_ARB, DepthBits,
			WGL_STENCIL_BITS_ARB, 0,
			WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
			WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
			WGL_SAMPLES_ARB, MultiSample,
			0,
		};

		UINT N = 0;
		PixelFormatIndex = 0;
		wglChoosePixelFormatARB( m_hDeviceContext, PixelFormatAttributes, NULL, 1, &PixelFormatIndex, &N);
    if (N > 0)
      break;

    MultiSample >>= 1;
	}

	ReleaseDC( W.Handle(), m_hDeviceContext );
	wglDeleteContext( m_hGLContext );
	W.Destroy();

	m_hDeviceContext = GetDC(m_pWindow->Handle());

	ZeroMemory( &PixelFormat, sizeof(PixelFormat) );

	PixelFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  PixelFormat.nVersion   = 1;
  PixelFormat.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION | PFD_SWAP_COPY;
  PixelFormat.iPixelType = PFD_TYPE_RGBA;
  PixelFormat.cColorBits = ColorBits + AlphaBits;
	PixelFormat.cDepthBits = DepthBits;

	if (MultiSample == 0)
		PixelFormatIndex = ChoosePixelFormat( m_hDeviceContext, &PixelFormat );
	SetPixelFormat(m_hDeviceContext, PixelFormatIndex, &PixelFormat);

	m_hGLContext = wglCreateContext(m_hDeviceContext); 

	Activate();

	TraceD(TEXT("OpenGL Renderer: %s"), glGetString(GL_RENDERER) );
	TraceD(TEXT("OpenGL Vendor: %s"), glGetString(GL_VENDOR) );
	TraceD(TEXT("OpenGL Version: %s"), glGetString(GL_VERSION) );
  TraceD(TEXT("MultiSampling: %d"), MultiSample );

	InitExtensions();

  m_pWindow = 0;
}