• Advertisement
Sign in to follow this  

Any idea why this outputs nothing?

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

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]>0)||(heights[j]>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]-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
Advertisement
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
Wow! What a "duh" moment. OK that sorted it all out.. thanks a lot! Here I was trying to figure out what I did wrong directx-wise, and it was a simple logic error.

I appreciate the help!

Share this post


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

  • Advertisement