Sign in to follow this  
Icebone1000

Noob - Wheres the vertex colors?

Recommended Posts

Hi, just triing to render a simple red triangle, but it are being displaied in black..why ? Im posting the info that I think is enought, if I missing something, tell me.. // typedef struct{ float x, y, z; //vertex position DWORD color; //vertex color }GSPVERTEX_PC; #define D3DFVF_GSPVERTEX_PC ( D3DFVF_XYZ | D3DFVF_DIFFUSE ) //init custom vertex data:--------------------------------------------------- GSPVERTEX_PC tri_one[3] = { { 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB( 255, 0, 0 ) }, { 50.0f, 100.0f, 0.0f, D3DCOLOR_XRGB( 255, 0, 0 ) }, { 100.0f, 0.0f, 0.0f, D3DCOLOR_XRGB( 255, 0, 0 ) } }; //... //create vertex buffer:----------XXXXXXXXXXXXXXXXXXXXXXX-------------------------- if( gsp_pD3Ddevice9->CreateVertexBuffer( (sizeof( GSPVERTEX_PC )*3), D3DUSAGE_SOFTWAREPROCESSING, D3DFVF_GSPVERTEX_PC, D3DPOOL_SYSTEMMEM, &gsp_vb_one, NULL ) != D3D_OK ) MessageBoxA( NULL, "Error creating vertex buffer gsp_vb_one!", " dx error", MB_OK|MB_ICONEXCLAMATION ); /* Note it creates a blank buffer( with the right vertex size and type ) */ //-------------------------------XXXXXXXXXXXXXXXXXXXXXXX-------------------------- //fill vertex buffer:------------XXXXXXXXXXXXXXXXXXXXXXX-------------------------- //step 1: lock the buffer : /* You can retrieve a pointer to vertex buffer memory by calling the Lock method */ void * p_vb; //pointer to the vertex buffer in memory if( gsp_vb_one->Lock( 0, 0, &p_vb, 0 ) != D3D_OK ) MessageBoxA( NULL, "Coldnt lock the gsp_vb_one vertex buffer interface!", " dx error", MB_OK|MB_ICONEXCLAMATION ); //step 2: copy custom vertex data to that buffer: memcpy( p_vb, tri_one, sizeof( tri_one ) ); //step 3: unlock the buffer : gsp_vb_one->Unlock(); //-------------------------------XXXXXXXXXXXXXXXXXXXXXXX-------------------------- //... if( gsp_pD3Ddevice9->BeginScene() == D3D_OK ){ //rendering promitives: gsp_pD3Ddevice9->SetStreamSource( 0, gsp_vb_one, 0, sizeof( GSPVERTEX_PC ) ); gsp_pD3Ddevice9->SetFVF( D3DFVF_GSPVERTEX_PC ); gsp_pD3Ddevice9->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 ); gsp_pD3Ddevice9->EndScene(); } gsp_pD3Ddevice9->Present( NULL, NULL, NULL, NULL );

Share this post


Link to post
Share on other sites
1. You should be clearing the buffer to a background color before every BeginScene.

2. I don't know what state you set the device to, but make sure D3DRS_LIGHTING is set to FALSE.

By the way, there should be an example app in the SDK (under C++ Examples/Tutorials, I think) that does (almost) exactly what you're trying.

Share this post


Link to post
Share on other sites
I am calling Clear, sorry, just didnt post it ( // ... )
gsp_pD3Ddevice9->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 200 ), 1.0, 0 );

I didnt set any state..but it should just render a simple triangle in the simplest way possible..Do I need this?

heres how Im creating the device:

ZeroMemory( & gsp_D3Dpp, sizeof(gsp_D3Dpp) );

gsp_D3Dpp.Windowed = true;//false;
gsp_D3Dpp.BackBufferCount = 2;
gsp_D3Dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //D3DFMT_UNKNOWN = take current// D3DFMT_A8R8G8B8;
//gsp_D3Dpp.BackBufferWidth = gspWND_W;
//gsp_D3Dpp.BackBufferHeight= gspWND_H; //0 indicates backbuffer dimensions match windows size
gsp_D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
//to multisampletype.(Only discard supports miltisample )

gsp_D3Dpp.hDeviceWindow = gsp_mainwnd; //if set to NULL, the focus window is taken.
//gsp_D3Dpp.PresentationInterval= D3DPRESENT_INTERVAL_DEFAULT;
gsp_D3Dpp.EnableAutoDepthStencil = TRUE;
gsp_D3Dpp.AutoDepthStencilFormat = D3DFMT_D16;



//LPDIRECT3DDEVICE9 gsp_pD3Ddevice9;

if( ( gsp_pD3D9->CreateDevice( D3DADAPTER_DEFAULT, //primary adapter
D3DDEVTYPE_HAL, //can be HAL or REF
gsp_mainwnd, //the focus window( can be NULL if pp(function) is not NULL )
(hwvertexproc == true)? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING,//controls the device behavior
&gsp_D3Dpp, &gsp_pD3Ddevice9 ) ) != D3D_OK ){

MessageBox( NULL,
TEXT( "Error creating D3D device 9" ),
TEXT( " DX error" ),
MB_OK|MB_ICONEXCLAMATION );

CleanUp();

return E_FAIL;
}

Share this post


Link to post
Share on other sites
For a simple display, you don't need the stencil buffer stuff or 2 back buffers. Once you ZeroMemory the present parameters, try setting just:

Windowed = TRUE;
SwapEffect = D3DSWAPEFFECT_DISCARD;
BackBufferFormat = D3DFMT_UNKNOWN;

Again, take a look at the example in the SDK. It's nearly identical to what you've posted so far.

Share this post


Link to post
Share on other sites
Checking my code with the one of the SDK, I saw that the only difference is that I was using D3DFVF_XYZ not D3DFVF_XYZRHW..Now its all ok, I guess if I want use just XYZ i have to apply the transformations myself before render it..?
Thanx for the help.

Share this post


Link to post
Share on other sites
Sorry. The example does use transformed vertices. I had intended to refer only to the simpler device creation code.

For your code, you can simplify just the device creation code (which you posted), add
gsp_pD3Ddevice9->SetRenderState(D3DRS_LIGHTING,FALSE);
after the device is created, and keep the rest of your code as-is.

As mentioned by flyfish_bit, lighting is ON by default. You haven't set any lights so everything is dark. Don't worry about lights until you get the more basic triangle rendering stuff correct.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this