Jump to content
  • Advertisement

Archived

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

Keermalec

Please help me simplify this code

This topic is 6110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, this problem is driving me crazy, and it keeps cropping up again all the time. I would like to simplify the following: ---------start----------- void function ( void ) { glCallList ( list0 ); glCallList ( list1 ); glCallList ( list2 ); glCallList ( list3 ); glCallList ( list4 ); } ---------end----------- To something like this: ---------start----------- void function ( int num ) { for ( int i = 0; i < num; i++ ) glCallList ( list"i" ); } ---------end----------- I know there must be a simple C++ trick for this but I cant find it. Thanks for your help.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
void glCallLists(GLsizei n, GLenum type, const GLvoid * lists);
=]
Try looking this one up, it simply calls all the lists in the array passed as the lists parameter.
Hope this helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks, I didnt know even know that function existed. I will certainly use it. My question had a wider scope, however. What I want to be able to do its not necessarilly call several display lists at once, but write out commands that have been compiled as strings. For example, instead of:

glCallList ( list0 );
glCallList ( list1 );
glCallList ( list2 );
glCallList ( list3 );
glCallList ( list4 );

to write someting like:

for ( int j = 0; j < 5; j++ ) glCallList ( "list%i", j );

With emphasis on that last "%i" part. How can I replace a part of a command using string-type functions?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oh I took list0 etc just to be your variable names not actuall strings.
Well I still think the best thing to be would be to make an array.
Otherwise I guess you''d prolly have to do some super pre-processor stuff that I wouldnt have a clue about =]
Umm I cant really help you then sorry.

Share this post


Link to post
Share on other sites
I knpow its out there somewhere because I saw it once, but its difficult searching for something when you don't know what its called. What I want to do looks somthing like this, except that the printf function would print out to my code instead of to the screen:

for ( int j = 0; j < 5; j++ )
{
printf ( "glCallList ( list%i );", j );
}


Edited by - Keermalec on December 28, 2001 11:31:48 AM

Share this post


Link to post
Share on other sites
char List[5][5] = {"list0","list1","list2", "list3", "list4"}

for (int i = 0; i < 5; i ++) glCallList ( List );



I''ve not tried the code but tell me if it''s work.



========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/

Share this post


Link to post
Share on other sites
Sorry, I''ve made a mistake :

for (int i = 0; i < 5; i ++) glCallList ( List );





========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/

Share this post


Link to post
Share on other sites
Keermalec: I don''t think you can do what you want to do because C/C++ is a compiled language. I believe that would stop you from being able to do what your talking about. If you put those variables in an array then you could do it easily.

Example instead of the following variables:
list0,list1,list2,list3,list4 you had an array like

List[5]. Then you could just do:


for(int i = 0;i < 5;i++)
{
glCallList(list);
}
[CODE]

That void glCallLists(GLsizei n, GLenum type, const GLvoid * lists); function seems to let you do the same thing but I don''t use OpenGL so I don''t know...


Jesus Freak,
Jesus Loves you. He is the Alpha and Omega the Beginning and the End.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!