[HELP] Color probs
the color of my grid lines doesn't seem to work. i tried changing it to almost
any color but it's ineffective. here's the screenshot http://www.geocities.com/cursebox87/spaceship.JPG
and here's my code:
void DrawGrid()
{
tVector3 vertData[2];
for(float i = -500; i <= 500; i += 5)
{
vertData[0] = tVector3(-500, 0, i);
vertData[0].color = D3DCOLOR_XRGB(255,0,255);
vertData[1] = tVector3( 500, 0, i);
vertData[1].color = D3DCOLOR_XRGB(255,0,255);
d3ddev->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vertData, sizeof(
vertData[0] ) );
//z direction
vertData[0] = tVector3(i, 0,-500);
vertData[0].color = D3DCOLOR_XRGB(255,0,255);
vertData[1] = tVector3(i, 0, 500);
vertData[1].color = D3DCOLOR_XRGB(255,0,255);
d3ddev->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vertData, sizeof(
vertData[0] ) );
}
}
void InitD3D(HWND hwnd)
{
d3d = Direct3DCreate9 (D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
InitGraphics();
InitLight();
d3ddev->SetRenderState(D3DRS_LIGHTING, true);
d3ddev->SetRenderState(D3DRS_ZENABLE, true);
d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
return;
}
void InitGraphics()
{
LPD3DXBUFFER bufferObjectMaterial;
D3DXLoadMeshFromX("spaceship.x", D3DXMESH_SYSTEMMEM, d3ddev, NULL, &bufferObjectMaterial, NULL,
&numMaterials, &meshObject);
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufferObjectMaterial->GetBufferPointer();
Material = new D3DMATERIAL9[numMaterials];
for(DWORD i = 0; i < numMaterials; i++)
{
Material = tempMaterials.MatD3D;
Material.Ambient = Material.Diffuse;
}
return;
}
void RenderFrame()
{
d3ddev->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
d3ddev->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45.0f),
(float)SCREEN_WIDTH / (float)SCREEN_HEIGHT, 0.1f, 300.0f);
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);
D3DXMatrixIdentity(&matProjection);
D3DXMATRIX matView;
D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(Camera.Pos.x, Camera.Pos.y, Camera.Pos.z), &D3DXVECTOR3(Camera.Angle.x, Camera.Angle.y, Camera.Angle.z),
&D3DXVECTOR3(Camera.UP.x, Camera.UP.y, Camera.UP.z));
d3ddev->SetTransform(D3DTS_VIEW, &matView);
d3ddev->BeginScene();
D3DXMATRIX matWorld;
D3DXMatrixTranslation(&matWorld, Pyramid.mPos.x, Pyramid.mPos.y, Pyramid.mPos.z);
d3ddev->SetTransform(D3DTS_WORLD,&matWorld );
for(DWORD i = 0; i < numMaterials; i++)
{
d3ddev->SetMaterial(&Material);
meshObject->DrawSubset(i);
}
D3DXMATRIX matGrid;
D3DXMatrixTranslation(&matGrid, 0.0f,0.0f,0.0f);
d3ddev->SetTransform(D3DTS_WORLD,&matGrid );
DrawGrid();
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
return;
}
void CleanD3D()
{
d3d->Release();
d3ddev->Release();
meshObject->Release();
}
void InitLight()
{
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 0.5f;
light.Diffuse.g = 0.5f;
light.Diffuse.b = 0.5f;
light.Diffuse.a = 1.0f;
D3DVECTOR vecDirection = {-1.0f, -1.0f, -1.0f};
light.Direction = vecDirection;
d3ddev->SetLight(0, &light);
d3ddev->LightEnable(0, TRUE);
return;
}
[Edited by - ShurikeN on March 18, 2008 6:25:32 PM]
anyone???
i have another question: what does D3DXMatrixIdentity do??
what's the difference if i do not include it in this code?
i have another question: what does D3DXMatrixIdentity do??
what's the difference if i do not include it in this code?
void Draw_Grid(){ D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); pD3DDevice->SetTransform(D3DTS_WORLD,&matWorld); tVector3 vertData[2]; for(float i = -500; i <= 500; i += 5) { // draw line in x direction vertData[0] = tVector3(-500, 0, i); vertData[0].color = 0xFFD9810E; vertData[1] = tVector3( 500, 0, i); vertData[1].color = 0xFFD9810E; pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vertData, sizeof( vertData[0] ) ); // draw line in z direction vertData[0] = tVector3(i, 0,-500); vertData[0].color = 0xFFD9810E; vertData[1] = tVector3(i, 0, 500); vertData[1].color = 0xFFD9810E; pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vertData, sizeof( vertData[0] ) ); }}
I was thinking something like..
You should study the rendering pipeline to understand the transformations.
that function simply changes the matrix into an identity matrix.
If you set a matrix as a transform, all the vertices you send to the rendering pipeline will get multiplied with the world view projection matrix.
It is something like, the way an object appears (like smaller or larger or front/back or upside down etc) to you is depended on it's position and orientation. You can set the position and/or orientation of an object, using the transformation matrices
[Edited by - Saughmraat on March 19, 2008 12:49:54 AM]
void Draw(){EnableLights();DrawObjects();DisableLights();DrawLines();}
You should study the rendering pipeline to understand the transformations.
that function simply changes the matrix into an identity matrix.
If you set a matrix as a transform, all the vertices you send to the rendering pipeline will get multiplied with the world view projection matrix.
It is something like, the way an object appears (like smaller or larger or front/back or upside down etc) to you is depended on it's position and orientation. You can set the position and/or orientation of an object, using the transformation matrices
[Edited by - Saughmraat on March 19, 2008 12:49:54 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement