Please help me simplify this code
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.
December 28, 2001 09:24 AM
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.
=]
Try looking this one up, it simply calls all the lists in the array passed as the lists parameter.
Hope this helps.
December 28, 2001 10:02 AM
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?
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?
December 28, 2001 10:08 AM
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.
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.
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
for ( int j = 0; j < 5; j++ )
{
printf ( "glCallList ( list%i );", j );
}
Edited by - Keermalec on December 28, 2001 11:31:48 AM
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/
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/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Sorry, I''ve made a mistake :
for (int i = 0; i < 5; i ++) glCallList ( List );
========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
for (int i = 0; i < 5; i ++) glCallList ( List );
========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
The forum doesn''t accepted ""List""
========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
I''ve tested and it''s doesn''t work. Sorry
========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
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:
Jesus Freak,
Jesus Loves you. He is the Alpha and Omega the Beginning and the End.
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);}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.
Jesus Freak,Jesus Loves you. He is the Alpha and Omega the Beginning and the End.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement