Archived

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

can someone tell me why...

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

....can someone tell me why when i render The Vertex Buffer created by this funciton, only half of it is drawn...
  
__declspec(dllexport) void RENDER::CreateVB(LPDIRECT3DVERTEXBUFFER8 & vb,int numVerts, CUSTOMVERTEX  * cstm,LPDIRECT3DDEVICE8 & D3D_DEVICE, HWND & hwnd)
{
	LPDIRECT3DVERTEXBUFFER8 VtxB;

	if( FAILED( D3D_DEVICE->CreateVertexBuffer( numVerts*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &vb ) ) )
		{
			MessageBox(hwnd,"Couldn''t create vb","Error",MB_OK | MB_ICONERROR);
			return  ;
		}
int i;
    //Fill the vertex buffer.

    CUSTOMVERTEX* pVertices;
	if( FAILED( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) )
    
	{
		MessageBox(hwnd,"Couldn''t create vb","Error",MB_OK | MB_ICONERROR);
		return  ;
	}
	for (i=0;i<numVerts;i++)
	{
		pVertices[i].x=cstm[i].x;
		pVertices[i].y=cstm[i].y;
		pVertices[i].z=cstm[i].z;
		pVertices[i].tu=cstm[i].tu;
		pVertices[i].tv=cstm[i].tv;
		pVertices[i].color=cstm[i].color;
	}
  
It is not the rendering code because i hvae tried that out on someone elses prog and it worked.

Share this post


Link to post
Share on other sites
It might depend on your video card. When I first started doing that, I was doing a terrain rendering engine. I''d draw tons of triangles and at one point, it would just stop. On my desktop it got further, but never quite finished. It took me forever to figure out that the problem is that you can only draw so many triangles with each call to the rendering functions.

Check your DDCAPS stuff and see what the maximum number of vertices you can render in a single function call is. I was running out at 16k or so. Don''t try and render any more than that in a single rendering call. Otherwise it won''t render all of them.


Looking for an honest video game publisher? Visit www.gamethoughts.com

Share this post


Link to post
Share on other sites
quote:
Original post by tHiSiSbOb
lol ty for the advice but i think a geforce 4 can handle more than 1 polygon


1 polygon ? OK so you are saying you are trying to draw 2 and only seeing one ? Why didn''t you say so in the first place ? Or used a meaningful subject.

Anyway, usually this is caused by drawing the second polygon counter clockwise.

Share this post


Link to post
Share on other sites
You need to also give us the code you use to initialize your vertex coordinates and it would be nice to see the render section as well just in case. My guess is that your vertices are declared out of order for the second triangle. In order means clockwise when viewed from the camera.

If verts are 0,0,0 1,0,0 0,1,0 and 1,1,0 then it looks like this
v0---v1

v2---v3

v0, v1 and v2 are in clockwise order but v1, v2 and v3 are not. Seeing how you initialize your vertices would be handy to know what order they are in. How you set them up depends on what primitive type you are designating when you call DrawPrimitive() which is why seeing your render code would be useful.

Share this post


Link to post
Share on other sites
one other thing. the naming of variables isn''t very clear but it appears that you create a vertex buffer with a call to CreateVertexBuffer (which returns you a vertex buffer in the &vb variable you pass it)

but then you call ''lock'' on a global (?) variable which seems to be another vertex buffer.

i think you want to lock the buffer you just created (vb), but i could be wrong.

also as posted above, you should supply your custom vertex structure/creation.

wb

Share this post


Link to post
Share on other sites
code to init verts:






  

struct CUSTOMVERTEX
{
FLOAT x, y, z; the vertex
DWORD color;
FLOAT tu,tv;
};
CUSTOMVERTEX verts[6];
verts[0].x=-1;
verts[0].y=-1;
verts[0].z=0;
verts[0].tu=0;
verts[0].tv=0;
//verts[0].color=0xffff000000;


verts[1].x=1;
verts[1].y=-1;
verts[1].z=0;
verts[1].tu=1;
verts[1].tv=0;


verts[2].x=1;
verts[2].y=1;
verts[2].z=0;

verts[2].tu=1;
verts[2].tv=1;

verts[3].x=1;
verts[3].y=1;
verts[3].z=0;

verts[3].tu=1;
verts[3].tv=1;

verts[4].x=-1;
verts[4].y=1;
verts[4].z=0;

verts[4].tu=0;
verts[4].tv=1;

verts[5].x=-1;
verts[5].y=-1;
verts[5].z=0;

verts[5].tu=0;
verts[5].tv=0;
LPDIRECT3DVERTEXBUFFER8 vb;


RENDER render;
CAMERA camera;
render.CreateVB(vb,6,verts,PRID,hwnd);

rendering code:

  
__declspec(dllexport) void RENDER::RenderVB(LPDIRECT3DVERTEXBUFFER8 & VertexBuffer, int numPrimitives,LPDIRECT3DDEVICE8 & D3D_DEVICE)
{
D3D_DEVICE->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

// Begin the scene

D3D_DEVICE->BeginScene();


// Camera.SetProjectionMatrix();


// Camera.LookAt(0,0,-10,0,0,0);


D3D_DEVICE->SetStreamSource( 0, VertexBuffer, sizeof(CUSTOMVERTEX) );
D3D_DEVICE->SetVertexShader( D3DFVF_CUSTOMVERTEX );
D3D_DEVICE->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, numPrimitives );

// End the scene

D3D_DEVICE->EndScene();

// Present the backbuffer contents to the display

D3D_DEVICE->Present( NULL, NULL, NULL, NULL );
}

Share this post


Link to post
Share on other sites
LOL...I fixed the verts so they are clock wise....now it draws 3/4 of what i want.
  
CUSTOMVERTEX verts[6];
verts[0].x=1;
verts[0].y=1;
verts[0].z=0;
verts[0].tu=1;
verts[0].tv=1;
//verts[0].color=0xffff000000;


verts[1].x=1;
verts[1].y=-1;
verts[1].z=0;
verts[1].tu=1;
verts[1].tv=0;


verts[2].x=-1;
verts[2].y=-1;
verts[2].z=0;

verts[2].tu=0;
verts[2].tv=0;

verts[3].x=-1;
verts[3].y=1;
verts[3].z=0;

verts[3].tu=0;
verts[3].tv=1;

verts[4].x=1;
verts[4].y=1;
verts[4].z=0;

verts[4].tu=1;
verts[4].tv=1;

verts[5].x=-1;
verts[5].y=-1;
verts[5].z=0;

verts[5].tu=0;
verts[5].tv=0;

Share this post


Link to post
Share on other sites
I think your vertices may have been in the right order the first time around.

Your mistake is that you are using TRIANGLE_STRIP instead of TRIANGLE_LIST I think.

TRIANGLE_STRIP uses the first three vertices to draw the first triangle. From then on it takes the last two vertices from the last triangle drawn, adds the next unused vertex and renders the next triangle.

TRIANGLE_LIST uses every three vertices for the next triangle.

Share this post


Link to post
Share on other sites