Jump to content
  • Advertisement

Archived

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

zacharya

d3d application problem

This topic is 5238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve made a simple application using direct3d but the problem is everytime I run it and then close the application my computer suddenly went idle (mouse movement becomes slow...and all kind of stuff). I''m using tnt2 riva 32 mb. could it possinly my graphic card that cause the problem or just my code? here''s my code #include <windows.h> #include <d3d8.h> #pragma comment(lib,"d3d8.lib") #pragma comment(lib,"dxguid.lib") IDirect3D8 *g_pD3D; IDirect3DDevice8 *g_pD3DDevice; WNDCLASSEX g_wndclassex; HWND g_hWnd; void init(void); void draw(void); void cleanup(void); LRESULT CALLBACK WndProc(HWND hWn,UINT Msg,WPARAM wParam,LPARAM lParam); int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { MSG Msg; ZeroMemory(&g_wndclassex,sizeof(WNDCLASSEX)); g_wndclassex.cbSize = sizeof(WNDCLASSEX); g_wndclassex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); g_wndclassex.hInstance = hInstance; g_wndclassex.lpfnWndProc = WndProc; g_wndclassex.lpszClassName = "direct3d"; g_wndclassex.style = CS_HREDRAW | CS_VREDRAW; RegisterClassEx(&g_wndclassex); g_hWnd = CreateWindowEx(NULL,"direct3d","RZ''s first D3D application",WS_OVERLAPPEDWINDOW,0,0,500,400,NULL,NULL,hInstance,NULL); init(); ShowWindow(g_hWnd,SW_SHOW); while(1) { while(PeekMessage(&Msg,g_hWnd,0,0,PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } if(Msg.message == WM_QUIT) break; draw(); } cleanup(); return 1; } LRESULT CALLBACK WndProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam) { switch(Msg) { case WM_CREATE : break; case WM_DESTROY : PostQuitMessage(0); break; } return DefWindowProc(hWnd,Msg,wParam,lParam); } void init(void) { g_pD3D = Direct3DCreate8(D3D_SDK_VERSION); D3DDISPLAYMODE d3ddm; g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_pD3DDevice); } void draw(void) { static int rgb[3] = {0}; static int i = 0; static int inc = 1; g_pD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(rgb[0],rgb[1],rgb[2]),1.0f,0); g_pD3DDevice->BeginScene(); g_pD3DDevice->EndScene(); g_pD3DDevice->Present(NULL,NULL,NULL,NULL); if( (rgb < 0 && inc == -1) || (rgb[i] > 255 && inc == 1)) { if(i == 0 || i == 2) { inc=-inc; } else { i+=inc; } } rgb[i]+=inc; } void cleanup(void) { g_pD3DDevice->Release(); g_pD3D->Release(); }

Share this post


Link to post
Share on other sites
Advertisement
Not sure about your problem, but just a suggestion:

It would make a lot sense to handle the WM_QUIT message where you handle all of the other messages (in WndProc()). Just make a state variable, like "gameRunning" and change your main loop to while (gameRunning).

Your problem may be that the application isn't closing properly.

[edited by - glassJAw on January 23, 2004 6:08:52 PM]

Share this post


Link to post
Share on other sites
Change your PeekMessage call to pass NULL for the window handle. WM_QUIT isn''t sent to your window, so you won''t see it if you only extract messages destined for your window.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!