Sign in to follow this  
pressgreen

OpenGL geometry Loader( Arrays, Vectors, or Link_lists

Recommended Posts

I am currently working on my own C++ geometry loader for OpenGL games. and i am wondering if i should use one of the following when loading geometry from a file to memory. Arrays, Vectors, or Link_lists are the methodologies I am investigating as far as pros and cons are concerned. if there is a better way or if you have knowledge on which of these would be the best that would be awesome.

thanks for your time

Green :)

Share this post


Link to post
Share on other sites
In that case, vectors are probably your best bet. Linked lists wont work well, since you will want to pass all the vertices to opengl as a chunk of memory, and linked lists are spaced out. For efficiency, it would be best to prescan your file to get a count of all the vertices, then preallocate a normal array before you read them in, but thats most likely overkill. In the end, you shouldnt be using OBJ for production, but for prototyping (and there for not efficiency heavy), its great.

Share this post


Link to post
Share on other sites
Obj files are supported by every modeller, and theyre easy to parse, so theyre good to get your game up and running with. However, theyre also limited (no animation, for instance), and much slower to parse than most other formats. So theyre good to use to get your game up and running, but once your game is past the prototyping stage, youll probably want to switch to a more complex (possibly custom) format, which would tell you in advance how many vertices it has, for instance, so you wouldnt incur the overhead of using a vector (although small) when loading them

Share this post


Link to post
Share on other sites
if I am making this geometry in 3ds max what file type do you recommend and how would i make my own file type if there are only a list of specified ones given. also when you say switch to a custom format do you mean like after i know exactly what my geometry will look like i can write something to make the game more affection with that particular amount of vertices and what not in mind? like have all of the geometry read from one large file that has all of the geometry verts and meshes and what not written to it by me?

Share this post


Link to post
Share on other sites
Sortof. There are upsides and downsides to all the different formats supported my 3ds max. WHen you make your own file type, usually the easiest thing to do would just make a converter, that would read the old file type that you had been using for prototyping, and print out only the relevant information that you need. (for example, you dont really need group names from OBJ files, so those wouldnt be included). You would basically look at your rendering code, and figure out what data was needed, and just store that so that you could easily load just that data later. Or, you could learn the 3DS Max SDK, and code a custom exporter, but that seems much more complex.

You would still store youre geometry individually, not in one giant file though. I found a very easy route was to use Assimp, which handles loading many different formats for you, and then gives you all the data, so you can render it, or output the data however you want for your custom format. Not only does it load OBJ files, but also more complex formats, like COLLADA or 3ds, etc

Share this post


Link to post
Share on other sites
every time i try to use assimp or any collada library i get build error and i spend most of my days trying to figure out what is not working with this things. i have not successfully found one the will run or an example using vs2010 and that is mainly why i am building my own loader. you would not have a simple example or know where i could find one to learn how to properly us Assimp would you?

Share this post


Link to post
Share on other sites
Im using assimp for my project with vs2010. Do you get the build error when linking with assimp, or when building assimp? Ill see if I can whip together a quick demo project

Share this post


Link to post
Share on other sites
Here you go. Ive included the assimp.lib I used, youll have to move it to your lib folder. This also requires that the assimp headers be installed in your include folder. You should just be able to copy the include folder in the assimp sdk over.

Share this post


Link to post
Share on other sites
Can you find an assimp32.dll file anywhere in the assimp sdk? If so, copy it to the folder where the exe is and/or c:\windows and c:\windows\system32

Share this post


Link to post
Share on other sites
ok i did that and it resolved that error but it just brings up a console window for a second that this shuts down. is it suppose to do more then that?

Share this post


Link to post
Share on other sites
add the line system("pause"); at the end of main(). Then it should wait for you to press enter before exiting. This program just loads the file and prints the number of vertices and faces, theres no drawing. You should be able to use the loaded aiScene file as a source of data for your renderer

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this