well not really when locking the buffer but inside the lock when i use memcpy.
heres my source(skip for short version)
#include<windows.h>
#include<d3d9.h>
#include<d3dx9.h>
#include<string>
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"d3d9.lib")
using namespace std;
bool bAppDone = false;
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg, WPARAM wParam, LPARAM lParam);
struct points{
int x,y,z;
DWORD color;
};
const DWORD point_fvf=D3DFVF_XYZRHW|D3DFVF_DIFFUSE;
class Program{
private:
IDirect3D9 *pD3D;
IDirect3DDevice9 *pDevice;
IDirect3DVertexBuffer9 *pVB;
D3DCOLOR bgColor;
points point1;
public:
HRESULT InitD3D(bool bWindowed, HWND hwnd){
pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if(!pD3D){
CatchErrors("Error initializing D3D");
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
ZeroMemory(&d3ddm,sizeof(D3DDISPLAYMODE));
pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = FALSE;
if(bWindowed){
d3dpp.Windowed = TRUE;
}
else{
RECT rect;
GetWindowRect(hwnd,&rect);
int bbHeight = rect.bottom - rect.top;
int bbWidth = rect.right - rect.left;
d3dpp.BackBufferHeight = bbHeight;
d3dpp.BackBufferWidth = bbWidth;
d3dpp.Windowed = FALSE;
}
if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pDevice))){
CatchErrors("Error creating device!");
return E_FAIL;
}
bgColor = D3DCOLOR_COLORVALUE(1,0,0,0);
point1.color = D3DCOLOR_COLORVALUE(0,0,1,0);
point1.x = 50;
point1.y = 50;
point1.z = 1;
return S_OK;
}
HRESULT ShutdownD3D(){
if(pD3D != NULL){
if(FAILED(pD3D->Release())){
CatchErrors("Error shutting down D3D");
return E_FAIL;
}
}
if(pDevice != NULL){
if(FAILED(pDevice->Release())){
CatchErrors("Error shutting down D3D Device");
return E_FAIL;
}
}
return S_OK;
}
HRESULT RenderD3D(){
pDevice->SetFVF(point_fvf);
void* data;
pDevice->CreateVertexBuffer(sizeof(points),D3DUSAGE_WRITEONLY,point_fvf,D3DPOOL_MANAGED,
&pVB,NULL);
pVB->Lock(0,sizeof(point1),&data,0);
memcpy(data,point1,sizeof(points));
pVB->Unlock();
if(FAILED(pDevice->Clear(0,NULL,D3DCLEAR_TARGET,bgColor,1.0f,0))){
CatchErrors("Failed to clear!");
return E_FAIL;
}
pDevice->BeginScene();
pDevice->DrawPrimitiveUP(D3DPT_POINTLIST,1,data,sizeof(points));
pDevice->EndScene();
pDevice->Present(NULL,NULL,NULL,NULL);
return S_OK;
}
void CatchErrors(string error){
MessageBox(NULL,error.c_str(),"Error",MB_OK);
ShutdownD3D();
}
void SetBGColor(D3DCOLOR iColor){
bgColor = iColor;
}
}program;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hpInstance, PSTR cmdLine, int iCmd){
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "class";
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wc);
HWND hwnd = CreateWindow("class","window",WS_OVERLAPPEDWINDOW,0,0,
GetSystemMetrics(0),GetSystemMetrics(1),NULL,NULL,hInstance,NULL);
program.InitD3D(false,hwnd);
MSG msg;
UpdateWindow(hwnd);
ShowWindow(hwnd, iCmd);
while(!bAppDone){
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
program.RenderD3D();
}
}
program.ShutdownD3D();
UnregisterClass("class",hInstance);
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg, WPARAM wParam, LPARAM lParam){
switch(iMsg){
case WM_KEYDOWN:
switch(LOWORD(wParam)){
case VK_RETURN:
break;
case VK_ESCAPE:
bAppDone = true;
break;
}
break;
case WM_DESTROY:
bAppDone = true;
break;
}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
heres the part where i'm having trouble:
HRESULT RenderD3D(){
pDevice->SetFVF(point_fvf);
void* data;
pDevice->CreateVertexBuffer(sizeof(points),D3DUSAGE_WRITEONLY,point_fvf,D3DPOOL_MANAGED,
&pVB,NULL);
pVB->Lock(0,sizeof(point1),&data,0);
memcpy(data,point1,sizeof(points));
pVB->Unlock();
if(FAILED(pDevice->Clear(0,NULL,D3DCLEAR_TARGET,bgColor,1.0f,0))){
CatchErrors("Failed to clear!");
return E_FAIL;
}
pDevice->BeginScene();
pDevice->DrawPrimitiveUP(D3DPT_POINTLIST,1,data,sizeof(points));
pDevice->EndScene();
pDevice->Present(NULL,NULL,NULL,NULL);
return S_OK;
}
where i call memcpy(data,point1,sizeof(points)) i get a compiler error:
c:\documents and settings\cory fisher\my documents\visual studio 2005\projects\directx\directx\main.cpp(91) : error C2664: 'memcpy' : cannot convert parameter 2 from 'points' to 'const void *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
any ideas on how to fix this?
thx,
Cory