Sign in to follow this  

directx basic problems....

This topic is 4199 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

Ok, I'm working out of the book "Ulitmate Game Programming With DirectX". While helpful, the source code he gives is full of problems - at least for me. so i checked the cd which gives the full source code (with the libraries). Here it is: /* Demo Name: Blank Window Author: Allen Sherrod Chapter: Ch 1 */ #include<d3d9.h> #pragma comment(lib, "d3d9.lib") #pragma comment(lib, "d3dx9.lib") #define WINDOW_CLASS "UGPDX" #define WINDOW_NAME "Blank D3D Window" // Function Prototypes... bool InitializeD3D(HWND hWnd, bool fullscreen); void RenderScene(); void Shutdown(); // Direct3D object and device. LPDIRECT3D9 g_D3D = NULL; LPDIRECT3DDEVICE9 g_D3DDevice = NULL; LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); return 0; break; case WM_KEYUP: if(wParam == VK_ESCAPE) PostQuitMessage(0); break; } return DefWindowProc(hWnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevhInst, LPSTR cmdLine, int show) { // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, WINDOW_CLASS, NULL }; RegisterClassEx(&wc); // Create the application's window HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, GetDesktopWindow(), NULL, wc.hInstance, NULL); // Initialize Direct3D if(InitializeD3D(hWnd, false)) { // Show the window ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while(msg.message != WM_QUIT) { if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else RenderScene(); } } // Release any and all resources. Shutdown(); // Unregister our window. UnregisterClass(WINDOW_CLASS, wc.hInstance); return 0; } bool InitializeD3D(HWND hWnd, bool fullscreen) { D3DDISPLAYMODE displayMode; // Create the D3D object. g_D3D = Direct3DCreate9(D3D_SDK_VERSION); if(g_D3D == NULL) return false; // Get the desktop display mode. if(FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode))) return false; // Set up the structure used to create the D3DDevice D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); if(fullscreen) { d3dpp.Windowed = FALSE; d3dpp.BackBufferWidth = 640; d3dpp.BackBufferHeight = 480; } else d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = displayMode.Format; // Create the D3DDevice if(FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_D3DDevice))) { return false; } return true; } void RenderScene() { // Clear the backbuffer. g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); // Begin the scene. Start rendering. g_D3DDevice->BeginScene(); // End the scene. Stop rendering. g_D3DDevice->EndScene(); // Display the scene. g_D3DDevice->Present(NULL, NULL, NULL, NULL); } void Shutdown() { if(g_D3DDevice != NULL) g_D3DDevice->Release(); if(g_D3D != NULL) g_D3D->Release(); } Now this gives me one problem sraight off: "undefined reference to Direct3DCreate9@4". However I fixed this by putting in: Import "libd3d9.a" Now I get these problems: Line 12: expected constructor, deconstructor, or type conversion before string constant Line 12: expected ',' or ';' before string constant In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': Line 54: `InitializeD3D' undeclared (first use this function) In function `bool InitializeD3D(HWND__*, bool)': Line 86: `bool InitializeD3D(HWND__*, bool)' used prior to declaration I am using Bloodshed Dev-C++ on a Windows XP. I have the latest version of DirectX runtime and DirectX SDK. Also, I am a beginner at this so things may not be as obvious to me as they are to you. Thanks

Share this post


Link to post
Share on other sites
Are you sure GCC (the compiler bundled with Dev-c++) can compile/link DirectX code? I'm quite sure you're supposed to use VisualC++ for that (#pragma comment(lib, "d3d9.lib") seems VC specific?)

Also, the errors you get definitly sound like missing windows.h.. Could be some VC specific code in the DirectX include files though..


Consider downloading Visual C++ 2005 Express Edition, it's free, and in my opinion alot better than Dev-C++..

Share this post


Link to post
Share on other sites
#pragma's only for VC++. While Express 2005's free, I suggest sticking with Dev for a little while, as it's quite a transition.
There's a DX9 devpack for Dev-C++. I had installed it and it worked fine.

Share this post


Link to post
Share on other sites
Yeah its probably the VC code. He never specified what compiler he was working with. I'm going to download VC++ and see if the code works any better on that. Thanks guys

Share this post


Link to post
Share on other sites
I see what Sol462 was saying. VC++ is quite a transition. Two questions:
1. How do I link to the d3d9.h and d3dx9.h files? The debugger says they dont exist, yet I have the DirectX SDK.
2. Where do I get the windows.h library? It wasnt included in the download of VC++. Is there a website that has a lot of libraries?

Share this post


Link to post
Share on other sites

This topic is 4199 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this