Jump to content
  • Advertisement
Sign in to follow this  

loading meshes

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

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 this post

Link to post
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 this post

Link to post
Share on other sites
im using directx9 as my API

i'd made an OBJ loader just right now..

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.


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 this post

Link to post
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

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 this post

Link to post
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..


Share this post

Link to post
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.


void *p;

void *p2;

what's wrong?

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

Share this post

Link to post
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 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!