Original Post
Ive been trying to write a function that creates a vertex buffer, but it returns NULL when i try to run it. Any ideas why?
Heres where i call it:
Thanks all!
[edited by - ACAC on April 13, 2002 12:23:29 PM]
IDirect3DVertexBuffer8 * MakeVbuffer(int nVertices, CUSTOMVERTEX *Vertices)
{
IDirect3DVertexBuffer8* tempV; //temp vertexbuffer
VOID *p_vertices; // pointer to the vbuffer
if( FAILED ( g_pD3DDevice->CreateVertexBuffer( nVertices*sizeof( CUSTOMVERTEX ),
0,
CUSTOM_VERTEX,
D3DPOOL_DEFAULT,
&tempV ) ) )
return NULL;
if( FAILED ( tempV->Lock(0,nVertices*sizeof( CUSTOMVERTEX ), (BYTE**)&p_vertices, 0 ) ) )
return NULL;
memcpy( p_vertices, Vertices, nVertices*sizeof( CUSTOMVERTEX ));
tempV->Unlock();
return (tempV);
}
char * Direct3DInit( )
{
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return "Error creating D3D Object";
D3DDISPLAYMODE displayMode;
//if( FAILED ( g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm) ) )
// return "Error Gettting Adapter Display Mode";
displayMode.Width=WINDOW_WIDTH; // Set the screen width to the window width
displayMode.Height=WINDOW_HEIGHT; // Set the screen height to the window height
displayMode.RefreshRate=0; // Set the refresh rate to default
displayMode.Format=D3DFMT_R5G6B5; // Set the color format to 565 16 bit
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = displayMode.Format;
d3dpp.BackBufferWidth = displayMode.Width; // The back buffer width
d3dpp.BackBufferHeight = displayMode.Height; // The back buffer height
if( FAILED (g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING ,
&d3dpp, &g_pD3DDevice) ) )
return "Error Creating Device ";
p_Vertices = Vertices;
if(MakeVbuffer(3, p_Vertices)== NULL);
MessageBox(g_hwnd,"NULLRETURNED","BLEH", MB_OK);
return "OK";
}