I seem like a whining baby oh well. After taking an 8 month break and going to DirectDraw...I''m coming back to Direct3D...and am sucking greatly at it. I''m pretty sure all my initialization stuff works...but my triangle wont show up on the screen damnit!!!
I think I have to post the full(what matters at least) code or else it still wont make sense.
This is bascially all of the functions that matter in showing the verticies - please note I do have my program in seperate source files.
WinMain()
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode)
{
WNDCLASSEX wcl;
HWND hwnd;
MSG msg;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wcl.lpfnWndProc = WindowFunc;
wcl.lpszClassName = szClassName;
wcl.lpszMenuName = NULL;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcl.hCursor = LoadCursor(NULL, IDC_CROSS);
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
if(!RegisterClassEx(&wcl))
{
MessageBox(NULL, "Could not register window class!!!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
DWORD dwstyle = 0;
if(fullscreen)
{
dwstyle = WS_POPUP | WS_VISIBLE;
}
else
{
dwstyle = WS_CAPTION| WS_SYSMENU | WS_BORDER | WS_VISIBLE;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
szClassName,
szWindowTitle,
dwstyle,
0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL);
if(!hwnd)
{
MessageBox(NULL, "Could not create window!!!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
//Copy to global variables
g_hinst = hThisInst;
g_hwnd = hwnd;
if(!GameInit())
{
GameShutdown(); //Ignore shutdown error if it happens on init
MessageBox(g_hwnd, "Error initializing game resources!!!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
while(!done)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GameLoop(); //Run game loop function...
}
if(!GameShutdown())
{
MessageBox(g_hwnd, "Error shutting down!!!", "Error!", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
return msg.wParam;
}
Direct3DInit:
bool D3DInit(int width, int height, int depth, bool fullscreen)
{
//Try to create the main Direct3D object
pd3d = Direct3DCreate8(D3D_SDK_VERSION);
if(!pd3d)
return false;
ZeroMemory(&d3ddm, sizeof(D3DDISPLAYMODE));
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
if(!fullscreen)
{
if(FAILED(pd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm) ))
{
int ans;
ans = MessageBox(g_hwnd, "Could not create window in windowed mode!!\nTry fullscreen?",
"Error!", MB_YESNO | MB_ICONEXCLAMATION);
if(ans == IDYES)
fullscreen = true;
else
return false;
}
}
//We check below in case windowed mode failed and they want to use fullscreen
if(fullscreen)
{
d3ddm.Width = width;
d3ddm.Height = height;
d3ddm.RefreshRate = 0; //Default
switch(depth)
{
case 16:
d3ddm.Format = D3DFMT_R5G6B5;
break;
case 24:
d3ddm.Format = D3DFMT_R8G8B8;
break;
case 32:
d3ddm.Format = D3DFMT_A8R8G8B8;
break;
default: //Choose 16 bit if called with an improper depth
d3ddm.Format = D3DFMT_R5G6B5;
break;
}
}
d3dpp.Windowed = !fullscreen;
d3dpp.BackBufferWidth = d3ddm.Width;
d3dpp.BackBufferHeight = d3ddm.Height;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
if( FAILED( pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &pd3dd) ))
{
MessageBox(g_hwnd, "Could not create Direct3D device!!!", "Error", MB_OK | MB_ICONEXCLAMATION);
return false;
}
ResetMatricies();
LoadGeometry();
return true;
}
LoadGeometry():
void LoadGeometry()
{
OutputDebugString("IN LOAD GEOMETRY!!!\n");
triangles[0].SetColor( D3DCOLOR_XRGB(255, 0, 0) );
triangles[0].SetPos( 0.0f, 0.0f, 0.0f );
triangles[1].SetColor( D3DCOLOR_XRGB(0, 255, 0) );
triangles[1].SetPos( 0.0f, 1.0f, 0.0f );
triangles[2].SetColor( D3DCOLOR_XRGB(0, 0, 255) );
triangles[2].SetPos( 1.0f, 0.0f, 0.0f );
}
ResetMatricies();
void ResetMatricies()
{
OutputDebugString("IN RESET MATRICIES!!!\n");
//Set important 3D matricies to set up projection,
//view, and world
D3DXMatrixPerspectiveFovLH(&projmat, D3DX_PI/6, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0f, 100.0f);
pd3dd->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)projmat);
D3DXMatrixIdentity(&worldmat);
pd3dd->SetTransform(D3DTS_WORLD, &(D3DMATRIX)worldmat);
D3DXMatrixTranslation(&viewmat, 0, 0, 10);
pd3dd->SetTransform(D3DTS_VIEW, &(D3DMATRIX)viewmat);
}
ResetMatricies();
void ResetMatricies()
{
OutputDebugString("IN RESET MATRICIES!!!\n");
//Set important 3D matricies to set up projection,
//view, and world
D3DXMatrixPerspectiveFovLH(&projmat, D3DX_PI/6, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0f, 100.0f);
pd3dd->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)projmat);
D3DXMatrixIdentity(&worldmat);
pd3dd->SetTransform(D3DTS_WORLD, &(D3DMATRIX)worldmat);
D3DXMatrixTranslation(&viewmat, 0, 0, 10);
pd3dd->SetTransform(D3DTS_VIEW, &(D3DMATRIX)viewmat);
}
To possibly speed up finding errors...I think most of the attention should be put to looking at my transformation matricies and where my verticies actually are.
For the record my FVF is defined as D3DFVF_XYZ | D3DFVF_DIFFUSE.
"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.
"Ogun's Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.