I've seen people saying it's better and faster to use a custom binary format for your 3D models, based on your needs, instead of using exchange formats. But, I'd like to know how to create a basic format, that contains just vertex and index data, how to write this data into a binary file and read it. Much obliged.
What you ultimately end up using at runtime is going to be processed version of your exchange formats whether you do it offline or at runtime. The main differences are:
I'm not sure what your use case is but I assume you'll be putting the data into either a D3D or OpenGL set of index/vertex buffers. It sounds like you're already familiar with what an index/vertex buffer is, so I think the part you might be missing is what D3D calls the vertex declaration.
OpenGL does the same thing but I find it less well defined conceptually. You'll want to take a look at the OpenGL wiki for Vertex Specification paying particular attention to glVertexAttribPointer.
Anyway, the vertex declaration specifies in the type of each component and where it occurs in a vertex. For example, a vertex declaration could look something like:
Given this vertex declaration, you would then proceed to write out your vertex buffer using this description. I generally tend to just match it with a straight C structure:
Create an array for all the vertices, populate them as appropriate and dump that and the vertex description to a file.
On the runtime side, you'll then load your data into memory, and then make the appropriate calls to D3D/OpenGL to say "my vertex format is this" and construct your vertex buffer by passing a pointer to your data array.
Index buffers are basically identical except you just specify the size of each index (8 bit, 16 bit, etc.).
It gets slightly more complicated if you want to have different vertex buffers supplying different streams of data, but I hope that's good enough to help you understand the general idea.
I've implemented such offline format near month ago for my engine. The basic algorithm is:
Do not forget to add support for vertex data compression, triangle strips, multiple files export.
Just simple vertex coords and index data export is insufficient to render. You need more data. As much as can be extracted from 3D editor. Moreover this data should take as little GPU memory space as possible.
The main disadvantage of such scheme that step 3 is difficult to transfer to other computer, to get final binary pack you should always rebuild conversion project using custom script. But it gives your much more possibilities to work with data using many existing C++ libraries, but not a poorly developed editor script languages.