Sign in to follow this  
ktuluorion

Any idea why this outputs nothing?

Recommended Posts

I got this to work as a function that just had vertices[], and transformed it each time and output it. Instead, I want to batch the entire grid together, but for some reason it doesn't output anything when I try to make this large vertex buffer and transform them all into it. Any idea why? Thanks!
	CUSTOMVERTEX vertices[] =
    {
        {2.0f, 0.057f, 0.0f, 0xff00ff00, },
		{ 0.0f, 0.057f, 0.0f, 0xff00ff00, }, // x, y, z, rhw, color
        {2.0f, 0.057f, 2.0f, 0xff00ff00, },
        
		{ 0.0f, 0.057f, 2.0f, 0xff00ff00, }, // x, y, z, rhw, color
        { 2.0f, 0.057f, 2.0f, 0xff00ff00, },
        { 0.0f, 0.057f, 0.0f, 0xff00ff00, },
	
    };
	
CUSTOMVERTEX vertices2[11000];
int tot=0;

int i,j;

for ( i =by-10;i<by+7;i++)
 for (int j=bx-10;j<bx+7;j++)	  
     if ((tops[j][i]>0)||(heights[j][i]>0)){
		   for (int c=0;c<6;c++)
		   {
		    /*
			vertices2[tot+c].x=vertices[c].x+(float)(j-10)*2;
			vertices2[tot+c].y=vertices[c].y+(float)heights[j][i]-1;
			vertices2[tot+c].z=vertices[c].z+(float)(i-10)*2;
			vertices2[tot+c].color=0xff00ff00;	 
		    tot+=6;
		   */
		    vertices2[tot+c].x=vertices[c].x;
			vertices2[tot+c].y=vertices[c].y;
			vertices2[tot+c].z=vertices[c].z;
			vertices2[tot+c].color=0xff00ff00;	 
		    tot+=6;
		   
			
		}
	 }



D3DXMATRIX matWorld,matTrans;
    
D3DXMatrixTransformation( &matTrans,NULL,NULL,NULL,NULL,NULL,
&D3DXVECTOR3(0,0,0));

D3DXMatrixRotationYawPitchRoll(&matWorld,(float)rad(ry),(float)rad(rx),(float)rad(rz));

D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

D3DXMatrixScaling( &matTrans,sc,sc,sc);
D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

    d3ddevice->SetTransform( D3DTS_WORLD, &matWorld );
   
d3ddevice->SetRenderState(D3DRS_LIGHTING,FALSE);


if( FAILED( d3ddevice->CreateVertexBuffer( sizeof(vertices2),
			 D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &batch, NULL ) ) )
		return 0;
    
	VOID* pVertices;
    if( FAILED( batch->Lock( 0, sizeof(vertices2), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices2, sizeof(vertices2) );
    batch->Unlock();



d3ddevice->SetStreamSource( 0, batch, 0,sizeof(CUSTOMVERTEX) );
d3ddevice->SetFVF( D3DFVF_CUSTOMVERTEX );
d3ddevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 20);

d3ddevice->SetRenderState(D3DRS_LIGHTING,TRUE);

return 0;

Share this post


Link to post
Share on other sites
Do I have you all stumped? Basically what this is supposed to be doing is taking a basic square (vertices[]), and creating transformed copies and storing them into vertices2[], then displaying them. This is supposed to replace a routine for displaying a map where I was using a 3d model to display this square grid, because I want to batch it all up and make one call. Unfortunately, it's not doing anything at all once I run it.

Any help here? I've also tried calling
d3ddevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 20);

as

d3ddevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, (tot/3)-1);

which should draw everything, but I wasn't sure if something was wrong with that so I tried lowering the value just to see if I get any triangles, hence the value of 20.


Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this