So I realized I was using precalculated vertices D3DFVF_XYZTRHW. Stopped that. Here is where I am now, I can still not see the triangle but can see the spaceship mesh in the center. Am I not looking at my triangle correctly?
Renderin' Rooteen
Code:
m_pd3dDevice->BeginScene();
D3DXMATRIX matWorld, matView;
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3(0.0f, 0.0f, -5.0f), // Eye
&D3DXVECTOR3(0.0f, 0.0f, 0.0f), // At
&D3DXVECTOR3(0.0f, 1.0f, 0.0f)); // Up
m_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
ScenePrimitive * s = square;
static float x = 0;
x += 0.1;
D3DXMatrixTranslation(&matWorld, 0, 0, 0);
D3DXMatrixRotationY(&matWorld, x);
m_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
for(size_t i = 0; i < spaceship.materials.size(); ++i)
{
m_pd3dDevice->SetMaterial(&spaceship.materials[i]);
spaceship.mesh->DrawSubset(i);
}
m_pd3dDevice->SetTexture(0, 0);
m_pd3dDevice->SetMaterial(&s->material);
m_pd3dDevice->SetFVF(s->fvf);
m_pd3dDevice->SetStreamSource(0, s->buffer, 0, sizeof(Vertex));
m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
m_pd3dDevice->EndScene();
Inishillization Rooteen
Code:
D3DXMATRIX mProjection;
::D3DXMatrixPerspectiveFovLH(&mProjection, D3DX_PI * 0.5f,
double(width) / double(height), 0.1f, 100.0f);
m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mProjection);
D3DLIGHT9 light;
D3DMATERIAL9 material;
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;
light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);
m_pd3dDevice->SetLight(0, &light);
m_pd3dDevice->LightEnable(0, true);
ZeroMemory(&material, sizeof(D3DMATERIAL9));
material.Diffuse.r = material.Ambient.r = 1.0f;
material.Diffuse.g = material.Ambient.g = 1.0f;
material.Diffuse.b = material.Ambient.b = 1.0f;
material.Diffuse.a = material.Ambient.a = 1.0f;
ScenePrimitive * p = new ScenePrimitive;
struct Vertex
triangle[] =
{
{0, 1, 0, D3DCOLOR_XRGB(0, 0, 255),},
{1, -1, 0, D3DCOLOR_XRGB(0, 255, 0),},
{-1, -1, 0, D3DCOLOR_XRGB(255, 0, 0),},
};
p->fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
p->bufsize = lengthof(triangle);
m_pd3dDevice->CreateVertexBuffer(sizeof(triangle),
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, p->fvf, D3DPOOL_DEFAULT,
&p->buffer, 0);
Vertex * vertices;
p->buffer->Lock(0, 0, (void**) &vertices, 0);
memcpy(vertices, triangle, sizeof(triangle));
p->buffer->Unlock();
square = p;
spaceship = loadMesh("C:\\Proijektz\\Directx\\Spaceship 2.x");