Here is the working version. You can see that this example shows ways on not to program windows :-). It is meant for doing intro programming with DX10. The thing I do not get currently is, why the DX9 version of the example is 0.75 kb and the DX10 version is 1.65kb ... but anyway I gave up on this for now to do more serious work. Thought someone might find it useful :-)
////////////////////////////////////////////////////////////////////////
//
// Skeleton Intro Coding
//
// by Wolfgang Engel
// Last time modified: 01/13/2007
//
///////////////////////////////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#define INITGUID
#include <windows.h>
#include <sal.h>
#include <rpcsal.h>
#include <d3d10.h>
// define full screen & to use the desktop window
// #define FULLSCREENUSE_DESKTOP
#if defined(FULLSCREENUSE_DESKTOP)
// define the size of the full-screen
#define WINWIDTH 1280
#define WINHEIGHT 720
#else
// define the size of the window
#define WINWIDTH 800
#define WINHEIGHT 600
#endif
// makes the applicaton behave well with windows
// allows to remove some system calls to reduce size
#define WELLBEHAVIOUR
// D3D 10 device variables
// Global Variables:
ID3D10Device *g_pd3dDevice = NULL;
IDXGISwapChain *g_pSwapChain = NULL;
ID3D10RenderTargetView *g_pRenderTargetView = NULL;
// main window handle
HWND g_MainWnd;
// timer global variables
DWORD g_StartTime;
DWORD g_CurrentTime;
// keep track if the game loop is still running
BOOL g_BRunning;
// this is the main windows entry point ... the assembly version is in crt0gui.asm
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// using the desktop window saves even more size
#if defined(FULLSCREENUSE_DESKTOP)
HWND hWnd = GetDesktopWindow();
#else
// the most simple window
HWND hWnd = CreateWindowEx(WS_EX_TOPMOST,
"STATIC",
0,
WS_POPUP | WS_VISIBLE,
0, 0,
WINWIDTH, WINHEIGHT,
0, 0, 0, 0);
// don't show the cursor
ShowCursor(FALSE);
#endif
DXGI_SWAP_CHAIN_DESC sd;
//ZeroMemory( &sd, sizeof(sd) );
sd.BufferCount = 1;
sd.BufferDesc.Width = WINWIDTH;
sd.BufferDesc.Height = WINHEIGHT;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 75;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
// full-screen or not
#if defined(FULLSCREENUSE_DESKTOP)
sd.Windowed = FALSE;
#else
sd.Windowed = TRUE;
#endif
D3D10CreateDeviceAndSwapChain( NULL,
D3D10_DRIVER_TYPE_REFERENCE,
(HMODULE)0,
0,
D3D10_SDK_VERSION,
&sd,
&g_pSwapChain,
&g_pd3dDevice );
// Create a render target view
ID3D10Texture2D *pBackBuffer;
g_pSwapChain->lpVtbl->GetBuffer( g_pSwapChain, 0, (REFIID ) &IID_ID3D10Texture2D, (LPVOID*)&(pBackBuffer) ) ;
g_pd3dDevice->lpVtbl->CreateRenderTargetView( g_pd3dDevice, (struct ID3D10Resource *)pBackBuffer, NULL, &g_pRenderTargetView );
g_pd3dDevice->lpVtbl->OMSetRenderTargets( g_pd3dDevice, 1, &g_pRenderTargetView, NULL );
// Setup the viewport
D3D10_VIEWPORT vp;
vp.Width = WINWIDTH;
vp.Height = WINHEIGHT;
vp.MinDepth = 0;
vp.MaxDepth = 1;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pd3dDevice->lpVtbl->RSSetViewports( g_pd3dDevice, 1, &vp );
// setup timer
g_StartTime = GetTickCount();
g_CurrentTime = 0;
// set the game loop to running by default
g_BRunning = TRUE;
MSG msg;
while (g_BRunning)
{
#if defined(WELLBEHAVIOUR)
// Just remove the message
PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE);
#endif
// Calculate the current demo time
g_CurrentTime = GetTickCount() - g_StartTime;
// go out of game loop and shutdown
if (g_CurrentTime > 15300)
g_BRunning = FALSE;
float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f };
g_pd3dDevice->lpVtbl->ClearRenderTargetView(g_pd3dDevice, g_pRenderTargetView, ClearColor );
g_pSwapChain->lpVtbl->Present( g_pSwapChain, 0, 0 );
}
// release all D3D device related resources
#if defined(WELLBEHAVIOUR)
if( g_pd3dDevice ) g_pd3dDevice->lpVtbl->ClearState(g_pd3dDevice);
if( g_pd3dDevice ) g_pd3dDevice->lpVtbl->Release(g_pd3dDevice);
if( g_pRenderTargetView ) g_pRenderTargetView->lpVtbl->Release(g_pRenderTargetView);
if( g_pSwapChain ) g_pSwapChain->lpVtbl->Release(g_pSwapChain);
if (pBackBuffer)pBackBuffer->lpVtbl->Release(pBackBuffer);
#endif
return msg.wParam;
}
Have fun,
- Wolfgang
=== Edited by WolfgangEngel @ 13 Jan 2007 11:03 PM UTC===
Fixed it. With INITGUID I get all the GUID's as data into the program. So what I have to do is specify each separately like this:
// name the GUID's here ... other with INITGUID you will have all the GUID's in the constant table
const IID IID_ID3D10Texture2D;
DEFINE_GUID(IID_ID3D10Texture2D,0x9B7E4C04,0x342C,0x4106,0xA1,0x9F,0x4F,0x27,0x04,0xF6,0x89,0xF0);
Size goes down to 867 bytes this way. Thanks again to everybody for help and support :-)