void Terrain::drawNodes()
{
_device->SetRenderState(D3DRS_LIGHTING, false);
_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
_device->SetRenderState(D3DRS_POINTSCALEENABLE, true);
_device->SetRenderState(D3DRS_POINTSIZE, d3d::FtoDw(0.25f));
_device->SetRenderState(D3DRS_POINTSIZE_MIN, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_A, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_B, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_C, d3d::FtoDw(1.0f));
_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
///////////////////////////////////////////////////////////////////////
_device->SetTexture(0, _point);
_device->SetFVF(TerrainNode::FVF);
_device->SetStreamSource(0, _vb, 0, sizeof(TerrainNode)); //this causes runtime error
_device->DrawPrimitive( D3DPT_POINTLIST, 0, _numNodes );
///////////////////////////////////////////////////////////////////////
_device->SetRenderState(D3DRS_LIGHTING, true);
_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
_device->SetRenderState(D3DRS_POINTSCALEENABLE, false);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}
[edited by - Silex on January 18, 2004 4:46:43 PM]
Runtime crash when calling SetStreamSource...
I have a terrain class that renders fine and I'm trying to add point sprites above each patch ( diamond) of the terrain. I have it set up so the terrain is rendered first using a mesh, then I set the stream to the vertex buffer containing the point sprites. The program compiles fine, but when I run it it crashes and the debugger points me to the line where I'm assigning the point sprite VB to the device stream.
Here's the function that's supposed to draw the point sprites:
quote:
_device->SetStreamSource(0, _vb, 0, sizeof(TerrainNode)); //this causes runtime error
I would be willing to bet that the size of your vertex buffer is wrong and you area accessing memory that has not been defined. Can you post the code where you create the vertex buffer along with the data structure definitions?
_______________________________________
Understanding is a three edged sword...
Have your independent game reviewed by your peers on the www.FreelanceGames.com review ladder.
This is where I fill and declare the buffer:
And this is the TerrainNode definition:
With the FVF defined as D3DFVF_XYZ | D3DFVF_DIFFUSE.
HRESULT hr = 0; hr = _device->CreateVertexBuffer( _numNodes * sizeof(TerrainNode), D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS, TerrainNode::FVF, D3DPOOL_MANAGED, &_vb, 0 ); if ( FAILED(hr) ) return false; // coordinates to start generating vertices at int startX = -_width / 2 + _cellSpacing / 2; int startZ = _depth / 2 - _cellSpacing / 2; // coordinates to end generating vertices at int endX = _width / 2 - _cellSpacing / 2; int endZ = -_depth / 2 + _cellSpacing / 2; TerrainNode* n; _vb->Lock( 0, 0, (void**)&n, 0 ); int i = 0; for(int z = startZ; z >= endZ; z -= _cellSpacing) { int j = 0; for(int x = startX; x <= endX; x += _cellSpacing) { int index = i * _numCellsPerRow + j; n[index] = TerrainNode( (float)x, getHeight(x, z), (float)z, d3d::LIGHTGREEN ); j++; // next column } i++; // next row } _vb->Unlock();}
And this is the TerrainNode definition:
struct TerrainNode { TerrainNode(){} TerrainNode( float x, float y, float z, D3DCOLOR color ) { _position.x = x; _position.y = y; _position.z = z; _color = color; } D3DXVECTOR3 _position; D3DCOLOR _color; static const DWORD FVF; };
With the FVF defined as D3DFVF_XYZ | D3DFVF_DIFFUSE.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement