I am working on a 开发者_开发百科opengl project in C++. I need to write a loader to input features from a .model file. It seems fstream can not handle that. Any comment or advice? Thanks.
You're probably using fstream
wrong. If you open it in text mode, you'll get conversions that mess up your loading process. You need to open the file as binary.
std::ifstream file("something.model", std::ios::binary);
You can then read in raw data:
// read in float
float f;
file.read(&f, sizeof(f));
However you need. Be aware that types like int
or char
aren't necessarily the correct bit-width. If you want to be sure, you need fixed-width integers. Boost provides such a library.
#include <boost/cstdint.hpp>
// ...
// read a 32-bit int
boost::uint32_t i;
file.read(&i, sizeof(i));
The data in your .model file is very likely to be numbers describing the coordinates of each polygons of your model. You have to read theses numbers just like you would read data in any other kind of file, and use openGL primitives to draw the polygons of your model.
The problem is : there is many different way to represent a bunch of polygons with numbers, so your .model file is almost useless if you don't know the structure of your .model file.
精彩评论