I started programming a directx 3D graphics engine that runs in full screen, a couple months ago for a game I'm trying to make. I started programming and thought I finished the engine and started on the game.
A month ago I moved to a new apartment, so I burnt and transferred all my files to a new computer. It still compiles just fine but I get a D3DERR_INVALIDCALL when I call the CreateDevice function. At first I thought there was something wrong with my computer so I played with compiling and running some of the directx example files, but they all worked fine. So I must be doing something wrong in my code. Here is some of my code, keep in mind that the code is in a couple of different functions so the variable names might not line up:
// here is some header info
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#include <d3d8.h>
#include <d3dx8.h>
#include <dinput.h>
#include <stdio.h>
// Variables
LPDIRECT3D8 g_pD3D = 0;
LPDIRECT3DSURFACE8 g_pBackSurface = 0;
LPDIRECT3DVERTEXBUFFER8 g_pVB = 0;
LPDIRECT3DDEVICE8 g_pDevice= 0;
LPDIRECT3DINDEXBUFFER8 g_pIB=0;
LPDIRECT3DTEXTURE8 g_pTexture =0;
LPDIRECTINPUT8 g_pDI =0;
// here is where I setup the window I'm going to use.
HWND hWnd;
WNDCLASSEX wc;
static char strAppName[]= GAME_NAME;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW |CS_OWNDC;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)GetStockObject( DKGRAY_BRUSH );
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor( NULL, IDC_CROSS);
wc.lpszMenuName = NULL;
wc.lpszClassName = strAppName;
RegisterClassEx( &wc);
hWnd = CreateWindowEx(WS_EX_TOPMO
ST, strAppName, strAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 150, NULL, NULL, hInstance, NULL);
hWndMain = hWnd;
ShowWindow ( hWnd, iCmdShow);
UpdateWindow (hWnd);
return hWnd;
// this is my call to create the direct3d object
g_pD3D =Direct3DCreate8( D3D_SDK_VERSION);
// and this is where I call the CreateDevice function
LPDIRECT3DDEVICE8 pDevice= 0;
HRESULT r = 0;
D3DDISPLAYMODE d3ddm;
D3DPRESENT_PARAMETERS d3dpp;
r=pD3D->GetAdapterDisplayM
ode( D3DADAPTER_DEFAULT, &d3ddm);
if ( FAILED(r) )
{
SetError("Couldnot get display adapter information");
return NULL;
}
ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
d3dpp.hDeviceWindow = hWndMain;
d3dpp.Windowed = FALSE;
d3dpp.EnableAutoDepthStenc
il = TRUE;
d3dpp.AutoDepthStencilForm
at =D3DFMT_D16;
d3dpp.FullScreen_RefreshRa
teInHz = 0;
d3dpp.FullScreen_Presentat
ionInterva
l = D3DPRESENT_INTERVAL_ONE;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BA
CKBUFFER;
r = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndMain, D3DCREATE_SOFTWARE_VERTEXP
ROCESSING,
&d3dpp, &pDevice);
if ( FAILED(r))
{
char *MyMessage;
if ( r == D3DERR_INVALIDCALL)
{
MyMessage =new char[]= "INVALIDCALL";
} else if ( r==D3DERR_NOTAVAILABLE) {
MyMessage =new char[]= "NOTAVAILABLE";
} else if ( r==D3DERR_OUTOFVIDEOMEMORY
) {
MyMessage =new char[]= "OUTOFVIDEOMEMORY";
}
MessageBox(NULL,MyMessage,
"Results",
MB_YESNO);
SetError("Could not create the render device");
return NULL;
}
That's it. I don't know what I'm doing wrong. I've been working on this for a couple days now. Ive been striping the code down and trying different screen settings, but all give the same error. Any input would be greatly appreciated.
Thanks,
Minott