How to load 3D models in OpenGL C++?
17,941
OpenGL doesn't do this for you. You should write your own parser, store the readed datas into your defined data structures and use OpenGL primitives to render them.
Here's a nice tutorial.
Author by
CppOgl
Updated on June 20, 2022Comments
-
CppOgl almost 2 years
I am trying to load 3D models. How do I to read the data in the model file?
For an example, this is the data:
VERTICES 80 21 32 32 34 17 14 93 56 33 54 87 MODEL_SCALE 5
I know the data in 3D models is not like this, but how will I read the 'vertex data' and the 'model scale amount'?
-
CppOgl over 12 yearsYes but how will I read the data? What I want to do is read the data of the file and draw vertices on them.
-
user786653 over 12 yearsIt looks like milkshape is a binary format, which I'm not sure is applicable for OP as it looks like he's showing an example of a text format.
-
CppOgl over 12 yearsHmm... seems quite helpful. But there is a way reading words with string.h and other stuff like that, right? I'll try to use that too. Anyway, thanks!
-
datenwolf over 12 years@CppOgl: FILE *filp = fopen(filename, "r"); fread(...), etc. Or in C++ using ifstream. This not an OpenGL question then, but a generic "how do I read a file" question.
-
Heisenbug over 12 years@user786653 : yes you are right. But like datenwolf pointed out, this is not an opengl question. The linked tutorial illustrate some basic operation and datastrutctures that one usually use while loading a model to be rendered with openGL primitives.
-
CppOgl over 12 yearsActually, NeHe's tutorials are not always useful which is why I'm a bit stuck on loading external models. Otherwise, Nehe's site comes on the first page when searched in google.
-
Heisenbug over 12 years@CppOgl: When I was studying openGL nehe's tutorial have been very useful to me. But I think what you have problem with seems not related to opengl, but to file parsing.
-
CppOgl over 12 yearsCould be. I have seen many model loading tutorials but most of them are never helpful
-
user786653 over 12 years@0verbose: It wasn't meant as a criticism of your post, the OP is extremely vague, so I was just pointing out that perhaps the OP was looking for something more like this. (Not tested, found by googling "asc opengl" where asc was just the first text 3d model format I could think of).
-
Heisenbug over 12 years@user786653 : don't worry. no problem. even the criticism are always well accepted. I think that everyone of us should be here to improve his knowledge.