Original Post
I can't get this to work for the life of me been days now how sad
I think it has something to do with creating the device or clearing the screen but I can't seem to find it. Any help or tips would be really nice still a noob
OK, when I run the program I get this error
Unhandled exception at 0x004121f7 in Application Shell.exe: 0xC0000005: Access violation reading location 0x00000000.
After that nothing else happens, my message box comes up saying error creating device, but i can't find whats wrong.
[edited by - Diamend on January 14, 2004 9:34:52 AM]
[edited by - Diamend on January 14, 2004 9:37:58 AM]
//------------------------------------------------------------------------------------
// Name: Application Shell
// Desc: A simple window shell that will be used later as a base of my games.
//------------------------------------------------------------------------------------
#include <Windows.h>
#include <d3dx8.h>
#include <d3d8.h>
#pragma comment(lib,"d3d8.lib")
#pragma comment(lib,"d3dx8.lib")
LPDIRECT3D8 g_D3D; //Global IDirect3D8 object
LPDIRECT3DDEVICE8 g_pD3DDevice;
HWND hWnd;
//------------------------------------------------------------------------------------
// FUNCTION PROTOTYPES
//------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void D3D_Init(void);
void D3D_Render(void);
void D3D_Release(void);
//------------------------------------------------------------------------------------
// Name: WinMain()
// Desc: Main Entry Point
//------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdshow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, hInst,
NULL, NULL, NULL, NULL, "GameClass", NULL};
//Register the class and exit on an error
if(!RegisterClassEx(&wc))
return MessageBox(NULL,"Error Registering Window Class.","Error", MB_OK
);
//Create the window
hWnd = CreateWindow("GameClass", "My Game Title", WS_OVERLAPPED, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),400, 400, NULL, NULL, hInst, NULL);
//Return on error creating the window.
if(hWnd == NULL)
return MessageBox(NULL, "Error Creating Window", "Error", MB_OK);
//Show Window
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
D3D_Init();
//Clear out the message structure
ZeroMemory(&msg, sizeof(msg));
//Loop endlessly until you receive a quit message
while(msg.message != WM_QUIT)
{
//Peek into queue and see if there is a message waiting
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
//There is a message! Handle it normally.
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
D3D_Render();
//No messages waiting. Go ahead and do time-crucial stuff here, such as rendering graphics.
}
}
//Unregister class
UnregisterClass("GameClass", hInst);
D3D_Release();
//Exit application
return 0;
}
//------------------------------------------------------------------------------------
// Name: WinProc
// Desc: Message procedure
//------------------------------------------------------------------------------------
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0); //Tell windows to clase application.
break;
//Handle every other message.
default: return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
//------------------------------------------------------------------------------------
// Name: D3D_Init()
// Desc: Initializes direct3d
//------------------------------------------------------------------------------------
void D3D_Init()
{
if((g_D3D = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
{
//Error
}
D3DDISPLAYMODE d3ddm;
d3ddm.Width = 800;
d3ddm.Height = 640;
d3ddm.RefreshRate = 0;
d3ddm.Format = D3DFMT_R8G8B8;
if(FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
{
//Error
}
D3DPRESENT_PARAMETERS d3dpp;
//Clear out the structure
ZeroMemory(&d3dpp, sizeof(d3dpp));
//Full Screen
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.BackBufferFormat = d3ddm.Format;
if(FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
{
MessageBox(NULL, "Error Creating Device","Error",NULL);
//Error
}
}
//------------------------------------------------------------------------------------
// Name: D3D_Render()
//------------------------------------------------------------------------------------
void D3D_Render()
{
if(FAILED(g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0, 200, 255),
1.0f, 0)))
{
MessageBox(NULL, "Error Clearing Backbuffer", "Error", NULL);
}
if(SUCCEEDED(g_pD3DDevice->BeginScene()))
{
//Put fun stuff here
g_pD3DDevice->EndScene();
}
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
//------------------------------------------------------------------------------------
// Name: D3D_Release()
// Desc: Release
//------------------------------------------------------------------------------------
void D3D_Release()
{
if(g_pD3DDevice)
{
g_pD3DDevice->Release();
g_pD3DDevice=NULL;
}
if(g_D3D)
{
g_D3D->Release();
g_D3D=NULL;
}
}
Thanks in advance
Sorry normally just read the posts not post