Jump to content
  • Advertisement
Sign in to follow this  
kelcharge

NeHe lesson 10 confusion.

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

Advertisement
Well, looking at the world.txt file that comes with the tutorial and the code itself, it seems like it's just a long list of vertex and texture coordinates.

Quote:
world.txt
NUMPOLLIES 36

This is the number of polygons
Quote:
world.txt
// Floor 1
-3.0 0.0 -3.0 0.0 6.0
[..]

The first line is just a comment and will be skipped by the parser.
The second line contains (in order):
- the x component of the first vertex
- the y component of the first vertex
- the z component of the first vertex
- the u coordinate of the texture for the first vertex
- the v coordinate of the texture for the first vertex

And so on..

In "real life" a mesh would never be stored in a flat file like this, but as an example it works.

Share this post


Link to post
Share on other sites
Quote:
Original post by WanMaster

In "real life" a mesh would never be stored in a flat file like this


Could you elaborate a little more on this please, storing a world in something else perhaps.

EDIT: Thats a pretty slick website there... :)

Share this post


Link to post
Share on other sites
Quote:
Could you elaborate a little more on this please, storing a world in something else perhaps.

Reading a mesh description from a plain text file like this is pretty slow. In the tutorial, the model consists of only a couple of triangles, so it doesn't matter. Vertices, texture coordinates, normals etc. are normally stored in a binary (human unreadable) format that allows you to load the data much faster. Examples of these of these formats are 3DS, M3D, DirectX X files etc. Or you can come up with your own specification.

Creating a binary file could look something like this:

(just a quick example)

// vertex structure
struct vertex
{
float x, y, z;
};

// array holding ten vertices
vertex vertices[10];

// after these vertices have been initialized, we'll write them to a file
FILE *pFile = NULL;
pFile = fopen("filename.ext", "wb");
fwrite(&vertices, sizeof(vertex), 10, pFile);
fclose(pFile);

Reading would look pretty much the same. You can notice you only need one call to write (or read) all the vertices. Most formats include a header (like the Nehe example) specifying the number of vertices, the number of indices, the name, materials etc.

Besides faster loading, it makes the file a lot smaller as well.

I'm pretty sure there's a Nehe tutorial covering the loading of these kind of files.

Quote:
EDIT: Thats a pretty slick website there... :)

Just temporary, didn't have time to put something up yet. [grin]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!