Jump to content
  • Advertisement
Sign in to follow this  
JClayton

VertexBuffer!! arfgh!!!

This topic is 4893 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

They aren't being drawn. Can anyone find the problem in the code? They are created using:
VertexBuffer *RenderWindow::CreateVertexBuffer( const string &name, long numVerts,
    long vertSize, DWORD descriptor )
  {
    VertexBuffer           *buffer;
    IDirect3DVertexBuffer8 *vertexBuffer;
    
    if ( FAILED( mDevice->CreateVertexBuffer( vertSize * numVerts, NULL, descriptor, 
      D3DPOOL_MANAGED, &vertexBuffer ) ) )
    {
      return NULL;
    }
    
    
    try
    {
      buffer = new VertexBuffer( name, numVerts, vertSize, descriptor, vertexBuffer );
    }
    catch( ... )
    {
      delete buffer;
      
      return NULL;
    }
    
    buffer->AddNode( VertexBuffer::mRoot );
    
    return buffer;
  }
Rendered using:
void RenderWindow::RenderVertexBuffer( VertexBuffer *buffer, int firstVertex, int numTris )
  {
    mDevice->SetStreamSource( 0, buffer->mBuffer, buffer->mVertSize );
    mDevice->SetVertexShader( buffer->mFVF );
    
    mDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, firstVertex, numTris );
  }
And manipulated using:
VertexBuffer::VertexBuffer( const string &value, long numVerts, long vertSize, 
    DWORD descriptor, IDirect3DVertexBuffer8 *vb ) : Node( value ), mNumVerts( numVerts ), 
    mVertSize( vertSize ), mFVF( descriptor ), mDataPtr( NULL ), mBuffer( vb )
  {
    
  }
  
  
  VertexBuffer::~VertexBuffer()
  {
    
  }
  
  
  bool VertexBuffer::Lock( int firstVertex )
  {    
    if ( FAILED( mBuffer->Lock( firstVertex * mVertSize, mNumVerts * mVertSize, 
      (BYTE**)&mDataPtr, D3DLOCK_NOSYSLOCK | D3DLOCK_DISCARD ) ) )
    {
      return false;
    }
    
    return true;
  }
  
  
  void VertexBuffer::Unlock()
  {
    mBuffer->Unlock(); 
  }
  
  
  bool VertexBuffer::Fill( int firstVertex, void *data )
  {
    if( !Lock( firstVertex ) )
    {
      return false;
    } 
    
    memcpy( mDataPtr, data, mNumVerts * mVertSize );
    
    Unlock();
    
    return true;
  }

Share this post


Link to post
Share on other sites
Advertisement
What does the debug output say?

Also, how do you know they aren't being drawn? How do you know they aren't just being drawn off-screen or behind the camera?

Share this post


Link to post
Share on other sites
The vbuffer is rendered using the following vertex data. No changes have been made to the default D3D settings. (no perspective translations etc...)

Vertex verts[4] = { 
{ 0.0f, 0.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f },
{ 1.0f, 0.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f },
{ 0.0f, 1.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f } };

Share this post


Link to post
Share on other sites
Hello,

HRESULT SetStreamSource( UINT StreamNumber,
IDirect3DVertexBuffer9 *pStreamData,
UINT OffsetInBytes,
UINT Stride
);

as you can se the third parameter is an offset, you se your fvf size as taht offset, i suggest 0 instead..
hmm maybe i'm wrong, which Dx version do you use?

Share this post


Link to post
Share on other sites
Hi,

have you set the following parameter in the rendering function?!

mDevice->LightEnable( 0, FALSE);

Maybe you should check your vertex format again!

hope this is the reason!
cu

Share this post


Link to post
Share on other sites
Still having problems...

More information:
#define VERTEXFVF ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 )

typedef struct
{
float x, y, z, rhw;
DWORD color;
float u, v;
} Vertex;

Share this post


Link to post
Share on other sites
Hi again,

I can't test it out, because my dev-machine currently isn't working, so I can only bet!

In your VertexBuffer-constructor you don't do anything, do you?! If this is the code you use then this might be the problem, because there are no information saved then. So if you write

buffer = new VertexBuffer( name, numVerts, vertSize, descriptor, vertexBuffer );

in your VertexBuffer-creating-function, the information isn't saved in the new buffer.


cu

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!