Hey everyone, I am creating a grid using a vertex buffer and D3DPT_LINELIST.
I set each vertex color to:
D3DCOLOR_XRGB(0, 50, 50), the line appears dark green
D3DCOLOR_XRGB(0, 50, 150), the line appears the EXACT same color as (0,50,50)
D3DCOLOR_XRGB(0, 10, 100), the line is COMPLETELY black.
As you can see, my colors are not displaying properly at all. I am using 24-bit color on my desktop and 32 bit color in fullscreen mode, as you'll see below.
Lighting is disabled to test the purity of the colors. These invalid color displays occur in both fullscreen AND windowed mode.
Here is how I have initialized my device:
m_Object = Direct3DCreate9(D3D_SDK_VERSION);
m_Object->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_AdapterInfo);
// Create Device
D3DPRESENT_PARAMETERS d3p = {0};
if(dp.EnableDepth)
{
d3p.EnableAutoDepthStencil = TRUE;
d3p.AutoDepthStencilFormat = D3DFMT_D24X8;
}
m_Window->GetClientSize(m_Resolution);
d3p.BackBufferFormat = dp.Fullscreen ? D3DFMT_A8R8G8B8 : m_AdapterInfo.Format;
d3p.Windowed = dp.Fullscreen ? FALSE : TRUE;
d3p.BackBufferWidth = m_Resolution.x;
d3p.BackBufferHeight = m_Resolution.y;
d3p.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3p.Flags = dp.LockableBackbuffer ? D3DPRESENTFLAG_LOCKABLE_BACKBUFFER : 0;
d3p.hDeviceWindow = m_Window->GetWindowHandle();
m_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
m_Window->GetWindowHandle(), D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3p, &m_Device);
if(dp.EnableDepth)
{
// Initialize View Volume
D3DVIEWPORT9 vp;
vp.X = 0;
vp.Y = 0;
vp.Width = m_Resolution.x;
vp.Height = m_Resolution.y;
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;
m_Device->SetViewport(&vp);
// Initialize Projection Matrix
D3DXMATRIX pm;
float Aspect = (float)m_Resolution.x / m_Resolution.y;
float FOV = PI / 4;
D3DXMatrixPerspectiveFovLH(&pm, FOV, Aspect, 1.0f, 1000.0f);
m_Device->SetTransform(D3DTS_PROJECTION, &pm);
}
// Render States
m_Device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(60, 60, 60));
m_Device->SetRenderState(D3DRS_LIGHTING, (dp.EnableLighting && dp.EnableDepth) ? TRUE : FALSE);
m_Device->SetRenderState(D3DRS_CULLMODE, (dp.EnableCulling) ? D3DCULL_CCW : D3DCULL_NONE);
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
// Texture States
m_Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
I also display a mesh with a texture with this set of lines, and the mesh displays PERFECTLY! So, if the LINES are not coloring properly but the MESH is, this might have something to do with the vertex buffer, right? Here is my vertex format and vertex buffer initialization:
// Vertex Format
#define FVF_3D (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1)
// Vertex Structure
struct Vertex3D
{
float x; ///< Vertex X-Coordinate
float y; ///< Vertex Y-Coordinate
float z; ///< Vertex Z-Coordinate
float nx; ///< Vertex Normal X-Coordinate
float ny; ///< Vertex Normal Y-Coordinate
float nz; ///< Vertex Normal Z-Coordinate
D3DCOLOR Color; ///< Vertex Color (Blend)
float tu; ///< U Texture Coordinate
float tv; ///< V Texture Coordinate
};
// Vertex Buffer Initialization
m_Device->CreateVertexBuffer(
sizeof(Vertex3D) * NumVertices, D3DUSAGE_WRITEONLY,
FVF_3D, D3DPOOL_DEFAULT, &m_VertexBuffer, 0);
If you don't see the error here, what else can I check? Is there more source code you would like me to post? Keep in mind that lighting IS disabled and depth IS enabled.