Archived

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

Moltopulp

Little problem with vertex colour

Recommended Posts

Hi, i''m trying to do a simple Quake 3 map viewer and i have a problem with vertices colour. I already try the program with textures and lightmaps and all work fine. The structure of the vertex that i use is the seguent: struct CUSTOMVERTEX { FLOAT x, y, z; FLOAT u,v; FLOAT u1,v1; DWORD colour; }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_TEX2 | D3DFVF_DIFFUSE) As a test i have used a simple vertex buffer, and the vertices that i use as filled as seguent: pVertices[0].x = -1.0f; pVertices[0].y = -1.0f; pVertices[0].z = -1.0f; pVertices[0].u = 0.0f; pVertices[0].v = 1.0f; pVertices[0].u1 = 0.0f; pVertices[0].v1 = 1.0f; pVertices[0].colour = 0xFFFFFFFF; pVertices[1].x = -1.0f; pVertices[1].y = 1.0f; pVertices[1].z = -1.0f; pVertices[1].u = 0.0f; pVertices[1].v = 0.0f; pVertices[1].u1 = 0.0f; pVertices[1].v1 = 0.0f; pVertices[1].colour = 0xFFFFFFFF; pVertices[2].x = 1.0f; pVertices[2].y = 1.0f; pVertices[2].z = -1.0f; pVertices[2].u = 1.0f; pVertices[2].v = 0.0f; pVertices[2].u1 = 1.0f; pVertices[2].v1 = 0.0f; pVertices[2].colour = 0xFFFFFFFF; pVertices[3].x = 1.0f; pVertices[3].y = 1.0f; pVertices[3].z = -1.0f; pVertices[3].u = 1.0f; pVertices[3].v = 0.0f; pVertices[3].u1 = 1.0f; pVertices[3].v1 = 0.0f; pVertices[3].colour = 0xFFFFFFFF; pVertices[4].x = 1.0f; pVertices[4].y = -1.0f; pVertices[4].z = -1.0f; pVertices[4].u = 1.0f; pVertices[4].v = 1.0f; pVertices[4].u1 = 1.0f; pVertices[4].v1 = 1.0f; pVertices[4].colour = 0xFFFFFFFF; pVertices[5].x = -1.0f; pVertices[5].y = -1.0f; pVertices[5].z = -1.0f; pVertices[5].u = 0.0f; pVertices[5].v = 1.0f; pVertices[5].u1 = 0.0f; pVertices[5].v1 = 1.0f; pVertices[5].colour = 0xFFFFFFFF; The problem is that i always seen the rendered polygons with a red component. If i change the colour value for the vertices i don''t see any difference... I don''t know if i must set something in the render state or in the texture stage. Actually for the texture i set: g_pd3dDevice->SetTexture(0,texture[nText]); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_MODULATE); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_DIFFUSE); g_pd3dDevice->SetTextureStageState(0,D3DTSS_MIPFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetTextureStageState(0,D3DTSS_MAGFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetTextureStageState(0,D3DTSS_MINFILTER, D3DTEXF_LINEAR); For the render stage i set: g_pd3dDevice->SetRenderState ( D3DRS_CULLMODE, D3DCULL_NONE); g_pd3dDevice->SetRenderState ( D3DRS_FILLMODE, D3DFILL_SOLID); g_pd3dDevice->SetRenderState ( D3DRS_ZENABLE, TRUE); g_pd3dDevice->SetRenderState ( D3DRS_LIGHTING, FALSE ); Thanks for the help. Alex

Share this post


Link to post
Share on other sites
When you use a custom vertex format (i.e. using FVFs) which is used with the fixed function pipeline, the components in each vertex *must* be in memory in the correct order (as specified in the D3D documentation).

Change your vertex structure to:

struct CUSTOMVERTEX
{
FLOAT x, y, z;
DWORD colour;
FLOAT u,v;
FLOAT u1,v1;
};


texture map coordinates always come at the END of the structure.

One other thing which is more a case of defensive programming:

Make sure you put a SetTSS(1,D3DTSS_COLOROP, D3DTOP_DISABLE); in there to mark the end of the colour pipe.

Also do the same with alpha pipe, even if you aren''t using alpha. The alpha pipe should be kept alive to that point too:

SetTSS(0,D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
SetTSS(0,D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
SetTSS(1,D3DTSS_ALPHAOP, D3DTOP_DISABLE);



--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites