This topic is 3721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

any model would do.. i just wanna ask if the vertices must be saved inside vertexbuffer?? u mean, include that inside it?? or you just put 3 vertices inside vertexbuffer then change the value of each vertex every loop.. waaaaaa!! im confused..

##### Share on other sites

Me too [smile]

First of all it would be useful to know which API you're using (DirectX, XNA, SlimDX...). All of these have functions to load a model into vertex-/indexbuffer pair, so yes vertices are typically saved in a vertexbuffer. This helps managing the memory the vertices use and facilitates copying them to video memory, which in turn helps performance.

For 3 or any low number of vertices, you can also use Draw functions that will upload them to videomemory each frame. This is typically less efficient, but for vertices that change every frame (so the vertex data *really* changes, to move/rotate/scale them you should use tranformation matrices), it saves you the overhead of the vertexbuffer and can actually work out better, not to mention it being more convenient. In case you feel like Googling, that function is called Drawprimitiveup in DirectX.

Hope this unconfuses you a bit [wink]

##### Share on other sites
im using directx9 as my API

i inserted all the vertices inside vertexbuffer.. my problem is, i use DrawPrimitive();

i cant manage to choose the vertex to use according to the faces needed.

e.g.

there are 8 vertices for a box

12 faces.

i inserted 8 vertices.. but i cant choose 3 vertices to use to form a face(from the 12 faces).

so what i did is:

12*3 = 36;
i inserted 36 vertices inside the vertexbuffer..

every 3 vertices forms 1 face.

so the downside is im wasting memory for repeated vertices.

how to solve this, i think DrawPrimitive is not suited for this job because it automatically get 3 consecutive vertices.

thanks for you replies!!

##### Share on other sites
You can use DrawIndexedPrimitive.

In addition to the vertexbuffer, you also need an index buffer.

Each set of 3 WORDs in the index buffer specify the vertices to use to draw a face.

If the first 4 vertices in the vertex buffer are the 4 vertices on one face of the cube (arranged clockwise), the first 2 faces specified in the index buffer are:

0,1,2 // specifying the vertices in CW order
2,3,0

Then set your stream source to the vertex buffer, the index buffer to the index buffer you filled, and call DrawIndexedPrimitive().

As you pick vertex indices to form faces, make sure you specify them in CW order!

##### Share on other sites
wow!! i get it! so the vertexbuffer stores vertices and indexbuffer stores indices. the problem is,,how to create indexbuffer? i only know how to use vertexbuffer..

thanks!!

##### Share on other sites
is there a structure for index buffer?

like vertex buffer.e.g.

struct myVer{    float x,y,z;    DWORD color;};

because,,the result is not what im expecting.. it must be a cube.
there will be 12 face. per face,it will have 3 indices.. so 12*3 is 36.

d3ddev-&gt;CreateVertexBuffer(sizeof(sVer)*numver,0,MYFVF,D3DPOOL_MANAGED,&d3dbuffer,0);	d3ddev-&gt;CreateIndexBuffer(sizeof(int)*numface*3,D3DUSAGE_SOFTWAREPROCESSING,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&d3dindex,0);	void *p;	d3dbuffer-&gt;Lock(0,0,&p,0);		memcpy(p,point,sizeof(sVer)*numver);		pPoint=(sVer*)p;	d3dbuffer-&gt;Unlock();	void *p2;	d3dindex-&gt;Lock(0,0,&p2,0);		memcpy(p2,ind,sizeof(int)*numface*3);	d3dindex-&gt;Unlock();

what's wrong?

[Edited by - macmoy on July 19, 2008 12:21:33 AM]

##### Share on other sites
I Got it!!! the ind data type must be WORD,,not INT

##### Share on other sites
You're creating a 16-bit index buffer but then copying ints into it ... You'll either want to use shorts for your indices or create a 32-bit index buffer :)

##### Share on other sites
ah!!! now i understand!! THANK YOU SO MUCH teutonicus!!!!

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 12
• 16
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632657
• Total Posts
3007680
• ### Who's Online (See full list)

There are no registered users currently online

×