Archived

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

MetaKnight

New to Direct X

Recommended Posts

Hey guys, oh that''s a lot for the help ive been getting latley, gamedev.net fourms are the best! It''s my first time using direct3d today, and i have no idea what im doing, i can draw a triangle , but when i try to draw this 3d sine wave it doesnt work. This is what i try to put into the vertex buffer CUSTOMVERTEX cvVertices[400]; for(int idx = 0;idx < 200;idx++) { for( int idz = 0;idz < 200;idz++) { cvVertices[idx+idz].colour = D3DCOLOR_XRGB(255,idx, idz); cvVertices[idz+idx].x= idx; cvVertices[idz+idx].z = idz/200; cvVertices[idz+idx].y = float(si((4*sqrt(sq(float(idx-50))+sq(float(idz-50))))/13)); cvVertices[idz+idx].rhw = 0.5; } }

Share this post


Link to post
Share on other sites
quote:
Original post by MetaKnight
CUSTOMVERTEX cvVertices[400];


for(int idx = 0;idx < 200;idx++)
{
for( int idz = 0;idz < 200;idz++)
{


cvVertices[idx+idz].colour = D3DCOLOR_XRGB(255,idx, idz);
cvVertices[idz+idx].x= idx;
cvVertices[idz+idx].z = idz/200;
cvVertices[idz+idx].y = float(si((4*sqrt(sq(float(idx-50))+sq(float(idz-50))))/13));
cvVertices[idz+idx].rhw = 0.5;


}
}


What function is si? Are you sure that shouldn''t be sin?


_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

Share this post


Link to post
Share on other sites
ohh okay, i fixed all of that stuff now, thanks!
but it still gives me a write error for somereason
i just wanna do a 2d wave now and it still wont let me do it
here''s my whole vertex init
HRESULT InitialiseVertexBuffer()
{
VOID* pVertices;


CUSTOMVERTEX cvVertices[200];



for( int idz = 0;idz < 200;idz++)
{


cvVertices[idz].colour = D3DCOLOR_XRGB(255,idx, idz);
cvVertices[idx].x= 1;
cvVertices[idz].z = idz/200;
cvVertices[idz].y = float(sin((4*sqrt(sq(float(idx-50))+sq(float(idz-50))))/13));
cvVertices[idz].rhw = 0.5;

}



//Create the vertex buffer from our device
if(FAILED(g_pD3DDevice->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVertexBuffer)))
{
return E_FAIL;
}

//Get a pointer to the vertex buffer vertices and lock the vertex buffer
if(FAILED(g_pVertexBuffer->Lock(0, sizeof(cvVertices), (BYTE**)&pVertices, 0)))
{
return E_FAIL;
}

//Copy our stored vertices values into the vertex buffer
memcpy(pVertices, cvVertices, sizeof(cvVertices));

//Unlock the vertex buffer
g_pVertexBuffer->Unlock();

return S_OK;
}

Share this post


Link to post
Share on other sites
First of all, post your code. Unless you've got a function sq, this code isn't gonna compile. Secondly, what's the deal with sizeof ( cvVertices )? Shouldn't this be specifying the total size of the vertex buffer to lock? (Like sizeof ( CUSTOMVERTEX ) * 200 )... Either way, how about posting all the code that's applicable, then we'll see what we can do. If there is a function sq that you've defined, I'd like to know what it does, perhaps that could be the cause of the problem... Also, what exactly is a write error? Unless you post the exact error message and when/where it happens, that doesn't mean much.

[edited by - Melraidin on August 11, 2002 12:35:11 AM]

Share this post


Link to post
Share on other sites
oh sorry, this is my first bug post
well here''s sq()
float sq(float go)
{
return go*go;

}

and what do you mean about "(Like sizeof ( CUSTOMVERTEX ) * 200 )... ?"
do you mean this:

memcpy(pVertices, cvVertices, sizeof(cvVertices));
should be:
memcpy(pVertices, cvVertices,sizeof ( CUSTOMVERTEX ) );

this is my first time using Direct X, im a opengl user,
the error i get says:
The instruction at "0x04001bd3" referenced memory at "0x0019300". The momory could not be "written". Click On OK to terminate the program



Share this post


Link to post
Share on other sites

g_pD3DDevice->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX))

This is allocating *3* vertices. I don''t think that''s what you want.

When you lock, you can set the size to 0 if you just want to lock the whole thing, keeps it simpler:

g_pVertexBuffer->Lock(0,0, (BYTE**)&pVertices, 0)

though using sizeof(cvVertices) should be okay for the lock and the memcpy.

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites