Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 rubsnick   Members   -  Reputation: 106

Like
0Likes
Like

Posted 03 May 2011 - 11:26 AM

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.

Sponsor:

#2 karwosts   Members   -  Reputation: 840

Like
1Likes
Like

Posted 03 May 2011 - 11:30 AM

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.
My Projects:
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game

#3 rubsnick   Members   -  Reputation: 106

Like
0Likes
Like

Posted 03 May 2011 - 11:48 AM

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?

#4 KulSeran   Members   -  Reputation: 2587

Like
0Likes
Like

Posted 03 May 2011 - 12:21 PM

You could try using Assimp.

#5 karwosts   Members   -  Reputation: 840

Like
0Likes
Like

Posted 03 May 2011 - 12:33 PM

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.
My Projects:
Portfolio Map for Android - Free Visual Portfolio Tracker
Electron Flux for Android - Free Puzzle/Logic Game

#6 Monkan   Members   -  Reputation: 643

Like
0Likes
Like

Posted 03 May 2011 - 12:35 PM

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, 03 May 2011 - 12:36 PM.

"To know the road ahead, ask those coming back."

#7 rubsnick   Members   -  Reputation: 106

Like
-2Likes
Like

Posted 04 May 2011 - 01:43 PM

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....

#8 marcDion1974   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 May 2011 - 03:36 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS