Sign in to follow this  
ronkelly

array of display lists

Recommended Posts

ronkelly    122
Hi all, I need to create an array of display lists for a program I am writing, but only the first object is displayed with the following code. Is the code wrong or can I not make an array of display lists?? Thanks, Ron. GLuint object_list[MAXFEATURES] ; ..... //initialisation for ( i = 0 ; i < MAXFEATURES ; i++ ) { object_list[i] = glGenLists(1) ; } ..... //create lists for ( i = 0 ; i < MAXFEATURES ; i++ ) { glNewList( object_list[i], GL_COMPILE ) ; ...... glEndList() ; } ...... for ( i = 0 ; i < MAXFEATURES ; i++ ) { ..... glCallList( object_list[i] ) ; }

Share this post


Link to post
Share on other sites
Solias    564
Seems like that should work. Check that gen lists isn't returning 0 and check for error values on new/end list. I assume you are transforming the objects to different locations, make sure that code is right or it could be drawing them all in the same place, or perhaps the others are off camera.

Share this post


Link to post
Share on other sites
kburkhart84    3182
I've done it like that before and it works fine as long as you draw different things at different spots or even the same thing at different spots(which would be an obvious waste.) Check and make sure you DO translate before each glCallList.

Share this post


Link to post
Share on other sites
silvermace    634
hi, your code looks ok, so it would be more helpfull to see your actual code.

PS, this is how i would implement your idea using DL's (you dont seem to be aware of the range feature of glGenLists, this should eleminate 2 of those loops.)


// assuming you're programming in C not C++
GLuint start = 0;
GLuint object_list[ MAXFEATURES ];
GLfloat obj_xpos[ MAXFEATURES ]; // fill these appropriately
GLfloat obj_ypos[ MAXFEATURES ];
GLfloat obj_zpos[ MAXFEATURES ];

int init( void )
{
start = glGenLists( MAXFEATURES );
if( start == 0 ) return -1;

for( GLuint i=0; i<MAXFEATURES; i++ ) {
object_list[i] = start + i;
glNewList( object_list[i], GL_COMPILE );
glPushMatrix();
glTranslatef( obj_xpos[i], obj_ypos[i], obj_zpos[i] );
// render stuff
glPopMatrix();
glEndList();
}
return 1;
}

int render()
{
// gl provides this functionality, so use it :-)
glCallLists( MAXFEATURES, GL_UNSIGNED_INT, (const GLvoid*)object_list );

if( glGetError() != GL_NO_ERROR )
return -1;
return 1;
}




WARNING: this is off the top of my head, errors and ommissions excepted!! [smile]

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