Archived

This topic is now archived and is closed to further replies.

dalaptop

initializing 8.0 (newbie question) Direct3D

Recommended Posts

dalaptop    122
I have recently been starting to learn DirectX 8.0. I have read the DirectX 8.0 SDK documentation from microsoft and I have followed along with the first tutorial and written the following sample to see I could use DirectX Graphics or more specifically Direct3D. This code compiles but nothing shows up on the screen. It''s as if nothing happened. I have to ALT-CTRL-DEL it and End it''s task. Please help me to find out what''s wrong with the following code: #include #include HINSTANCE hinst; HWND hwnd; LPDIRECT3D8 d3d = NULL; D3DDISPLAYMODE d3ddm; D3DPRESENT_PARAMETERS d3dpp; LPDIRECT3DDEVICE8 d3dd = NULL; void InitD3D(); void Render(); void Cleanup(); LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { WNDCLASSEX wc; MSG msg; hinst = hInstance; wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WinProc; wc.hInstance = hinst; wc.style = CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "DirectX"; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wc); hwnd = CreateWindowEx(NULL, NULL, "Dx8", WS_OVERLAPPEDWINDOW, 25, 25, 100, 100, GetDesktopWindow(), NULL, hinst, NULL); InitD3D(); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DESTROY: Cleanup(); PostQuitMessage(0); return 0; case WM_PAINT: Render(); ValidateRect(hWnd, NULL); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } void InitD3D() { d3d = Direct3DCreate8(D3D_SDK_VERSION); d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dd); } void Render() { d3dd->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0); d3dd->BeginScene(); d3dd->EndScene(); d3dd->Present(NULL, NULL, NULL, NULL); } void Cleanup() { if(d3dd != NULL) { d3dd->Release(); d3dd = NULL; } if(d3d != NULL) { d3d->Release(); d3d = NULL; } }

Share this post


Link to post
Share on other sites
drdarkon    122
I don''t really know much about Direct3D yet but as far as I can tell your code works fine. All its doing is amking and displaying a window. You have to draw something or make it so that it closes when you hit esc.

Share this post


Link to post
Share on other sites
Prozak    898
Hi
I know enough to help you,
but i can''t right now (4am!!)

I''ve bookmarked this posting, just post
all of the source code, and I''ll compile it and
debug it tomorrow, what do u say?

Meanwhile, and at first glance, is your WinProc
flow working correctly? (use F10 keystrokes to test
code flow inside MSVC++6).

Thats all tha help I can give,
bye...


Hugo Ferreira
UniteK Future
"Concentrate, and you can see it. If you see it, then it is possible. If it is possible, you can Achieve it."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If you want to avoid ShowWindow(...) & UpdateWindow(...) you can add WS_VISIBLE into your CreateWindowEx(...) call, so it''d say WS_OVERLAPPEDWINDOW | WS_VISIBLE.

Share this post


Link to post
Share on other sites
Dactylos    122
Look at this:
quote:

wc.lpszClassName = "DirectX";


and later
quote:

hwnd = CreateWindowEx(NULL, NULL, "Dx8", WS_OVERLAPPEDWINDOW, 25, 25, 100, 100,
GetDesktopWindow(), NULL, hinst, NULL);


The class name given in the WNDCLASS(EX) struct and in the call to CreateWindow(Ex) must be the same. Change your call to CreateWindowEx to:


hwnd = CreateWindowEx(0, "DirectX", "Dx8",
WS_OVERLAPPEDWINDOW, 25, 25, 100, 100,
NULL, // no need to pass the desktop window here
NULL, hinst, NULL);

The second parameter in that call must match a previously registered window-class.

Also you really should call UpdateWindow and ShowWindow.

Share this post


Link to post
Share on other sites
dalaptop    122
Thanks for the help, I think that is the problem. I''ll try it out when I get home. Thanks for all the help. Should I call ShowWindow() and UpdateWindow() or can I just use the WS_POPUP flag in CreateWindowEx()? Kind of weird: I have had more experience with MFC then developing straight Win32 Applications with WinMain. Just as a I learned C++ without C first. Kind of habit that I have. Thanks for all the help, I''ll try the class name.

~Andrew Clark

Share this post


Link to post
Share on other sites
crazemanx    128
quote:
Original post by pentium3id
Meanwhile, and at first glance, is your WinProc
flow working correctly? (use F10 keystrokes to test
code flow inside MSVC++6).



Sorry this is off-topic, but what do you mean by use f10 keystrokes to test?

Share this post


Link to post
Share on other sites
DanMan    122
quote:
Original post by crazemanx

Sorry this is off-topic, but what do you mean by use f10 keystrokes to test?




In VS, if you start your program in debug mode, pressing F10 let''s you "step" through your code as its executing. It''s VERY handy, you can see exactly what your code is doing. I can''t tell you how many times I''ve used the debugger to run down pesky bugs. =)

Share this post


Link to post
Share on other sites