HI everyone, I'm trying to get into 3D programming ( once and for all ) but I've stumbled on a problem, the program crashes when I add dx_Scene() in the sys_MessageLoop(), does someone find something buggy in my code?
#ifndef _DX_MAIN_H_
#define _DX_MAIN_H_
#pragma comment(lib, "D3d8.lib") // Direct 3D 8
#include <d3d8.h>
#include <windows.h>
namespace {
IDirect3D8* g_pD3D;
D3DDISPLAYMODE g_DispMode;
D3DPRESENT_PARAMETERS g_Params;
IDirect3DDevice8* g_Device;
};
/*********************************************************
** DirectX-specific functions
*********************************************************/
BOOL dx_InitD3D();
BOOL dx_GetDisplayMode();
BOOL dx_CreateMainDevice();
void dx_Cleanup();
void dx_Scene();
#endif
#include "dx_main.h"
#include "sys_main.h"
BOOL dx_InitD3D()
{
CoInitialize(NULL); // Initialize COM
g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if(g_pD3D == NULL)
return FALSE;
dx_GetDisplayMode();
dx_CreateMainDevice();
return TRUE;
}
BOOL dx_GetDisplayMode()
{
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &g_DispMode)))
return FALSE;
return TRUE;
}
BOOL dx_CreateMainDevice()
{
ZeroMemory(&g_Params, sizeof(g_Params));
g_Params.Windowed = TRUE;
g_Params.SwapEffect = D3DSWAPEFFECT_DISCARD;
g_Params.BackBufferFormat = g_DispMode.Format;
if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_Wnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&g_Params, &g_Device)))
return FALSE;
return TRUE;
}
void dx_Cleanup()
{
if(g_Device != NULL)
g_Device->Release();
if(g_pD3D != NULL)
g_pD3D->Release();
}
void dx_Scene()
{
g_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
//g_Device->BeginScene();
//g_Device->EndScene();
g_Device->Present(NULL, NULL, NULL, NULL);
}
#include "sys_main.h"
#include "dx_main.h"
int __stdcall WinMain(HINSTANCE hPrevInstance,
HINSTANCE hInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
if(!sys_RegisterWindowClass() || !sys_CreateWindow()) {
MessageBox(NULL, "Program failed on startup", g_Title, MB_ICONEXCLAMATION);
return 1;
}
dx_InitD3D();
sys_MessageLoop();
dx_Cleanup();
sys_Cleanup();
return 0 ;
}
Besides, does any of you guys know how to do so that IntelliSense finds the function declaration and do its job (finds the parameters of the functions your are currently typing or find the members of a struct/class/namespace.... )
Thank you all
PS: Sorry, I know that's a bit too much code to post on a forum but I hope I'm not annoying anybody.