![]() |
| | #1 |
| Supermassive black hole Join Date: Jul 2005 Location: South Wales, UK
Posts: 1,709
| Direct3D problem It's pretty good all I've had to do so far is swap the 8's around for 9's and the occasional function call is different by one parameter, which is usually NULL anyway. So anyway I'm here: http://www.robertwrose.com/d3d/tutorial3.html Near the end where I draw the vertex buffer, I get an error trying to compile this: Code: // ... g_pD3DDevice->SetVertexShader(D3DFVF_D3DVertex); // ... Code: c:\Documents and Settings\lee\Desktop\d3d\d3d.cpp(165) : error C2664: 'IDirect3DDevice9::SetVertexShader' : cannot convert parameter 1 from 'int' to 'IDirect3DVertexShader9 *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Code: g_pD3DDevice->SetVertexShader(reinterpret_cast<IDirect3DVertexShader9 *> (D3DFVF_D3DVertex)); Code: Unhandled exception at 0x4fe5831f in d3d.exe: 0xC0000005: Access violation writing location 0x0000004e. D3DFVF_D3DVertex is the same #define from the tutorial page: Code: #define D3DFVF_D3DVertex (D3DFVF_XYZ | D3DFVF_DIFFUSE)
__________________ Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife. - Mike McShaffry |
| ahluka is offline | |
| | #2 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,125
| Well, you're trying to pass an integral value when you should pass a vertex shader (an object). Are you sure you know what you're doing, perhaps you're trying to (want to) call SetFVF() instead?
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #3 | |
| Supermassive black hole Join Date: Jul 2005 Location: South Wales, UK
Posts: 1,709
| Quote:
In other news and completely off-topic, I just had my 3rd driving lesson and it's been the worst so far: stalled 3 times and just generally bad. Oh and I almost had a head on collision with a minibus. Almost? My instructor stopped me about 1 foot away from his nose.
__________________ Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife. - Mike McShaffry | |
| ahluka is offline | |
| | #4 |
| Supermassive black hole Join Date: Jul 2005 Location: South Wales, UK
Posts: 1,709
| You know what, after hours of doing this, you know what I say? Screw this until I can buy some books. As soon as I get enough money I'm having a field day on Amazon.
__________________ Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife. - Mike McShaffry |
| ahluka is offline | |
| | #5 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| SetVertexShader has been changed in DirectX9. Use SetFVF() instead. Bad tutorials; outdated tutorials; and in general most net tutorials will leave you in the dark. Get a book and also check the SDK docs. And you cannot make an integral value into an aggregated object by simply doing a re-interpret cast or any type of cast for that matter. COM is like polymorphic C++. If one function takes a IDirect3DTexture9 argument and yet you have an IDirect3DSurface9, you can still use it. IDirect3DTexture9 inherits from IDirect3DSurface9. Even though COM is not pure C++ in its operation, it is quite close to C++ in concept. Think of COM as how C++ should have been to begin with. You will like COM once you get the hang of it.
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 04-08-2006 at 07:34 PM. |
| Bubba is offline | |
| | #6 | |
| Registered User Join Date: Jan 2005
Posts: 847
| Quote:
| |
| Quantum1024 is offline | |
| | #7 | ||
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| Quote:
A pointer is a value at it's core - an integral value that specifies a location in memory. Therefore, again, you are not casting to an aggregated type. Quote:
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 04-08-2006 at 07:55 PM. | ||
| Bubba is offline | |
| | #8 |
| Supermassive black hole Join Date: Jul 2005 Location: South Wales, UK
Posts: 1,709
| Ok thanks Bubba I see what you mean.
__________________ Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife. - Mike McShaffry |
| ahluka is offline | |
| | #9 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| A handle in Windows API is a DWORD or UINT or unsigned 32 bit integer. Once you get the Windows crapola out of the way ahluka, it becomes much easier to work with Direct3D. I think you will come to enjoy working with it as you dive into it deeper. Direct3D makes a lot of things simple and DirectX makes a lot of nitty gritty mundane code come to life by implementing default objects to control playback of movies, MP3's, sound, music, etc. I thoroughly enjoy the entire API even though at times it makes me pull my hair out - but that's just game programming for ya.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #10 |
| Supermassive black hole Join Date: Jul 2005 Location: South Wales, UK
Posts: 1,709
| Could you take a look at this. It compiles but nothing is drawn: (~192 lines, mostly win32 crapola) Code: #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d9.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HRESULT Direct3DInit(HWND hWnd);
void Direct3DShutdown();
void Direct3DRender();
const char *lpszClassName = "D3D_App";
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pD3DDevice = NULL;
struct D3DVertex
{
float x, y, z;
DWORD color;
};
#define D3DFVF_D3DVertex (D3DFVF_XYZ | D3DFVF_DIFFUSE)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hWnd;
MSG mMsg;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(wc);
wc.cbWndExtra = 0;
wc.hbrBackground = static_cast<HBRUSH> (GetStockObject(GRAY_BRUSH));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = lpszClassName;
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW | CS_HREDRAW;
if (! RegisterClassEx(&wc))
{
MessageBox(0, "Error registering window class", "Error",
MB_OK | MB_ICONERROR);
return 1;
}
hWnd = CreateWindowEx(NULL, lpszClassName, "Direct3D App", WS_OVERLAPPEDWINDOW, 0, 0, 300, 300, NULL,
NULL, hInstance, NULL);
if (! hWnd)
{
MessageBox(0, "Error creating window", "Error",
MB_OK | MB_ICONERROR);
return 1;
}
if (SUCCEEDED(Direct3DInit(hWnd)))
{
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
SetFocus(hWnd);
ZeroMemory(&mMsg, sizeof(mMsg));
while (mMsg.message != WM_QUIT)
{
if (PeekMessage(&mMsg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&mMsg);
DispatchMessage(&mMsg);
}
else
Direct3DRender();
}
}
else
{
UnregisterClass(lpszClassName, hInstance);
MessageBox(0, "Error initialising Direct3D", "Error", MB_OK | MB_ICONERROR);
return 1;
}
Direct3DShutdown();
UnregisterClass(lpszClassName, hInstance);
return 0;
}
// WndProc
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
Direct3DRender();
ValidateRect(hWnd, NULL);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
// Direct3DInit
//
HRESULT Direct3DInit(HWND hWnd)
{
D3DDISPLAYMODE d3ddm;
D3DPRESENT_PARAMETERS d3dpp;
if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
return E_FAIL;
if (FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
return E_FAIL;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_pD3DDevice)))
{
return E_FAIL;
}
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
return S_OK;
}
// Direct3DShutdown
//
void Direct3DShutdown()
{
if (g_pD3DDevice != NULL)
g_pD3DDevice->Release();
if (g_pD3D != NULL)
g_pD3D->Release();
}
// Direct3DRender
//
void Direct3DRender()
{
LPDIRECT3DVERTEXBUFFER9 vBuffer;
D3DVertex *pVertices;
D3DVertex tri[3] = {
{-0.5f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0)},
{0.5f, 0.5f, 0.0f, D3DCOLOR_XRGB(0, 255, 0)},
{0.5f, -0.5f, 0.0f, D3DCOLOR_XRGB(0, 0, 255)}
};
if (g_pD3DDevice == NULL) return;
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
if (FAILED(g_pD3DDevice->CreateVertexBuffer(3 * sizeof(D3DVertex), 0,
D3DFVF_D3DVertex, D3DPOOL_DEFAULT, &vBuffer, NULL)))
{
return;
}
if (FAILED(vBuffer->Lock(0, sizeof(D3DVertex) * 3, (void **) &pVertices, 0)))
return;
memcpy(pVertices, tri, sizeof(D3DVertex) * 3);
vBuffer->Unlock();
g_pD3DDevice->BeginScene();
g_pD3DDevice->SetStreamSource(0, vBuffer, sizeof(D3DVertex), 0);
g_pD3DDevice->SetFVF(D3DFVF_D3DVertex);
g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
vBuffer->Release();
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
__________________ Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife. - Mike McShaffry Last edited by ahluka; 04-09-2006 at 03:12 AM. |
| ahluka is offline | |
| | #11 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| Well don't release the vertex buffer until you shut down the entire system. I will look at your code a bit closer later. EDIT: No message loop. Call message loop from main.
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 04-09-2006 at 06:26 AM. |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A question related to strcmp | meili100 | C++ Programming | 6 | 07-07-2007 02:51 PM |
| WS_POPUP, continuation of old problem | blurrymadness | Windows Programming | 1 | 04-20-2007 06:54 PM |
| Need help with getting DirectX 9.0 initilization | DarkMortar | Windows Programming | 7 | 05-09-2006 08:58 PM |
| Laptop Problem | Boomba | Tech Board | 1 | 03-07-2006 06:24 PM |
| beginner problem | The_Nymph | C Programming | 4 | 03-05-2002 05:46 PM |