I am in some desperate need for some help with some DX 9 Code. What I am trying to do is create a simple class to set up a dx9 object / device etc which i can then use for other projects later on. Now I can get the code to compile but as soon as I try and do anthing with it then everything just packs up.
Heres my code as it is now (there are bits that are broken i think)
Heres WinMain.h
// Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
// DirectX
#include <d3d9.h>
#include <d3dx9.h>
#include <dshow.h>
// Change these to change the window properties
#define WINDOW_TITLE "Vertex"
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM);
Here's WinMain.cpp
#include "WinMain.h"
#include "CD9device.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = WINDOW_TITLE;
wcex.hIconSm = 0;
RegisterClassEx( &wcex );
// Create the Window
HWND hWnd = CreateWindow(
WINDOW_TITLE,
WINDOW_TITLE,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
WINDOW_WIDTH,
WINDOW_HEIGHT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow( hWnd, SW_SHOW );
UpdateWindow( hWnd );
CD9device mydevice (HWND hWnd);
D3DADAPTER_IDENTIFIER9 ident;
mydevice->GetD3D->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &ident);
MessageBox( 0, ident.Description,0,0);
// Main loop
MSG msg;
while ( 1 )
{
// Did we recieve a message?
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if ( msg.message == WM_QUIT)
{
break;
}
TranslateMessage( &msg );
DispatchMessage ( &msg );
}
else
{
// Render a frame
}
}
return 0;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch ( message )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
// Render a frame then validate the client area
ValidateRect( hWnd, 0 );
return 0;
}
return DefWindowProc( hWnd, message, wParam, lParam );
}
Here's the CD9device.h (The Class part)
#include "WinMain.h"
class CD9device
{
public:
CD9device (HWND hWnd)
{
// Create D3D Object
// Error checking to be added
m_pD3D9 = Direct3DCreate9( D3D_SDK_VERSION );
// Build Present Params
m_D3Dpp.BackBufferWidth = 0;
m_D3Dpp.BackBufferHeight = 0;
m_D3Dpp.BackBufferFormat = D3DFMT_UNKNOWN;
m_D3Dpp.BackBufferCount = 1;
m_D3Dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
m_D3Dpp.MultiSampleQuality = D3DMULTISAMPLE_NONE;
m_D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_D3Dpp.hDeviceWindow = hWnd;
m_D3Dpp.Windowed = TRUE;
m_D3Dpp.EnableAutoDepthStencil = TRUE;
m_D3Dpp.Flags = 0;
m_D3Dpp.FullScreen_RefreshRateInHz = 0;
m_D3Dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
m_pD3D9->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, // Change this to D3DDEVTYPE_SW for uni
m_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&m_D3Dpp,
&m_pD3DDevice);
}
LPDIRECT3D9 GetD3D() { return m_pD3D9; }
LPDIRECT3DDEVICE9 GetDevice() { return m_pD3DDevice; }
private:
HWND m_hWnd;
LPDIRECT3D9 m_pD3D9;
LPDIRECT3DDEVICE9 m_pD3DDevice;
D3DPRESENT_PARAMETERS m_D3Dpp;
};
I am sure there is something stupid I have done but for the life of me I cannot see it.
Thanks for looking
S
[Edited by - ShayneC on November 10, 2005 10:57:49 AM]