Jump to content
  • Advertisement

Archived

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

SoulSkorpion

Direct X wierdness

This topic is 5607 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
Advertisement
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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!