Advertisement

NeHe lesson 10 confusion.

Started by August 14, 2005 06:50 PM
2 comments, last by Wan 19 years, 1 month ago
In lesson 10, I am confused on the text file holding the world information. What all goes in that text file exactly?
True God of the TribunalKelchargeMy SiteMy Ugly Forums
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.
Advertisement
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... :)
True God of the TribunalKelchargeMy SiteMy Ugly Forums
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 structurestruct vertex{  float x, y, z;};// array holding ten verticesvertex vertices[10];// after these vertices have been initialized, we'll write them to a fileFILE *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]

This topic is closed to new replies.

Advertisement