Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cryo75

Quads are too far!!!

This topic is 5387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I''ve got a scene which renders and 10x10 map of quads and each quad has a texture of size 128x128. Funnily enough all I see is just 100 dots (10x10) and nothing more... I checked and re-checked my code and I don''t know what I need to change!!! HELP!!! Ivan

Share this post


Link to post
Share on other sites
Advertisement
Post the code!

If I were to guess, I would guess the rendering call is the problem.

DrawPrimitive();

It sounds like you have "PointList" as the first parm.

Share this post


Link to post
Share on other sites
Here''s the code...


#include "CTile.h"

CTile::CTile()
{
mpdev = NULL;
mpvb = NULL;

miTiles = 1;
miMapWidth = 10;
miMapHeight = 10;

D3DFVF_TILEVERTEX = (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
}

CTile::~CTile()
{
CleanUp();
}

void CTile::CleanUp()
{
SAFE_RELEASE(mpvb);
//for (int i = 0; i < miTiles; i++)

// SAFE_DELETE(mpmesh[i]);

}

HRESULT CTile::Create(LPDIRECT3DDEVICE9 pDev)
{
CleanUp();

//Get rendering device

mpdev = pDev;
if (!mpdev)
return E_FAIL;

//Load tilemap textures

if (FAILED(LoadTexture(128.0f, 128.0f, "grass00.bmp")))
return E_FAIL;

for (int i = 0; i < miTiles; i++) {
mpmesh[i] = new CD3DMesh();
if (FAILED(mpmesh[i]->Create(mpdev, "ground_tile1.x"))) {
return E_FAIL;
break;
}
mpmesh[i]->SetFVF(mpdev, D3DFVF_TILEVERTEX);
mpmesh[i]->RestoreDeviceObjects(mpdev);
}
memset(miTileMap, 0, (miMapWidth * miMapHeight) * sizeof(int));

D3DXVECTOR3 vFromPt = D3DXVECTOR3(0.0f, -20.0f, 0.0f);
D3DXVECTOR3 vLookPt = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 vUpVect = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView, &vFromPt, &vLookPt, &vUpVect);
mpdev->SetTransform(D3DTS_VIEW, &matView);

// Set up the textures

mpdev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
mpdev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
mpdev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
mpdev->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
mpdev->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );

// Set miscellaneous render states

mpdev->SetRenderState(D3DRS_DITHERENABLE, FALSE);
mpdev->SetRenderState(D3DRS_SPECULARENABLE, FALSE);
mpdev->SetRenderState(D3DRS_ZENABLE, TRUE);
mpdev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

D3DXMATRIXA16 matIdentity;
D3DXMatrixIdentity(&matIdentity);
mpdev->SetTransform(D3DTS_WORLD, &matIdentity);

D3DXMATRIX matProj;
FLOAT fAspect = (FLOAT)(640 / 480);
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f);
mpdev->SetTransform(D3DTS_PROJECTION, &matProj);

// Setup a material

D3DMATERIAL9 mtrl;
D3DUtil_InitMaterial( mtrl, 1.0f, 1.0f, 1.0f, 1.0f );
mpdev->SetMaterial( &mtrl );

// Clear out light structure

D3DLIGHT9 d3dLight;
ZeroMemory(&d3dLight, sizeof(D3DLIGHT9));
d3dLight.Type = D3DLIGHT_POINT;
d3dLight.Diffuse.r = 1.0f;
d3dLight.Diffuse.g = 1.0f;
d3dLight.Diffuse.b = 1.0f;
d3dLight.Position.x = 0.0f;
d3dLight.Position.y = -20.0f;
d3dLight.Position.z = 20.0f;
d3dLight.Attenuation0 = 1.0f;
d3dLight.Attenuation1 = 0.0f;
d3dLight.Range = 100.0f;

mpdev->SetLight( 0, &d3dLight );
mpdev->LightEnable( 0, TRUE );
mpdev->SetRenderState( D3DRS_LIGHTING, TRUE );

return InitTile();
}

HRESULT CTile::InitTile()
{
TILEVERTEX* pVertices;

//Create the interface object buffer

if(FAILED(mpdev->CreateVertexBuffer(4*sizeof(TILEVERTEX), 0, D3DFVF_TILEVERTEX, D3DPOOL_DEFAULT, &mpvb, NULL)))
return E_FAIL;

//Lock the buffer for editing

if(FAILED(mpvb->Lock(0, 0, (void**)&pVertices, 0)))
return E_FAIL;

//Create a quad made up of 3 vertices (triangle strips)

pVertices[0].position = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
pVertices[0].tu = 0.0f;
pVertices[0].tv = 1.0f;
pVertices[0].vecNorm = D3DXVECTOR3(0.0f,0.0f,1.0f);

pVertices[1].position = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
pVertices[1].tu = 0.0f;
pVertices[1].tv = 0.0f;
pVertices[1].vecNorm = D3DXVECTOR3(0.0f,0.0f,1.0f);

pVertices[2].position = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
pVertices[2].tu = 1.0f;
pVertices[2].tv = 1.0f;
pVertices[2].vecNorm = D3DXVECTOR3(0.0f,0.0f,1.0f);

pVertices[3].position = D3DXVECTOR3( 1.0f, 1.0f, 0.0f );
pVertices[3].tu = 1.0f;
pVertices[3].tv = 0.0f;
pVertices[3].vecNorm = D3DXVECTOR3(0.0f,0.0f,1.0f);

//Done editing, unlock the buffer

mpvb->Unlock();

return D3D_OK;
}

HRESULT CTile::LoadTexture(float xs, float ys, LPCSTR szFileName)
{
//LPDIRECT3DTEXTURE9 mptex;


//Do we have a device?

if (!mpdev)
return E_FAIL;

//Have we reached the maximum textures?

//if (miElements == miMaxElements)

// return E_FAIL;


//Load the texture from file

if (FAILED(D3DXCreateTextureFromFile(mpdev, szFileName, &mptex))) {
//if (miElements > 0)

// miElements--;

return E_FAIL;
}

////Increment the number of textures we''re using

//miElements++;


////Set the appropriate values in the structure

//pElements[miElements-1].mptex = mptex;

//pElements[miElements-1].xSize = xs;

//pElements[miElements-1].ySize = ys;


return D3D_OK;
}

HRESULT CTile::Render()
{
if (!mpdev)
return E_FAIL;

//mpdev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);


D3DXMATRIX matTranslation;
for( int iY = 0; iY < miMapHeight; iY++ ) {
for( int iX = 0; iX < miMapWidth; iX++ ) {
//Calculate the position

FLOAT fXPos = (-5.0f*iX)+22.5f;
FLOAT fYPos = (-5.0f*iY)+32.5f;

//Set position of tile

D3DXMatrixTranslation(&matTranslation, fXPos, fYPos, 0.0f);
mpdev->SetTransform(D3DTS_WORLD, &matTranslation);

mpdev->SetTexture(0, mptex);
mpdev->SetStreamSource(0, mpvb, 0, sizeof(TILEVERTEX));
mpdev->SetFVF(D3DFVF_TILEVERTEX);
mpdev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

//Dereference texture

mpdev->SetTexture(0, NULL);

//Render the tile

mpmesh[0]->Render(mpdev);
}
}

return D3D_OK;
}

HRESULT CTile::RestoreDeviceObjects()
{
//for (int i = 0; i < miTiles; i++)

// mpmesh[i]->RestoreDeviceObjects(mpdev);


return D3D_OK;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!