Skip to content

Instantly share code, notes, and snippets.

@daramkun
Created June 3, 2016 17:40
Show Gist options
  • Select an option

  • Save daramkun/556ac504fd05a172411663abb808b92d to your computer and use it in GitHub Desktop.

Select an option

Save daramkun/556ac504fd05a172411663abb808b92d to your computer and use it in GitHub Desktop.
#include <Windows.h>
//////////////////////////////////////////////////////////////////
// TODO: Global Variables for Direct3D
bool InitializeDirect3D ( HWND hWnd )
{
// TODO: Initializing Direct3D
return true;
}
void UninitializeDirect3D ()
{
// TODO: Uninitializing Direct3D
}
void Loop ()
{
// TODO: Rendering
}
//////////////////////////////////////////////////////////////////
#pragma region Precode
LRESULT CALLBACK WndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case WM_CLOSE: PostQuitMessage ( 0 ); break;
default: return DefWindowProc ( hWnd, uMsg, wParam, lParam );
}
return 0;
}
HWND InitializeWindow ( int width = 1280, int height = 720 )
{
WNDCLASS wndClass = { CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, nullptr,
LoadIcon ( nullptr, IDI_APPLICATION ), LoadCursor ( nullptr, IDC_ARROW ),
nullptr, nullptr, TEXT ( "Win32AppWindow" ) };
if ( RegisterClass ( &wndClass ) == 0 )
return 0;
RECT rect = { 0, 0, width, height };
AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW, false );
int w = rect.right - rect.left, h = rect.bottom - rect.top;
int x = GetSystemMetrics ( SM_CXSCREEN ) / 2 - w / 2, y = GetSystemMetrics ( SM_CYSCREEN ) / 2 - h / 2;
return CreateWindow ( TEXT ( "Win32AppWindow" ), TEXT ( "Application" ), WS_OVERLAPPEDWINDOW,
x, y, w, h, nullptr, nullptr, GetModuleHandle ( nullptr ), nullptr );
}
void RunWindow ( HWND hWnd )
{
ShowWindow ( hWnd, SW_SHOW );
UpdateWindow ( hWnd );
MSG msg;
while ( true )
{
if ( PeekMessage ( &msg, nullptr, 0, 0, PM_NOREMOVE ) )
{
if ( !GetMessage ( &msg, nullptr, 0, 0 ) )
return;
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
else
{
Loop ();
Sleep ( 1 );
}
}
}
int WINAPI WinMain ( HINSTANCE, HINSTANCE, LPSTR, int )
{
HWND hWnd = InitializeWindow ();
if ( hWnd == nullptr ) return -1;
if ( !InitializeDirect3D ( hWnd ) ) return -2;
RunWindow ( hWnd );
UninitializeDirect3D ();
return 0;
}
#pragma endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment