Storing "Model" format
Oh..
Im very new to open GL. And refreshing myself in C++ which I hadnt touched much for about 6 years now..but its coming back. I acutally did it at university for 3 years...but vowed not to touch programming again (man I hated Unviersity)...funny how life comes back around on you, now I want to do it again!
anyways.........
Basically at the moment I have the openGL window up drawing models (if I explicitly enter coordinates etc). I can move around them with keyboard controls of a typical FPS game (W,A,S,D etc). Basically stuff learn from the first 10 lessons)
Next is the reading in .obj
I think I'll begin with reading in the models as arrays of faces, faces arrays of vertices, first then go from there. Not scalable and probably inefficient but its a start.
I dont have a grand plan of building any fancy 3d engine (well maybe I do...but its not realistic for me yet), I basically want to begin with
- Creating the openGL interface (done)
- Creating movement controls (half done. have keyboard working but not mouse controls yet)
- import an obj (next on the list)
- assign a texture
and so on slowly.
So regarding the model structure and reading posts above I could use:
arrays
dynamic arrays
sets
vertex buffers.
I think I'll begin with arrays to get my reading in files working then look at this vertex buffering.
Ive found interesting threads about it:
http://www.devmaster.net/forums/lofiversion/index.php?t360.html
http://steinsoft.net/index.php?site=Programming/Code%20Snippets/OpenGL/no11
So yeah, thanks for everyones help thus far. I'll freely admit Im at the bottom and learning. I like learning by jumping in and trying things....just seems openGL was a BIG jump.
Thanks again
-------------------LordsWarrior-------------------
Quote:
I like learning by jumping in and trying things....just seems openGL was a BIG jump.
That's actually a really good way to learn. Read, play, ask questions. And yeah, learning a graphical API can seem daunting at first. Really you just pick a topic, learn it, apply it, and then move on to the next. After a while, you relize you know a whole hell of a lot. A short while after that you realize there's a whole hell of a lot more you don't know. The fun part is getting the two to meet [smile]
Quote:
So regarding the model structure and reading posts above I could use:
arrays
dynamic arrays
sets
vertex buffers.
I think I'll begin with arrays to get my reading in files working then look at this vertex buffering.
That's a good start. You'll probably want to use dynamic arrays to start (there's no reason to use a regular array). Once you get it up and running, go to vertex arrays. Going from a vertex array to a vertex buffer object is trivial (once you get past all the little oversights).
Vertex arrays are easy and quick to do. The best resource I can recommend is the redbook. I learned them from the 1.2 version. I'm sure the 1.1 covers them almost the same. It really does a good job.
If it seems like this stuff is over your head, it just might be. I would actually take a break from the model loader and create your own models in OpenGL. Do it intelligently, though. You could specify every vertex in a cube, but it's a ton easier to write a square function and call that 6 times using different translations and rotations. Then you have a cube function and you can use that cube function in more complex shapes.
You always want to be working with objects that are centered at the origin. That way when you rotate it, it's rotated about the object's center and not one of it's sides.
The other nice part about breaking things up like this is it allows you to make display lists for the objects. Nehe can teach you all about that.
Oh and texturing is trivial, once you get the basic idea down. If you can texture a cube and then a sphere, you're good to go.
Good luck!
Without order nothing can exist - without chaos nothing can evolve.
Thanks
Dynamic arrays it is then...
-LW
Dynamic arrays it is then...
-LW
-------------------LordsWarrior-------------------
Hey
I was just rethinkin this
Most model foramt examples Iv eseen are something like
struct vertex {
double x,y,z,
}
struct vertex {
double x,y,z,
}
struct model{
triangel faces[maxFaces] //
}
ok..
IM thinking wouldnt this be better:
struct vertex {
double x,y,z,
}
struct face {
int a,b,c, // indexes to the 3 vertices they use
}
struct model{
triangles faces[maxFaces] //
vertex vertices[maxverts]
}
IN this way..a face stores the index of the 3 vertices it uses that are stored in vertex array. This was you dont get over lapping in vertices by storing 3 vertices per triangle. For example in 4 sided pyramid there are 4 vertices (one point and 3 at the bottom). If you store them in the first method you end up storing 12 vertices as each face stores the vertex locations of its 3 corners (4 faces * 3 verts = 12 vertices stored...)
The 2nd code stores the 4 vertices in an array and 4 faces to index them.
Isnt that more memory efficient?
I havent got to vertex buffering yet LOL
-LW
I was just rethinkin this
Most model foramt examples Iv eseen are something like
struct vertex {
double x,y,z,
}
struct vertex {
double x,y,z,
}
struct model{
triangel faces[maxFaces] //
}
ok..
IM thinking wouldnt this be better:
struct vertex {
double x,y,z,
}
struct face {
int a,b,c, // indexes to the 3 vertices they use
}
struct model{
triangles faces[maxFaces] //
vertex vertices[maxverts]
}
IN this way..a face stores the index of the 3 vertices it uses that are stored in vertex array. This was you dont get over lapping in vertices by storing 3 vertices per triangle. For example in 4 sided pyramid there are 4 vertices (one point and 3 at the bottom). If you store them in the first method you end up storing 12 vertices as each face stores the vertex locations of its 3 corners (4 faces * 3 verts = 12 vertices stored...)
The 2nd code stores the 4 vertices in an array and 4 faces to index them.
Isnt that more memory efficient?
I havent got to vertex buffering yet LOL
-LW
-------------------LordsWarrior-------------------
Quote:
struct vertex {
double x,y,z,
}
struct face {
int a,b,c, // indexes to the 3 vertices they use
}
struct model{
triangles faces[maxFaces] //
vertex vertices[maxverts]
}
yes, this is more efficient and is how most model formats are stored. Using floats instead of doubles will save quite a bit of memory though. Also bear in mind that vertex array formats use slightly different indexing.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement