Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualgreenzone

Posted 20 October 2012 - 08:55 AM

Ok I was in you shoes not long ago. It can be incredibly hard to find the legit answer online to this parsing question. The best thing you could do is learn how to open files for reading in and out information which is purely going to be with your C++ code. I only say C++ vs some other language because that's what you just wrote you where using. Now you can learn how to do this in almost any C++ book you can find or even online in any C++ programing tutorial site. Once you understand how to open and write to and read from like .txt files you will know that you can open and read and write to a plethora of file types using the exact same methodology, whether it be .DAE .obj .ASE. these are file types often used in the parsing process often because they are the easiest read by human eyes before parsing.

You also have to understand that there are only up to like 5 things you need to be able to extract at the beginning to get your objects on the screen and that's if you want to include info to do bump mapping. SO the most important info you need is Vertex Data. So POSITION AND NORMALS is the minimum to get something to render and this is with out textures or bump mapping. If you want textures then you will read in the POSITION, NORMALS, and TextureCOORDS. If you want to do bumpMapping then you will read in POSITIONS, NORMALS, TEXTRCOORDS, AND Binormals with BiTangent information. I would just try rendering Position and Normals to start out.
Unless you want to do animations in your game that where created in 3dsmax or blender then this is all the info you need to get objects to renderd in your world. And you can then just extract the info from one of the above file formats and place them into a vector(container) of vertex structs. such as this
[source lang="java"]#define FIELD_OFFSET(StructType, field) ((GLvoid*)(offsetof(StructType, field)))struct YourVec3 { float x,y,z;};struct Vertex { YourVec3 VertsPos; YourVec3 Norms; YourVec3 Tangents; YourVec3 Bitangents; YourVec3 texCoords;};struct Face { unsigned short v[3];};class Mesh{public: Mesh(void); ~Mesh(void); std::wstring name; std::vector<Vertex> v; std::vector<Face> f; Vertex Vertz; Material *mat; // Vertex Buffer Object Names // Buffer objects are handles to OpenGL-managed memory unsigned int VBO; ///--------------------------------- Vertex VBO Name unsigned int IBO; ///--------------------------------- Index VBO Name //----------------------------------// VBO Build Function void BuildVBOs() { if (f.size()==0 || v.size()==0) return; /// VERTEX BUFFER glGenBuffers( 1, &VBO );///--------------------------- Get A Valid object Name glBindBuffer( GL_ARRAY_BUFFER, VBO );///-------------- Bind The Buffer to the target GL_ARRAY_BUFFER glBufferData( GL_ARRAY_BUFFER, v.size()*sizeof(Vertex), v.data(), GL_STATIC_DRAW );///--Loading data /// INDEX BUFFER glGenBuffers( 1, &IBO );///--------------------------- Get A Valid object Name glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);///-------- Bind The Buffer to the target GL_ELEMENT_ARRAY_BUFFER glBufferData(GL_ELEMENT_ARRAY_BUFFER, f.size()*sizeof(Face), f.data(), GL_STATIC_DRAW);///--Loading data }[/source]

[source lang="cpp"] void Render(){ if (jVBO==0) BuildVBOs(); ///-------------------------- called once at beginning to initalize the VBOs jgVertex verts; enum {ATTRIBUTE_POSITION, ATTRIBUTE_NORMAL, ATTRIBUTE_TANGENT, ATTRIBUTE_BINORMAL, ATTRIBUTE_TEXTURE, NUM_ATTRIBUTES }; glEnableVertexAttribArray( ATTRIBUTE_POSITION); glEnableVertexAttribArray( ATTRIBUTE_NORMAL); glEnableVertexAttribArray( ATTRIBUTE_TANGENT); glEnableVertexAttribArray( ATTRIBUTE_BINORMAL); glEnableVertexAttribArray( ATTRIBUTE_TEXTURE); glBindBuffer(GL_ARRAY_BUFFER, jg_VBO); glVertexAttribPointer(ATTRIBUTE_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), FIELD_OFFSET(Vertex, VertsPos)); glVertexAttribPointer(ATTRIBUTE_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), FIELD_OFFSET(Vertex, Norms)); glVertexAttribPointer(ATTRIBUTE_TANGENT, 3, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(Vertex, Tangents)); glVertexAttribPointer(ATTRIBUTE_BINORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(Vertex, Bitangents)); glVertexAttribPointer(ATTRIBUTE_TEXTURE, 2, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(Vertex, texCoords)); // bind ibo glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); // draw! if(Globals::exterior) glDrawElements(GL_TRIANGLES, 3*f.size(), GL_UNSIGNED_SHORT, 0); if(!Globals::exterior) glDrawElements(GL_LINES, 3*f.size(), GL_UNSIGNED_SHORT, 0); glDisableVertexAttribArray( ATTRIBUTE_POSITION); glDisableVertexAttribArray( ATTRIBUTE_NORMAL); glDisableVertexAttribArray( ATTRIBUTE_TANGENT); glDisableVertexAttribArray( ATTRIBUTE_BINORMAL); glDisableVertexAttribArray( ATTRIBUTE_TEXTURE); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }[/source]

This is a typical set up for reading in that geometry data into your openGL environment.



Now learn the ins and outs of FILE I/O with C++. This will help you out but you should go deeper then this tutorial.

Then Open one of the file type above such as .ASE .DAE or .obj and look at them and the way they store thier info. .ASE is by far the easiest to understand just looking at it. Here is a link to help understand the .DAE file type.

Then once you have your mind wrapped around that then you can begin writing your own parser to extract the info you need to store so you can then, Hand your stored info to openGL to render.

I like creating my own file types. So i made a small program that reads from obj or DAE and then stores the info in my own file type then i read from my smaller more efficent file type into my program. Once you fully learn file in and out you can do all kinds of cool things like that and all of this will seem less difficult to understand.

Also I agree with what was said above about libraries. just wait until you understand more before using them. but they can help ones you understand.

Hope any of that helps

#2greenzone

Posted 20 October 2012 - 08:54 AM

Ok I was in you shoes not long ago. It can be incredibly hard to find the legit answer online to this parsing question. The best thing you could do is learn how to open files for reading in and out information which is purely going to be with your C++ code. I only say C++ vs some other language because that's what you just wrote you where using. Now you can learn how to do this in almost any C++ book you can find or even online in any C++ programing tutorial site. Once you understand how to open and write to and read from like .txt files you will know that you can open and read and write to a plethora of file types using the exact same methodology, whether it be .DAE .obj .ASE. these are file types often used in the parsing process often because they are the easiest read by human eyes before parsing.

You also have to understand that there are only up to like 5 things you need to be able to extract at the beginning to get your objects on the screen and that's if you want to include info to do bump mapping. SO the most important info you need is Vertex Data. So POSITION AND NORMALS is the minimum to get something to render and this is with out textures or bump mapping. If you want textures then you will read in the POSITION, NORMALS, and TextureCOORDS. If you want to do bumpMapping then you will read in POSITIONS, NORMALS, TEXTRCOORDS, AND Binormals with BiTangent information. I would just try rendering Position and Normals to start out.
Unless you want to do animations in your game that where created in 3dsmax or blender then this is all the info you need to get objects to renderd in your world. And you can then just extract the info from one of the above file formats and place them into a vector(container) of vertex structs. such as this
[source lang="java"]#define FIELD_OFFSET(StructType, field) ((GLvoid*)(offsetof(StructType, field)))struct YourVec3 { float x,y,z;};struct Vertex { YourVec3 VertsPos; YourVec3 Norms; YourVec3 Tangents; YourVec3 Bitangents; YourVec3 texCoords;};struct Face { unsigned short v[3];};class Mesh{public: Mesh(void); ~Mesh(void); std::wstring name; std::vector<Vertex> v; std::vector<Face> f; Vertex Vertz; Material *mat; // Vertex Buffer Object Names // Buffer objects are handles to OpenGL-managed memory unsigned int VBO; ///--------------------------------- Vertex VBO Name unsigned int IBO; ///--------------------------------- Index VBO Name //----------------------------------// VBO Build Function void BuildVBOs() { if (f.size()==0 || v.size()==0) return; /// VERTEX BUFFER glGenBuffers( 1, &VBO );///--------------------------- Get A Valid object Name glBindBuffer( GL_ARRAY_BUFFER, VBO );///-------------- Bind The Buffer to the target GL_ARRAY_BUFFER glBufferData( GL_ARRAY_BUFFER, v.size()*sizeof(Vertex), v.data(), GL_STATIC_DRAW );///--Loading data /// INDEX BUFFER glGenBuffers( 1, &IBO );///--------------------------- Get A Valid object Name glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);///-------- Bind The Buffer to the target GL_ELEMENT_ARRAY_BUFFER glBufferData(GL_ELEMENT_ARRAY_BUFFER, f.size()*sizeof(Face), f.data(), GL_STATIC_DRAW);///--Loading data }[/source]

[source lang="cpp"] void Render(){ if (jg_VBO==0) BuildVBOs(); ///-------------------------- called once at beginning to initalize the VBOs jgVertex verts; enum {ATTRIBUTE_POSITION, ATTRIBUTE_NORMAL, ATTRIBUTE_TANGENT, ATTRIBUTE_BINORMAL, ATTRIBUTE_TEXTURE, NUM_ATTRIBUTES }; glEnableVertexAttribArray( ATTRIBUTE_POSITION); glEnableVertexAttribArray( ATTRIBUTE_NORMAL); glEnableVertexAttribArray( ATTRIBUTE_TANGENT); glEnableVertexAttribArray( ATTRIBUTE_BINORMAL); glEnableVertexAttribArray( ATTRIBUTE_TEXTURE); glBindBuffer(GL_ARRAY_BUFFER, jg_VBO); glVertexAttribPointer(ATTRIBUTE_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(jgVertex, VertsPos)); glVertexAttribPointer(ATTRIBUTE_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(jgVertex, Norms)); glVertexAttribPointer(ATTRIBUTE_TANGENT, 3, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(jgVertex, Tangents)); glVertexAttribPointer(ATTRIBUTE_BINORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(jgVertex, Bitangents)); glVertexAttribPointer(ATTRIBUTE_TEXTURE, 2, GL_FLOAT, GL_FALSE, sizeof(jgVertex), FIELD_OFFSET(jgVertex, texCoords)); // bind ibo glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, jg_IBO); // draw! if(Globals::exterior) glDrawElements(GL_TRIANGLES, 3*f.size(), GL_UNSIGNED_SHORT, 0); if(!Globals::exterior) glDrawElements(GL_LINES, 3*f.size(), GL_UNSIGNED_SHORT, 0); glDisableVertexAttribArray( ATTRIBUTE_POSITION); glDisableVertexAttribArray( ATTRIBUTE_NORMAL); glDisableVertexAttribArray( ATTRIBUTE_TANGENT); glDisableVertexAttribArray( ATTRIBUTE_BINORMAL); glDisableVertexAttribArray( ATTRIBUTE_TEXTURE); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }[/source]

This is a typical set up for reading in that geometry data into your openGL environment.



Now learn the ins and outs of FILE I/O with C++. This will help you out but you should go deeper then this tutorial.

Then Open one of the file type above such as .ASE .DAE or .obj and look at them and the way they store thier info. .ASE is by far the easiest to understand just looking at it. Here is a link to help understand the .DAE file type.

Then once you have your mind wrapped around that then you can begin writing your own parser to extract the info you need to store so you can then, Hand your stored info to openGL to render.

I like creating my own file types. So i made a small program that reads from obj or DAE and then stores the info in my own file type then i read from my smaller more efficent file type into my program. Once you fully learn file in and out you can do all kinds of cool things like that and all of this will seem less difficult to understand.

Also I agree with what was said above about libraries. just wait until you understand more before using them. but they can help ones you understand.

Hope any of that helps

#1greenzone

Posted 20 October 2012 - 08:50 AM

Ok I was in you shoes not long ago. It can be incredibly hard to find the legit answer online to this parsing question. The best thing you could do is learn how to open files for reading in and out information which is purely going to be with your C++ code. I only say C++ vs some other language because that's what you just wrote you where using. Now you can learn how to do this in almost any C++ book you can find or even online in any C++ programing tutorial site. Once you understand how to open and write to and read from like .txt files you will know that you can open and read and write to a plethora of file types using the exact same methodology, whether it be .DAE .obj .ASE. these are file types often used in the parsing process often because they are the easiest read by human eyes before parsing.

You also have to understand that there are only up to like 5 things you need to be able to extract at the beginning to get your objects on the screen and that's if you want to include info to do bump mapping. SO the most important info you need is Vertex Data. So POSITION AND NORMALS is the minimum to get something to render and this is with out textures or bump mapping. If you want textures then you will read in the POSITION, NORMALS, and TextureCOORDS. If you want to do bumpMapping then you will read in POSITIONS, NORMALS, TEXTRCOORDS, AND Binormals with BiTangent information. I would just try rendering Position and Normals to start out.
Unless you want to do animations in your game that where created in 3dsmax or blender then this is all the info you need to get objects to renderd in your world. And you can then just extract the info from one of the above file formats and place them into a vector(container) of vertex structs. such as this
[source lang="java"]#define FIELD_OFFSET(StructType, field) ((GLvoid*)(offsetof(StructType, field)))struct YourVec3 { float x,y,z;};struct Vertex { YourVec3 VertsPos; YourVec3 Norms; YourVec3 Tangents; YourVec3 Bitangents; YourVec3 texCoords;};struct Face { unsigned short v[3];};class Mesh{public: Mesh(void); ~Mesh(void); std::wstring name; std::vector<Vertex> v; std::vector<Face> f; Vertex Vertz; Material *mat; // Vertex Buffer Object Names // Buffer objects are handles to OpenGL-managed memory unsigned int VBO; ///--------------------------------- Vertex VBO Name unsigned int IBO; ///--------------------------------- Index VBO Name //----------------------------------// VBO Build Function void BuildVBOs() { if (f.size()==0 || v.size()==0) return; /// VERTEX BUFFER glGenBuffers( 1, &VBO );///--------------------------- Get A Valid object Name glBindBuffer( GL_ARRAY_BUFFER, VBO );///-------------- Bind The Buffer to the target GL_ARRAY_BUFFER glBufferData( GL_ARRAY_BUFFER, v.size()*sizeof(Vertex), v.data(), GL_STATIC_DRAW );///--Loading data /// INDEX BUFFER glGenBuffers( 1, &IBO );///--------------------------- Get A Valid object Name glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);///-------- Bind The Buffer to the target GL_ELEMENT_ARRAY_BUFFER glBufferData(GL_ELEMENT_ARRAY_BUFFER, f.size()*sizeof(Face), f.data(), GL_STATIC_DRAW);///--Loading data }[/source]

This is a typical set up for reading in that geometry data into your openGL environment.



Now learn the ins and outs of FILE I/O with C++. This will help you out but you should go deeper then this tutorial.

Then Open one of the file type above such as .ASE .DAE or .obj and look at them and the way they store thier info. .ASE is by far the easiest to understand just looking at it. Here is a link to help understand the .DAE file type.

Then once you have your mind wrapped around that then you can begin writing your own parser to extract the info you need to store so you can then, Hand your stored info to openGL to render.

I like creating my own file types. So i made a small program that reads from obj or DAE and then stores the info in my own file type then i read from my smaller more efficent file type into my program. Once you fully learn file in and out you can do all kinds of cool things like that and all of this will seem less difficult to understand.

Also I agree with what was said above about libraries. just wait until you understand more before using them. but they can help ones you understand.

Hope any of that helps

PARTNERS