Archived

This topic is now archived and is closed to further replies.

tilex

Multiple objects

Recommended Posts

tilex    122
Hi everyone, I''m newb to openGL and I found out that awesome tutorial ( yeah no jokes ) but I wanted to know that: in games like RTCW or MOH (return to castle wolfenstein and medal of honor) there''s often a lot of crates, boxes etc... How do they do that... they can''t just write a million times glBegin ( GL_QUADS ) .... if they have a million boxes, so how is it possible to do that without writing about 11 millions lines of codes only for those boxes ( 1,000,000 is big I know but it''s an exemple, even 10 boxes would be pretty long ) Thanks for every reply

Share this post


Link to post
Share on other sites
skow    248
Don''t stop reading the new tutorials, alot of that is explained. There are many things that can be used: display lists, vertex arrays, vertex buffer objects.

Share this post


Link to post
Share on other sites
hplus0603    11347
I think what's important is not the realization that you can submit data as geometry arrays (which is a good way to submit data) but the fact that you can read the data to submit from a file.

At its easiest, you could think of a mesh file on disk as containing lists of coordinates, and read it like so:



FILE * f = fopen( "file.mesh", "rb" );
glBegin( GL_TRIANGLES );
while( fscanf( f, "%f,%f,%f", &vert[0], &vert[1], &vert[2] ) ) {
glVertex3fv( vert );
}
glEnd();
fclose( f );



Now, this would clearly have terrible performance, but it would have the right idea: data comes from files on disk, data should NOT be hard-coded into the program.

To make if efficient, pre-process the files on disk into a binary format, and read in an entire vertex array in one swell foop; then issue the entire array using glDrawRangeElements().

Edit: and, clearly, you'd load this data ONCE on level load, not each time you needed to draw the mesh :-)

[edited by - hplus0603 on January 6, 2004 7:09:05 PM]

Share this post


Link to post
Share on other sites
MessageBox    109
1. Load in one box mesh at the start of the level.
2. Load in the locations of all the boxes for the level.

3. During rendering -->
for (int i = 0; i < numBoxes; ++i)
{
DrawBox();
}


There''s a bit more to it than that but that''s the basics of it.
You only have to create/load the actual box mesh once and then redraw it many times, in different locations.

Share this post


Link to post
Share on other sites