=]Mid[=]Night[= Super JLI'ler
Anmeldedatum: 20.11.2002 Beiträge: 380 Wohnort: Aachen Medaillen: Keine
|
Verfasst am: 29.07.2003, 13:38 Titel: Problem mit Skybox |
|
|
Meine Skybox ist fast genauso programmiert, wie im Buch, sie produziert aber grässliche Grafikfehler.
Blick in eine Ecke:
Code: |
#include "Skybox.h"
CSkyBox::CSkyBox(void)
{
for(int i = 0; i < 6; i++)
{
m_lpSkyTextures[i] = 0;
}
m_lpDevice = 0;
m_lpVertexBuffer = 0;
}
CSkyBox::~CSkyBox(void)
{
for(int i = 0; i < 6; i++)
{
if(m_lpSkyTextures[i])
{
m_lpSkyTextures[i]->Release();
m_lpSkyTextures[i] = 0;
}
}
if(m_lpVertexBuffer)
{
m_lpVertexBuffer->Release();
m_lpVertexBuffer = 0;
}
}
void CSkyBox::CreateSky(char* SkyName, float Size, LPDIRECT3DDEVICE9 lpDevice)
{
char Buffer[MAX_PATH];
SkyVertex Vertices[24];
float HalfSize = Size * 0.5f;
unsigned char* VBStart;
m_lpDevice = lpDevice;
// front
SetSkyVertex(&Vertices[0], -HalfSize, HalfSize, HalfSize, 0.0f, 0.0f);
SetSkyVertex(&Vertices[1], HalfSize, HalfSize, HalfSize, 1.0f, 0.0f);
SetSkyVertex(&Vertices[2], HalfSize, -HalfSize, HalfSize, 1.0f, 1.0f);
SetSkyVertex(&Vertices[3], -HalfSize, -HalfSize, HalfSize, 0.0f, 1.0f);
// right
SetSkyVertex(&Vertices[4], HalfSize, HalfSize, HalfSize, 0.0f, 0.0f);
SetSkyVertex(&Vertices[5], HalfSize, HalfSize, -HalfSize, 1.0f, 0.0f);
SetSkyVertex(&Vertices[6], HalfSize, -HalfSize, -HalfSize, 1.0f, 1.0f);
SetSkyVertex(&Vertices[7], HalfSize, -HalfSize, HalfSize, 0.0f, 1.0f);
// back
SetSkyVertex(&Vertices[8], HalfSize, HalfSize, -HalfSize, 0.0f, 0.0f);
SetSkyVertex(&Vertices[9], -HalfSize, HalfSize, -HalfSize, 1.0f, 0.0f);
SetSkyVertex(&Vertices[10], -HalfSize, -HalfSize, -HalfSize, 1.0f, 1.0f);
SetSkyVertex(&Vertices[11], HalfSize, -HalfSize, -HalfSize, 0.0f, 1.0f);
// left
SetSkyVertex(&Vertices[12], -HalfSize, HalfSize, -HalfSize, 0.0f, 0.0f);
SetSkyVertex(&Vertices[13], -HalfSize, HalfSize, HalfSize, 1.0f, 0.0f);
SetSkyVertex(&Vertices[14], -HalfSize, -HalfSize, HalfSize, 1.0f, 1.0f);
SetSkyVertex(&Vertices[15], -HalfSize, -HalfSize, -HalfSize, 0.0f, 1.0f);
// up
SetSkyVertex(&Vertices[16], -HalfSize, HalfSize, -HalfSize, 0.0f, 0.0f);
SetSkyVertex(&Vertices[17], HalfSize, HalfSize, -HalfSize, 1.0f, 0.0f);
SetSkyVertex(&Vertices[18], HalfSize, HalfSize, HalfSize, 1.0f, 1.0f);
SetSkyVertex(&Vertices[19], -HalfSize, HalfSize, HalfSize, 0.0f, 1.0f);
// down
SetSkyVertex(&Vertices[20], -HalfSize, -HalfSize, HalfSize, 0.0f, 0.0f);
SetSkyVertex(&Vertices[21], HalfSize, -HalfSize, HalfSize, 1.0f, 0.0f);
SetSkyVertex(&Vertices[22], HalfSize, -HalfSize, -HalfSize, 1.0f, 1.0f);
SetSkyVertex(&Vertices[23], -HalfSize, -HalfSize, -HalfSize, 0.0f, 1.0f);
for(int i = 0; i < 6; i++)
{
if(m_lpSkyTextures[i])
{
m_lpSkyTextures[i]->Release();
}
}
if(m_lpVertexBuffer)
{
m_lpVertexBuffer->Release();
}
sprintf(Buffer, "%s%s%s", "gfx\\", SkyName, "front.png");
D3DXCreateTextureFromFileEx(m_lpDevice, Buffer, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_lpSkyTextures[0]);
sprintf(Buffer, "%s%s%s", "gfx\\", SkyName, "right.png");
D3DXCreateTextureFromFileEx(m_lpDevice, Buffer, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_lpSkyTextures[1]);
sprintf(Buffer, "%s%s%s", "gfx\\", SkyName, "back.png");
D3DXCreateTextureFromFileEx(m_lpDevice, Buffer, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_lpSkyTextures[2]);
sprintf(Buffer, "%s%s%s", "gfx\\", SkyName, "left.png");
D3DXCreateTextureFromFileEx(m_lpDevice, Buffer, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_lpSkyTextures[3]);
sprintf(Buffer, "%s%s%s", "gfx\\", SkyName, "up.png");
D3DXCreateTextureFromFileEx(m_lpDevice, Buffer, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_lpSkyTextures[4]);
sprintf(Buffer, "%s%s%s", "gfx\\", SkyName, "down.png");
D3DXCreateTextureFromFileEx(m_lpDevice, Buffer, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_lpSkyTextures[5]);
m_lpDevice->CreateVertexBuffer(sizeof(SkyVertex) * 24, D3DUSAGE_WRITEONLY, D3D_SKYVERTEX, D3DPOOL_DEFAULT, &m_lpVertexBuffer, 0);
m_lpVertexBuffer->Lock(0, sizeof(SkyVertex) * 24, (void**)&VBStart, 0);
memcpy(VBStart, Vertices, sizeof(SkyVertex) * 24);
m_lpVertexBuffer->Unlock();
}
void CSkyBox::SetSkyVertex(SkyVertex* Vertex, float x, float y, float z, float tu, float tv)
{
Vertex->x = x;
Vertex->y = y;
Vertex->z = z;
Vertex->tu = tu;
Vertex->tv = tv;
}
void CSkyBox::Render(float CamXPos, float CamYPos, float CamZPos)
{
D3DXMatrixTranslation(&m_TransMatrix, CamXPos, CamYPos, CamZPos);
m_lpDevice->SetTransform(D3DTS_WORLD, &m_TransMatrix);
m_lpDevice->SetRenderState(D3DRS_ZENABLE, 0);
m_lpDevice->SetStreamSource(0, m_lpVertexBuffer, 0, sizeof(SkyVertex));
m_lpDevice->SetFVF(D3D_SKYVERTEX);
m_lpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_lpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
m_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
for(int i = 0; i < 6; i++)
{
m_lpDevice->SetTexture(0, m_lpSkyTextures[i]);
m_lpDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, i * 4, 2);
}
m_lpDevice->SetTexture(0, 0);
m_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
m_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
m_lpDevice->SetRenderState(D3DRS_ZENABLE, 1);
D3DXMatrixIdentity(&m_TransMatrix);
m_lpDevice->SetTransform(D3DTS_WORLD, &m_TransMatrix);
}
|
|
|