1

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.

2
  • 2
    Can you provide more info as to the .model file format and why you think fstream cannot handle it? Commented Jan 23, 2010 at 8:24
  • As so often, trying to boil it down to a simple, minimal test-case that show-cases the problem would be helpful. Commented Jan 23, 2010 at 8:38

2 Answers 2

4

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));
Sign up to request clarification or add additional context in comments.

2 Comments

Sigh ... in fact, I forgot to put the flag for glut. Sorry guys, I guess fstream handles the situation well now. Thank you guys.
@small_potato: No problem. Go ahead and post your solution as the answer and accept it, so the question is finished.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.