Archived

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

Direct X wierdness

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

On trying to compile some code out of a book on Direct X (the source file physically copied off the example CD), MSVC++ ''97 is inexplicably telling me that there''s an error in d3dx8math.h. Yeah, right. Specifically, it''s complaining: "C:\DXSDK\INCLUDE\d3dx8math.h(259) : error C2065: ''UINT_PTR'' : undeclared identifier" I seriously doubt there''s an error in the Direct X SDK. The thing is, someone somewhere has managed to compile the example code ok because there''s a compiled executable included with it which runs fine. I''m not going to include the whole source file here, but can anyone suggest what the problem could possibly be? By the way, when I tried to compile the project using Dev-C++ instead of visual studio it also refused to compile, and wouldn''t tell me why. Ordinarily I''d suspect that I''ve set up MSVC++ badly, or that my version''s a little screwy, but the compile failed with two seperate compilers... so if anyone has any idea of what''s going on I''d love to hear it

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
stuff like that happened to me before. I useually end up cursing at the computer until it crashes.

In fact I started learning SDL a few days ago because when trying to set up direct3d in directX9 I would get errors saying functions that I know for a fact belonged to IDirect3D9 did not exist. However I specifically looked up those functions in the Documentation and the library files themselves.

really sorry about your problem and hope some one helps you out.

Share this post


Link to post
Share on other sites
Well since its missing a typedef I can only assume it is missing some other header... Anyway it is a bit of a hack but if that is the only header your missing you may want to try putting "typedef unsigned int *UINT_PTR" (no quotes) before the header.

Share this post


Link to post
Share on other sites
There are a few things you have to check :
1) You have the proper sdk installed (not just the runtime)
2) Very important - in the tools->options->directories verify that the directx include directory and lib directory is the topmost.
3) Make sure you include all necessary files.
4) Check that you link to the library files in the project settings.
Good luck.

Share this post


Link to post
Share on other sites
/me bangs head against table.

Thanks for the help, everyone, but none of it''s worked

1: The code already includes windows.h. I checked to see whether it does so before the others - it does.
2: I''ve DEFINATELY got the SDK and not the runtime. I even installed a second copy of it in a seperate directory and changed all the options to include the SDK''s directories. The directory setup is (including the default stuff):
Executable files: C:\DXSDK\BIN
Include files: C:\DXSDK\INCLUDE
Library files: C:\DXSDK\LIB
Source files: C:\DXSDK\INCLUDE.
Moving these to the top of the lists doesn''t help.

3: When I added the suggested typedef to the .cpp file, I got the same error message and one more:
"C:\...\TriangleApp.cpp(10) : error C2378: ''UINT_PTR'' : redefinition; symbol cannot be overloaded with a typedef"
Wonderful. It acknowledged that UINT_PTR has been defined, and refused to use it!
I tried adding the typedef in the header file itself, right before it''s being used, and it totally ignored it.

4: It''s not a missing semi or a bracket. I''m very sure it''s not a missing semi or a bracket. This isn''t my code - it''s demo code! The code is a single .cpp file, with no headers (other than the direct X ones and the windows one).

I''ll include the code:
//////////////////////////////////////////////////////

// TriangleApp

//////////////////////////////////////////////////////


#include <windows.h>
#include <d3d8.h>
#include <d3dx8tex.h>
#include <dxerr8.h>

// Function prototypes.

LRESULT WINAPI WndProc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam);
void RegisterWindowClass(HINSTANCE hInstance);
void CreateAppWindow(HINSTANCE hInstance);
WPARAM StartMessageLoop();
HRESULT InitFullScreenDirect3D();
void Render();
void CleanUpDirect3D();

// Global variables.

HWND g_hWnd;
IDirect3D8* g_pDirect3D = NULL;
IDirect3DDevice8* g_pDirect3DDevice = NULL;

struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw;
DWORD color;
};

//////////////////////////////////////////////////////

// WinMain()

//////////////////////////////////////////////////////

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
RegisterWindowClass(hInstance);
CreateAppWindow(hInstance);
ShowWindow(g_hWnd, SW_SHOWDEFAULT);
UpdateWindow(g_hWnd);
HRESULT hResult = InitFullScreenDirect3D();
if (SUCCEEDED(hResult))
WPARAM result = StartMessageLoop();
CleanUpDirect3D();
return 0;
}

//////////////////////////////////////////////////////

// WndProc()

//////////////////////////////////////////////////////

LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
return 0;

case WM_DESTROY:
PostQuitMessage( 0 );
return 0;

case WM_PAINT:
ValidateRect(g_hWnd, NULL);
return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
PostQuitMessage(WM_QUIT);
break;
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

//////////////////////////////////////////////////////

// RegisterWindowClass()

//////////////////////////////////////////////////////

void RegisterWindowClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "TriangleApp";
wc.hIconSm = NULL;

RegisterClassEx(&wc);
}

//////////////////////////////////////////////////////

// CreateAppWindow()

//////////////////////////////////////////////////////

void CreateAppWindow(HINSTANCE hInstance)
{
g_hWnd = CreateWindowEx(
NULL,
"TriangleApp",
"Triangle Application",
WS_OVERLAPPEDWINDOW,
100,
100,
648,
514,
GetDesktopWindow(),
NULL,
hInstance,
NULL);
}

//////////////////////////////////////////////////////

// StartMessageLoop()

//////////////////////////////////////////////////////

WPARAM StartMessageLoop()
{
MSG msg;
while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Use idle time here.

Render();
}
}
return msg.wParam;
}

//////////////////////////////////////////////////////

// InitFullScreenDirect3D()

//////////////////////////////////////////////////////

HRESULT InitFullScreenDirect3D()
{
g_pDirect3D = Direct3DCreate8(D3D_SDK_VERSION);
if (g_pDirect3D == NULL)
return E_FAIL;
HRESULT hResult = g_pDirect3D->CheckDeviceType(D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE);
if (hResult != D3D_OK)
{
MessageBox(g_hWnd,
"Sorry. This program won’t\nrun on your system.",
"DirectX Error", MB_OK);
return E_FAIL;
}
D3DPRESENT_PARAMETERS D3DPresentParams;
ZeroMemory(&D3DPresentParams, sizeof(D3DPRESENT_PARAMETERS));
D3DPresentParams.Windowed = FALSE;
D3DPresentParams.BackBufferCount = 1;
D3DPresentParams.BackBufferWidth = 800;
D3DPresentParams.BackBufferHeight = 600;
D3DPresentParams.BackBufferFormat = D3DFMT_X8R8G8B8;
D3DPresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DPresentParams.hDeviceWindow = g_hWnd;
hResult = g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&D3DPresentParams, &g_pDirect3DDevice);
if (FAILED(hResult))
return E_FAIL;
return D3D_OK;
}
//////////////////////////////////////////////////////

// CleanUpDirect3D()

//////////////////////////////////////////////////////

void CleanUpDirect3D()
{
if (g_pDirect3DDevice)
g_pDirect3DDevice->Release();
if (g_pDirect3D)
g_pDirect3D->Release();
}

//////////////////////////////////////////////////////

// Render()

//////////////////////////////////////////////////////

void Render()
{
CUSTOMVERTEX triangleVertices[] =
{
{400.0f, 180.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255,0,0),},
{500.0f, 380.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0,255,0),},
{300.0f, 380.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0,0,255),},
};

IDirect3DVertexBuffer8* pVertexBuf = NULL;
HRESULT hResult = g_pDirect3DDevice->CreateVertexBuffer(
3*sizeof(CUSTOMVERTEX), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT, &pVertexBuf);
if(FAILED(hResult))
{
DXTRACE_ERR("Error creating vertex buffer", hResult);
return;
}
VOID* pVertices;
hResult = pVertexBuf->Lock(0, 0, (BYTE**)&pVertices, 0);
if(FAILED(hResult))
{
DXTRACE_ERR("Error locking vertex buffer", hResult);
return;
}
memcpy(pVertices, triangleVertices, sizeof(triangleVertices));
pVertexBuf->Unlock();

g_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
g_pDirect3DDevice->SetStreamSource(0, pVertexBuf,
sizeof(CUSTOMVERTEX));
g_pDirect3DDevice->SetVertexShader(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);

g_pDirect3DDevice->BeginScene();
g_pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
g_pDirect3DDevice->EndScene();

g_pDirect3DDevice->Present( NULL, NULL, NULL, NULL );

if (pVertexBuf)
pVertexBuf->Release();
}

Share this post


Link to post
Share on other sites
I don''t believe this...

Yes, the link to your post helped. Very much. There''s just one teensy weensy problem that''s popped up instead:

LINK : fatal error LNK1104: cannot open file "d3d8.lib,"

Share this post


Link to post
Share on other sites
You need to add the lib file to your project. Check your settings in VS.

____________________________________________________________
Try RealityRift at www.planetrift.com
Feel free to comment, object, laugh at or agree to this. I won''t engage in flaming because of what I have said.
I could be wrong or right but the ideas are mine.

Share this post


Link to post
Share on other sites
Michael: He has the file in the project VC++ just can''t find it.

You need to make sure that the path to the DX libs is at the TOP of your list of library paths. I don''t know exactly how to do that b/c I don''t use VC++, but I''m sure you can figure it out.

Share this post


Link to post
Share on other sites
Explicitly including the .lib and .h files hasn''t helped. Physically copying the library to the same directory as the project, adding, and compiling hasn''t worked. Changing the order of the Direct X directories in the options hasn''t worked (not even including both of the installed copies of the SDK - one at the top of the list and one at the bottom).

By the way, after adding #include <basetsd.h> a whole pile of "external dependancies" popped up in the project window, for some unknown reason (I don''t get "external dependancies" when I #include <stdio.h>, so something must be screwy). Of course, manually adding every single one of the "external dependancies" to the project hasn''t helped.

Share this post


Link to post
Share on other sites
You can always try this then:

#pragma comment(lib,"d3d8.lib")

____________________________________________________________
Try RealityRift at www.planetrift.com
Feel free to comment, object, laugh at or agree to this. I won''t engage in flaming because of what I have said.
I could be wrong or right but the ideas are mine.

Share this post


Link to post
Share on other sites
ok. Let''s try this again...

I started an entirely new project, as a "win32 Application", included the same .cpp file. The preprocessor directives at the top of the file read:

#pragma comment(lib,"d3d8.lib") //added by me
#include <windows.h>
#include <basetsd.h> //added by me
#include <d3dx8tex.h>
#include <dxerr8.h>
#include <d3d8.h>

When I try to compile, it''s decided it *can* open d3d8.lib. It''s come up with something new to whinge about now:

TriangleApp.obj : error LNK2001: unresolved external symbol _DXTraceA@20

1: What in the hell does that mean?
2: Is there anything I can do about it?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Surely the file "d3d8.lib" is missing from your settings.

To include this:
1. Choose from the menu "Project->Settings". A "Project Settings" dialog box will open.
2. Choose the 4th tab ("Link" tab).
3. In "Object/library modules" edit box add the file name "d3d8.lib", without the quotes.
That''s it.

Regarding setting the DirectX directory to a higher priority:
1. Choose from the menu "Tools->Options". A "Options" dialog box will open.
2. Click on the "Directories" tab (6th tab).
3. For "Show directories for" combo box, make sure "Include files" is selected.
4. From the "Directories" list control, highlight your DirectX folder.
5. Click on the UP arrow (situated alongside the list control''s header, an UP arrow icon is there). Click the UP arrow until the highlighted path becomes the topmost part.

Hope this helps...
BTW, that linkage error hints that probably an appropriate library file (.lib file) is missing from your setting.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"not even including both of the installed copies of the SDK"
I doubt that you should have two copies installed, since the installer will tell you to uninstall previous versions.

Share this post


Link to post
Share on other sites
quote:
Original post by SoulSkorpion
ok. Let''s try this again...

I started an entirely new project, as a "win32 Application", included the same .cpp file. The preprocessor directives at the top of the file read:

#pragma comment(lib,"d3d8.lib") //added by me
#include <windows.h>
#include <basetsd.h> //added by me
#include <d3dx8tex.h>
#include <dxerr8.h>
#include <d3d8.h>

When I try to compile, it''s decided it *can* open d3d8.lib. It''s come up with something new to whinge about now:

TriangleApp.obj : error LNK2001: unresolved external symbol _DXTraceA@20

1: What in the hell does that mean?
2: Is there anything I can do about it?


You need to add dxerr8.lib



____________________________________________________________
Try RealityRift at www.planetrift.com
Feel free to comment, object, laugh at or agree to this. I won''t engage in flaming because of what I have said.
I could be wrong or right but the ideas are mine.

Share this post


Link to post
Share on other sites