Jump to content
  • Advertisement
Sign in to follow this  
otreum

Setting up Dx9 with VS2008?

This topic is 2991 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 understand that the topic for this subject is a bit vague, so I will elaborate. I have just recently received the book "Programming Role Playing Games with DirectX", which to my knowledge was made in 2004? I have only just started it, and I'm already stuck with setting up Visual Studio 2008 with DirectX. So far I have done the following: 1. Downloaded the DirectX SDK (February 2010). 2. Open Visual Studio 2008, and create a win32 Application. 3. I go to Tools>Options (options window opens), I go to Projects and Solutions>VC++Directories. 4. I go to the "Show directories for" dropdown list and select "include Files" 5. I click the "New Line" icon and add "Microsoft DirectX SDK (February 2010)\include" 6. I then choose Library files from the drop down list and add line "Microsoft DirectX SDK (February 2010)\Lib" 7. Next I right click on my project in the solution explorer called "compiler_setup" and go to properties. 8. In properties I go to Configuration Properties > linker > input and add the following library files: d3d9.lib d3dx9d.lib (debugger version?) d3dx9of.lib dxguid.lib DxErr9.lib dinput8.lib (direct input 8? isn't this for directX 8?) winmm.lib 9. While i'm still in the project properties, I go to Linker > Command Line and type "/J" (minus quotations) into the "Additional options:" text box. 10. (THIS IS WHERE I GET STUCK) The book now talks about multithreaded libraries, and that visual studio needs to be set up for multithreading. It tells me that if i'm using visual studio.net, to click on the project in the solutions explorer, select project then go to properties. Then in the properties pages, select the C/C++ folder and click on the Code Generation option. The problem is, I do not have a folder in the project properties called C/C++, nor could I find anything in any of the folders that had a Code Generation option. So my questions are this: - Does anybody know how I can go about setting up multithreaded libraries, or finding what this book is talking about? - Does anybody know a more up to date book or (preferably)web link to run through the process? (I have looked online, but each tutorial is different, they add different library files, they do different methods of setting up and so on...so it's confusing.) I would greatly appreciate any help on this matter. Thankyou in advance.

Share this post


Link to post
Share on other sites
Advertisement
It's set by default.

Otherwise, your book is probably telling you how to do it under Visual C++ 2008 Express, not Visual Studio 2008 (they're different!). If so, you might want to download it (free at microsoft.com) and try it out.

Share this post


Link to post
Share on other sites
Quote:
Original post by PlasticineGuy
Visual C++ 2008 Express, not Visual Studio 2008 (they're different!)


Sure, they're different, but for all intents and purposes, Visual C++ 2008 Express and Visual Studio 2008 Professional are exactly the same. Its just the professional version has a bunch of features you probably will never use; you'll encounter the exact same problem as the OP describes in the Express edition.

Quote:
Original post by otreum
The problem is, I do not have a folder in the project properties called C/C++, nor could I find anything in any of the folders that had a Code Generation option.


It's an oddity of Visual Studio 2008. You need to add a C/C++ file to your project before you are able edit the C/C++ project settings.

Quote:
d3dx9d.lib (debugger version?)

Yes, libraries suffixed with a "d" typically stand for debug version.

Quote:
dinput8.lib (direct input 8? isn't this for directX 8?)

Yes, because there wasn't any changes since DirectX8. However, DirectInput is now deprecated in favor of XInput.

Share this post


Link to post
Share on other sites
Just a little point. If I can remember correctly there is no more library called:
DxErr9.lib

Now that library is common between dx9 and 10 and it's called:
DxErr.lib

Is your project compiling and linking ?

Share this post


Link to post
Share on other sites
Well i'd just like to get my project set up correctly for directX before I even start trying to compile any code.

The book is actually saying how to do the steps for Visual Studio 6.0 and extra steps for Visual Studio .NET .
The visual studio .NET steps are closer to what I need but obviously there are differences between Visual Studio 2008 and .NET so now i'm stuck.

_fastcall hit the nail on the head.
All the problem was, that I had not yet added a .cpp file to the project yet, and therefore there was no C/C++ settings to edit for the project.

Thanks _fastcall, I appreciate you pointing this out as it's probably solved alot of headaches! :)

Also I changed a few of my linked library files based on what has been said by repka3, so now I have the following files linked:
d3d9.lib d3dx9d.lib d3dxof.lib dxguid.lib XInput.lib DxErr.lib winmm.lib dinput8.lib

I changed some others there after actually having a look at the library names in my directX SDK folder.

Now I can continue....actually...no, I can't continue.
I can't because this book sortof just throws code at the reader and says "It's too complex to explain, but just type this code in anyway".

So I figured I should google around and see what I could find online, I found a place called www.directxtutorial.com and another website here:
http://gregs-blog.com/2008/02/20/directx-9-c-graphics-tutorial-1-getting-started/

Which are some starters to directX, however when I use this code:

#include <windows.h> // include the basic windows header file

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
// create a "Hello World" message box using MessageBox()
MessageBox(NULL,
L"Hello World!",
L"Just another Hello World program!",
MB_ICONEXCLAMATION | MB_OK);

// return 0 to Windows
return 0;
}


I get the following error: (btw, the online lib file linked is now just d3d9.lib)

1>------ Build started: Project: compiler_setup, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>f:\gamedev\1\compiler_setup\compiler_setup\main.cpp(12) : error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'const wchar_t [13]' to 'LPCSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://f:\Gamedev\1\compiler_setup\compiler_setup\Debug\BuildLog.htm"
1>compiler_setup - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

[Edited by - otreum on April 11, 2010 8:41:59 AM]

Share this post


Link to post
Share on other sites
Anyway i'm reading that book right now, and yes is full of "it's too hard to explain, this is the code and that's all. Ok the code is quite self-explanatory, but for example for mesh animation , first i don't like at all his data structures, second he dont explain nothing about blend verticies and blend animation.
If can i suggest you a book try Introduction to 3d programming with directx 9.0: a shader approach. by Frank Luna.

bye.

Share this post


Link to post
Share on other sites
Quote:
Original post by otreum

1>------ Build started: Project: compiler_setup, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>f:\gamedev\1\compiler_setup\compiler_setup\main.cpp(12) : error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'const wchar_t [13]' to 'LPCSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://f:\Gamedev\1\compiler_setup\compiler_setup\Debug\BuildLog.htm"
1>compiler_setup - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Tell the compiler you want use Multi-byte character sets
Property->General->Character Set->Use Multi-Byte Character Set.

Share this post


Link to post
Share on other sites
Hmmm, it is already using Multi-byte character set :(

I think it was either the code is dodgy, or when it copied across, it copied the quotation marks with italics, and thus did not actually copy across as quotation marks.
I just copied the code from:
http://gregs-blog.com/2008/02/20/directx-9-c-graphics-tutorial-1-getting-started/

And it all had errors, until I fixed up some of the quotation marks.

However, while it compiles perfectly fine, when I actually try to run the program, it crashes, so I debug the code, it gets to this line:
g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);

and it then jumps to:
g_pDirect3D_Device->Release();

shows an unhandled exception error at the line saying:

The error itself says:
Quote:
Unhandled exception at 0x0122178a in compiler_setup.exe: 0xC0000005: Access violation reading location 0x00000000.


Below is the final code:

#include <windows.h>
#include <d3d9.h>


// globals
LPDIRECT3D9 g_pDirect3D = NULL;
LPDIRECT3DDEVICE9 g_pDirect3D_Device = NULL;
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
{
MSG msg;

WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC,
WndProc, 0, 0, hInstance, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1),
NULL, "DX9_TUTORIAL1_CLASS", NULL};

RegisterClassEx(&wc);


HWND hMainWnd = CreateWindow("DX9_TUTORIAL1_CLASS","DirectX 9 Bare Bones Tutorial 1?",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,NULL, NULL,hInstance,NULL);

g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);


D3DPRESENT_PARAMETERS PresentParams;
memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));

PresentParams.Windowed = TRUE;
PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;

g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams,
&g_pDirect3D_Device);

ShowWindow(hMainWnd, nShow);

UpdateWindow(hMainWnd);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(0);
}



LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return(0);
case WM_PAINT: // <— ADD THIS BLOCK
g_pDirect3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255),

1.0f, 0);
g_pDirect3D_Device->Present(NULL, NULL, NULL, NULL);

ValidateRect(hwnd, NULL);
return(0);

}

g_pDirect3D_Device->Release();
g_pDirect3D->Release();
return(DefWindowProc(hwnd, msg, wParam, lParam));
}


Share this post


Link to post
Share on other sites
Quote:
Original post by otreum
Hmmm, it is already using Multi-byte character set :(


Set it to Unicode. The Win32 API maps its functions, for example MessageBox, to either MessageBoxA (which take chars and char-strings) or MessageBoxW (which take wchar_ts and wchar_t-strings) depending on whether or not UNICODE and _UNICDOE are defined. You can define these macros manually before including windows-related headers, or you can set the character set to "Unicode", which does this for you as a project setting.

Quote:

D3DPRESENT_PARAMETERS PresentParams;
memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));



In C++, this is written as: D3DPRESENT_PARAMETERS PresentParams = {};

Also:
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return(0);

case WM_PAINT: // <— ADD THIS BLOCK
g_pDirect3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
g_pDirect3D_Device->Present(NULL, NULL, NULL, NULL);

ValidateRect(hwnd, NULL);
return(0);
}

// Wait what?
// Are you sure you want to destroy your Direct3D devices when
// a message wasn't handled by the code above, such as a WM_MOUSEMOTION?
g_pDirect3D_Device->Release();
g_pDirect3D->Release();

return(DefWindowProc(hwnd, msg, wParam, lParam));
}




This is, indeed, a problem with the code, however, it may not be the problem you're experiencing. As older1s suggested, use the debugging features of Visual Studio to determine where your code is going wrong. I noticed that the DirectX calls aren't being tested for success/failures. You might want to start there. For example, Direct3DCreate9 returns 0 on failure, and IDirect3D9::CreateDevice returns D3D_OK on success.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!