hey, ive got my code to draw some stars.....
struct FVF_XYZ_PSIZE_DIFFUSE
{
float x, y, z;
float rhw;
float psize;
D3DCOLOR diffuse;
};
const DWORD D3DFVF_XYZ_PSIZE_DIFFUSE = D3DFVF_XYZRHW | D3DFVF_PSIZE | D3DFVF_DIFFUSE;
void GalaxyScreen::GetViewport()
{
d3d_device->GetViewport(&vp);
}
void GalaxyScreen::InitScene()
{
GetViewport();
FVF_XYZ_PSIZE_DIFFUSE *verts = new FVF_XYZ_PSIZE_DIFFUSE[galaxy.numofstars];
for (int a = 0; a < galaxy.numofsystems; a++)
{
verts[a].x = galaxy.SolarSystems[a].pos.x + galaxy.SolarSystems[a].sun.pos.x;
verts[a].y = galaxy.SolarSystems[a].pos.y + galaxy.SolarSystems[a].sun.pos.y;
verts[a].z = 1.0f;
// verts[a].rhw = 0.5f;
verts[a].diffuse = galaxy.SolarSystems[a].sun.color;
verts[a].psize = 1.0f;
}
UINT numofverts = galaxy.numofsystems;
UINT sizeofverts = sizeof(FVF_XYZ_PSIZE_DIFFUSE) * numofverts;
if (FAILED( d3d_device->CreateVertexBuffer( sizeofverts, 0, D3DFVF_XYZ_PSIZE_DIFFUSE, D3DPOOL_MANAGED, &VB)))
FatalError("Vertex Buffer could not be made!");
void* Verticies;
if (FAILED(VB->Lock(0, sizeofverts, (BYTE**)&Verticies, 0)))
FatalError("Could not lock Vertex Buffer");
memcpy(Verticies, verts, sizeofverts);
VB->Unlock();
delete [] verts;
}
void GalaxyScreen::KillScene()
{
SAFE_RELEASE(VB);
}
void GalaxyScreen::Render()
{
d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 100), 1.0f, 0);
if(SUCCEEDED(d3d_device->BeginScene()))
{
UINT numofverts = galaxy.numofsystems;
d3d_device->SetStreamSource(0, VB, sizeof(FVF_XYZ_PSIZE_DIFFUSE));
d3d_device->SetVertexShader(D3DFVF_XYZ_PSIZE_DIFFUSE);
d3d_device->DrawPrimitive(D3DPT_POINTLIST, 0, numofverts);
d3d_device->EndScene();
}
d3d_device->Present(NULL, NULL, NULL, NULL);
}
This works... I didnt include the functions to scale the points, but it displays one quadrant of the points...
This is what I changed it to to try to get rid of the rhw component... what did I do wrong?
struct FVF_XYZ_PSIZE_DIFFUSE
{
float x, y, z;
// float rhw;
float psize;
D3DCOLOR diffuse;
};
const DWORD D3DFVF_XYZ_PSIZE_DIFFUSE = D3DFVF_XYZ | D3DFVF_PSIZE | D3DFVF_DIFFUSE;
void GalaxyScreen::GetViewport()
{
d3d_device->GetViewport(&vp);
}
void GalaxyScreen::InitScene()
{
GetViewport();
D3DXVECTOR3 EyePt = D3DXVECTOR3(0.0f, 0.0f, 2.0f);
D3DXVECTOR3 LookatPt = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 UpVec = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXMATRIX matWorld, matView, matProj;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixLookAtLH(&matView, &EyePt, &LookatPt, &UpVec);
FLOAT fAspect = vp.Width / (float)vp.Height;
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, fAspect, 1.0f, 500.0f);
d3d_device->SetTransform(D3DTS_WORLD, &matWorld);
d3d_device->SetTransform(D3DTS_VIEW, &matView);
d3d_device->SetTransform(D3DTS_PROJECTION, &matProj);
FVF_XYZ_PSIZE_DIFFUSE *verts = new FVF_XYZ_PSIZE_DIFFUSE[galaxy.numofstars];
for (int a = 0; a < galaxy.numofsystems; a++)
{
verts[a].x = galaxy.SolarSystems[a].pos.x + galaxy.SolarSystems[a].sun.pos.x;
verts[a].y = galaxy.SolarSystems[a].pos.y + galaxy.SolarSystems[a].sun.pos.y;
verts[a].z = 1.0f;
// verts[a].rhw = 0.5f;
verts[a].diffuse = galaxy.SolarSystems[a].sun.color;
verts[a].psize = 1.0f;
}
UINT numofverts = galaxy.numofsystems;
UINT sizeofverts = sizeof(FVF_XYZ_PSIZE_DIFFUSE) * numofverts;
if (FAILED( d3d_device->CreateVertexBuffer( sizeofverts, 0, D3DFVF_XYZ_PSIZE_DIFFUSE, D3DPOOL_MANAGED, &VB)))
FatalError("Vertex Buffer could not be made!");
void* Verticies;
if (FAILED(VB->Lock(0, sizeofverts, (BYTE**)&Verticies, 0)))
FatalError("Could not lock Vertex Buffer");
memcpy(Verticies, verts, sizeofverts);
VB->Unlock();
delete [] verts;
}
void GalaxyScreen::KillScene()
{
SAFE_RELEASE(VB);
}
void GalaxyScreen::Render()
{
d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 100), 1.0f, 0);
if(SUCCEEDED(d3d_device->BeginScene()))
{
UINT numofverts = galaxy.numofsystems;
d3d_device->SetStreamSource(0, VB, sizeof(FVF_XYZ_PSIZE_DIFFUSE));
d3d_device->SetVertexShader(D3DFVF_XYZ_PSIZE_DIFFUSE);
d3d_device->DrawPrimitive(D3DPT_POINTLIST, 0, numofverts);
d3d_device->EndScene();
}
d3d_device->Present(NULL, NULL, NULL, NULL);
}
Ive been stumped for ever and would really like some help!
thanx a lot!
Dwiel ~ tazzel3d