Jump to content
  • Advertisement
Sign in to follow this  
jolley

how to organize these vertex

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

i am trying to develop a kind of shapes like pentagram. there are totally 8 triangles which only share one vertex as u can see from code above,it is clockwise,but it doesnot print a pentagram as i expected! and i consider D3DPT_TRIANGLESTRIP in the app.also it is a pity that i cannot attach a structure of my idea.for the attachment is not in use. my customvertex is like this: struct CUSTOMVERTEX { FLOAT x,y,z,rhw; DWORD color; }; CUSTOMVERTEX g_Vertices[]={ //the first triangle. { 500.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 1 { 600.0f,1000.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 2 { 700.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 3 //the second triangle. { 700.f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 4 { 1000.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 5 { 750.0f,700.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 6 //the third triangle. { 600.0f,650.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 7 { 800.0f,600.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 8 { 750.f,700.f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 9 //the fourth triangle. { 500.f,700.f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 10 { 600.0f,650.f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 11 { 400.0f,600.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 12 //the fifth triangle. { 300.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 13 { 500.0f,800.0f,50.0f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 14 { 550.0f,600.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 15 //the sixth triangle. { 600.f,650.f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 16 { 700.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 17 { 750.f,700.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 18 //the seventh triangle. { 500.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 19 { 700.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 20 { 600.0f,650.f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 21 //the eighth triangle. { 500.0f,700.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 22 { 500.0f,800.0f,0.5f,1.0,D3DCOLOR_ARGB(255,255,255,255), },//vertex 23 { 600.0f,650.f,0.5f,1.0,D3DCOLOR_ARGB(255,127,127,127), },//vertex 24 }; help! regards, jolley [Edited by - jolley on August 25, 2005 2:28:37 AM]

Share this post


Link to post
Share on other sites
Advertisement
Does your code render any triangles at all? Are any number of them being rendered correctly? Are you using a triangle list when drawing?

You say that your vertices are clockwise orederd but since you have an RHW component in your vertex structure you seem to be using transformed vertices. If so you draw in screen coordinates with the origin in the top-left corner, positive x to the right and positive y downward. In this coordinate system your vertices are counter-clockwise oriented and should be rendered with CCW culling mode (the default).

Please place long code segments within [ source ][ /source ] tags.

Share this post


Link to post
Share on other sites
do u mean i should put something like

g_pD3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW);


in the render function if i use a counter clock-oriented coordinate system.
but i had expected to have the things done in a coordinate system with positve x goes right,and positive goes upward.
SO in that way, it need not be rendered with CCW culling mode (the default).
Quote:

Does your code render any triangles at all? Are any number of them being rendered correctly? Are you using a triangle list when drawing?


and the render function is as follow:

LPDIRECT3DDEVICE8 g_pD3DDevice=NULL;
void Render()
{
if(g_pD3DDevice == NULL)
{
return;
}

//Clear the backbuffer to a green color
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);

//Begin the scene
g_pD3DDevice->BeginScene();

//Rendering of our game objects will go here
g_pD3DDevice->SetStreamSource(0,g_pVertexBuffer,sizeof(CUSTOMVERTEX));
g_pD3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,8);//use triangle list,and build up 8 triangles
g_pD3DDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW);//later added!
//but in my opinoin,SetRenderState can be removed, for it gives no help here.
//End the scene
g_pD3DDevice->EndScene();

//Filp the back and front buffers so that whatever has been rendered on the back buffer
//will now be visible on screen (front buffer).
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}




when later i replace the CUSTOMVERTEX in a well-behaved function,it come out nothing.
so i do think the problem goes inside the CUSTOMVERTEX .these vertex is not well set,but i donot know how to fix the bug.
how do u know about pentagram?
if so can u give me some further advice? :)
thanks ,
jolley

Share this post


Link to post
Share on other sites
You need to place the SetRenderState call before the DrawPrimitive call. Otherwise the render state won't affect the drawn triangles.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!