Jump to content
  • Advertisement
Sign in to follow this  
rubsnick

OpenGL I need to learn how to load a mesh in OpenGL...

This topic is 2681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to learn how to load a mesh into opengl I'm currently using FreeGlut. Problem is I don't know what file format or how to start to do this. I know it's most likely a function within the api and this is probably really simple but well... I need help. I've found several files for meshes but they have all different extensions.. apprently they are all models.... there is a.wrl and the .3ds.... are both valid? could I use either one or what? any tips would be apreicated.

Share this post


Link to post
Share on other sites
Advertisement
There are no opengl api functions related to loading models. Opengl simply accepts lists of triangles and lists of vertices. Transforming data formatted in certain filetypes to these lists is the responsibility of the user.

However even though it is not part of the OpenGL API, there are many libraries out there that will assist with loading one type or another, such as Assimp. Or you can write the interpreter yourself. OBJ is a common format to use for beginners as it is pretty simple. But basically you can use any format, but you must parse it into arrays of vertices for OpenGL to understand.

Share this post


Link to post
Share on other sites

There are no opengl api functions related to loading models. Opengl simply accepts lists of triangles and lists of vertices. Transforming data formatted in certain filetypes to these lists is the responsibility of the user.

However even though it is not part of the OpenGL API, there are many libraries out there that will assist with loading one type or another, such as Assimp. Or you can write the interpreter yourself. OBJ is a common format to use for beginners as it is pretty simple. But basically you can use any format, but you must parse it into arrays of vertices for OpenGL to understand.


Oh thanks... I found this code http://openglsamples.sourceforge.net/files/glut_obj.cpp

Thing is it says it needs they need to be triangulated.... With is that? BTW If I use that I can simply create taht into a whole function and just call it whenever needed correct?

Share this post


Link to post
Share on other sites
Triangulated means that the model cannot contain any quads. OBJ faces can have 3 or 4 (or more?) vertices per face. Triangulated means that everything is broken up into triangles.

Share this post


Link to post
Share on other sites
Hi,

When I first tried looking into ASSIMP I was pretty noobish and it was all a bit much for me to take in and took a while to get it working but then again it does take me a while to figure things out in general.

Anyway you might want to look into this:
http://www.3dcodingt...etting-GLM.html


Its called GLM and is used to load .obj models. I haven't had a chance to have a proper look yet but it looks pretty simple and a lot lighter than ASSIMP which does pretty much everything.


EDIT: Beat me to it.......
.
As for triangulated meshes, its pretty standard and can be done with the simple click of a button in most modelling programs e.g. Maya.It just means that the mesh consists only of triangles but it all depends what the model loader is set-up to work with. In that tutorial the model loader is only set up for triangulated meshes as it accepts 3 vertices for each face so if there are any faces with more than 3 vertices it will cause an error or draw weird.

Good luck. Edited by Monkan

Share this post


Link to post
Share on other sites

Hi,

When I first tried looking into ASSIMP I was pretty noobish and it was all a bit much for me to take in and took a while to get it working but then again it does take me a while to figure things out in general.

Anyway you might want to look into this:
http://www.3dcodingt...etting-GLM.html


Its called GLM and is used to load .obj models. I haven't had a chance to have a proper look yet but it looks pretty simple and a lot lighter than ASSIMP which does pretty much everything.


EDIT: Beat me to it.......
.
As for triangulated meshes, its pretty standard and can be done with the simple click of a button in most modelling programs e.g. Maya.It just means that the mesh consists only of triangles but it all depends what the model loader is set-up to work with. In that tutorial the model loader is only set up for triangulated meshes as it accepts 3 vertices for each face so if there are any faces with more than 3 vertices it will cause an error or draw weird.

Good luck.


Ah alright well how do I triangulate the file? I downloaded maya 2012 I just want to triangulate the thing....

Share this post


Link to post
Share on other sites
Find yourself a model loader, I use 3DS, it could be .LWO, or .OBJ or whatever you want.........

(i)Add ->>> #include <fstream.h> at the beginning of your program


Next find the draw calls-->>>
//----------------------------------------------------------------------------------------
glBegin(GL_TRIANGLES);
glVertex3f( pointerX[0], pointerY[0], pointerZ[0]);
glVertex3f( pointerX[1], pointerY[1], pointerZ[1]);
glVertex3f( pointerX[2], pointerY[2], pointerZ[2]);
glEnd();
//----------------------------------------------------------------------------------------

Add something like the following to have this model loading program spit out vertex arrays which openGL loves.

//----------------------------------------------------------------------------------------
ofstream out("modelNameVertexArray.cpp"); //_THIS WILL CREATE A TEXT FILE WITH THE SPECIFIED NAME
//-------------------------------------------------------------------------------------

glBegin(GL_TRIANGLES);
//-------------------------------------------------------------------------------------
glVertex3f( pointerX[0], pointerY[0], pointerZ[0]);
out << pointerX[0] << pointerY[0] << pointeZ[0]<<",/n" // THESE OUTPUT LINES WILL CREATE A LINE OF CODE IN THE TEXT FILE FOR EVERY DRAW CALL.
//------------------------------------
glVertex3f( pointerX[1], pointerY[1], pointerZ[1]);
out << pointerX[1] << pointerY[1] << pointeZ[1] << ",/n"
//------------------------------------
glVertex3f( pointerX[2], pointerY[2], pointerZ[2]);
out << pointerX[2] << pointerY[2] << pointeZ[2] << ",/n"
//-----------------------------------------------------------------------
glEnd();

//--------------------------------------------------------------------------------------------------------------
Once you have the output file use #include "modelNameVertexArray.cpp" to include the vertex data
then use something like glDrawArrays(,,); to render the model.

I havn't posted the source code for this yet but I'll e-mail you a copy ->>darthidious@gmail.com

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!