Jump to content
  • Advertisement
Sign in to follow this  
nosajghoul

DX9 vs DX8 SetVertexShader() question

This topic is 5459 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

In drawing 3 vertices to the screen in order to draw a triangle, you eventually call : In DirectX 8.1 : IDirect3DDevice8::SetVertexShader(DWORD handle); In DirectX 9.0 : IDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9 *pShader); In 8, you pass a FVF code, like D3DFVF_XYZRHW|D3DFVF_DIFFUSE In 9 you pass a IDirect3DVertexShader9 object, which lead me to think maybe theres a Create() function, which there was : HRESULT CreateVertexShader(const DWORD *pFunction, IDirect3DVertexShader9** ppShader); How does it work? Why is it done this way now? Whats a pFunction? (Dont say "its a Pointer to the vertex shader function token array", thats gibberish to me, well, the token part anyhow) Am I supposed to do something else in the render function other than : Clear(...); BeginScene(...); SetVertexShader(...);//this is where the problem is i think SetStreamSource(...); DrawPrimitive(...); EndScene(...); Present(...); Im just trying to get a grip on DX9, now that Im finally comfortable w DX8 :P Is there anything new I need just to draw a triangle on the screen? -Jason

Share this post


Link to post
Share on other sites
Advertisement
If you just need a fixed function shader, then use SetFVF, otherwise you probably want to look at the D3DXAssembleShader or D3DXCompileShader functions.

Share this post


Link to post
Share on other sites
In Direct3D9 the SetVertexShader() function is redefined and the purpose for it has been changed.
If you want to use the Fixed Function Pipeline, choose from SetFVF() and SetVertexDeclaration().

Hope that is what you meant..

Share this post


Link to post
Share on other sites
Its still not putting the triangle the screen. Heres what Im doing now:


Definitions etc..

#define D3D8T_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)

vertex polyvertices[] =
{
{-2.0f,1.0f,10.0f,0xffff0000},
{-3.0f,-1.0f,10.0f,0xff00ff00},
{-1.0f,-1.0f,10.0f,0xff0000ff}
};




In my initialization on direct3d

pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pD3DDevice->SetRenderState(D3DRS_AMBIENT,RGB(255,255,255));
pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
pD3DDevice->SetFVF(D3D8T_CUSTOMVERTEX);



to create my vertex buffer
[source lang = "cpp"]
IDirect3DVertexBuffer9 *cGraphics::CreateVBuffer(IDirect3DVertexBuffer9 *buffer)
{
void *vertices = 0;

pD3DDevice->CreateVertexBuffer(sizeof(polyvertices), D3DUSAGE_WRITEONLY, D3D8T_CUSTOMVERTEX, D3DPOOL_MANAGED, &buffer, NULL);

ghr=buffer->Lock(0, 0, &vertices, 0);

memcpy(vertices, polyvertices, sizeof(polyvertices) );

buffer->Unlock();

return buffer;
}




And to draw it all

pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(128,128,128), 1.0f, 0);

pD3DDevice->BeginScene();

pD3DDevice->SetStreamSource(0,poly, 0 ,sizeof(vertex));
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0, 1);

pD3DDevice->EndScene();
pD3DDevice->Present(NULL, NULL, NULL, NULL);




Just a grey screen, no triangle :(

-Jason

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!