Jump to content
  • Advertisement


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


Problem with vertices

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

Hi all! I have a problem rendering a simple plane. This is my code (i only posted the parts concerning the vertices, its put together from an init- and a render-function):
//This is how my custom vertex is declared

    D3DXVECTOR3 position; // The position.

	D3DXVECTOR3 normal;
    FLOAT       tu, tv;   // The texture coordinates.



LPDIRECT3DVERTEXBUFFER8 g_pVB; // Buffer to hold vertices

LPDIRECT3DTEXTURE8      g_pGroundTexture; // Our ground texture

D3DMATERIAL8 Material;
//Then i load the texture:

D3DXCreateTextureFromFile( device, "ground.bmp", &g_pGroundTexture));
// and create the vertex buffer

device->CreateVertexBuffer( 5*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT, &g_pVB))
//and set up the material

Material.Diffuse.r = 1.0f;
Material.Diffuse.g = 1.0f;
Material.Diffuse.b = 1.0f;

// lock the vertex buffer

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

// and initialize the vertices

// i want to show a plane in the x/z axis, the normals point up


// then render it

device->SetTexture( 0, g_pGroundTexture);
device->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
device->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

device->SetVertexShader( D3DFVF_CUSTOMVERTEX );
device->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
device->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0,4);

It must be something very simple i forgot, but i just cant see it... Thank you! Edited by - gerbrost on November 5, 2001 4:53:34 PM

Share this post

Link to post
Share on other sites
device->CreateVertexBuffer( 5*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT, &g_pVB))

Change 5 to 4 (setting 4 vertices in code)

Also, vertex order means the triangle is only visible from below, normals don''t match. Change ordering of only the positions to 0,0,0 - 0,0,1 - 1,0,0 - 1,0,1

device->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0,4);

Change 4 to 2 (2 polygon primitives to draw, not 4)

Jim Adams

Share this post

Link to post
Share on other sites
Shame on me

Thank you very much!!

I still seem to have a problem: The plane is not lit...
The only lighting processed is ambient light.
Directional or other light types do not affect the plane, it stays dark.
Is there something up with the normals?

Edited by - gerbrost on November 6, 2001 7:13:21 AM

Share this post

Link to post
Share on other sites
For lighting, enable lighting render state as well as light:

pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
pd3dDevice->SetLight(0, &Light);
pd3dDevice->LightEnable(0, TRUE);

If you''ve done that, then make sure the D3DLIGHT8::Range is properly set to encompass the plane.

Jim Adams

Share this post

Link to post
Share on other sites
Here is my lighting code:
//*** Set up some lights to make the scene look cool

D3DLIGHT8 light;
ZeroMemory( &light, sizeof(D3DLIGHT8) );

light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
light.Ambient.r = 0.0f;
light.Ambient.g = 0.0f;
light.Ambient.b = 0.0f;
light.Specular.r = 0.0f;
light.Specular.g = 0.0f;
light.Specular.b = 0.0f;

vecDir = D3DXVECTOR3(0.0f,-1.0f,0.0f);

D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );

light.Range = 1000.0f;
device->SetLight( 0, &light );
device->LightEnable( 0, TRUE );

device->SetRenderState( D3DRS_LIGHTING, TRUE );

//*** Finally, turn on some ambient light.

device->SetRenderState( D3DRS_AMBIENT, 0x00202020 );

The ambient light affects the plane.
But whatever values i set for the directional light, it doesnt change anything.
When i load an x-file, the model is displayed correctly and affected by the light as it should be...

Im really confused...

Share this post

Link to post
Share on other sites
I dont understand any of the lighting stuff. Not like its hard but I have simpler concepts to understand first...onto my point : Do you have to set the specular light to 0.0f if you hvae already called ZeroMemory on the light struct?(reffering to the code above)

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!