sending referance parameters to RenderScene()?

is it possible to pass parameters by referance to void RenderScene(), for example void RenderScene(int numobjects, int some_array)? any information would be helpful.

It depends on what RenderScene is… if you are using Glut and passing RenderScene as the display call-back then, no you can’t. Callback functions have to be of a specific prototype. If you are not using it as a callback, then of course it is. Get a good book on C/C++, you’re going to need it if you are serious about programming OpenGL. It isn’t wise to start jumping into OpenGL before you understand the language you are working with.

As to your question…

From the prototype you gave it sounds like you want to pass an array. Arrays are always passed by pointer in C/C++.

void RenderScene(int numObjects, int some_array[]); // you forgot the [] in yours

is equivalent to
void RenderScene(int numObjects, int* some_array);

For both of the above you would do something like so

int blah[256];

RenderScene(256, blah);

Passing by reference is different from passing by pointer. As I said before, get a good C/C++ book. It’ll help you out a lot in the long run.

hello,

I agree with the second poster. But, just returning to the premise that the original author wants to attach this render() function as a callback to glut, if you will. You can “pass” the info you want as global variables.

so, suppose you want to REALLY do this:

void render(int n, int *narray)
{
}

...

glutDrawFunction(render);

then, you can’t. neh. but what you can do is something like this:

static struct _global {
  int n;
  int *narray;
} state;

void render(void) /* conforms to glut spec */
{
}

glutDrawFunc(render); /* this works */

and then you can set the state as appropriate in your idle function (for example) and the next time render() func is called, it’ll have access to the “new” data.

The advantages of this are: it works. kinda. well, you can ‘pass’ your parameters.
the disadvantages are: (1) global variables are… well… they’re global, and C scope rules suck =) (this isn’t really much of a disadvantage, but i thought i’d throw it in=), and (2) you can’t change the parameters per call to draw, since draw() func may be called several times before the idle func is called. this may not be such a disadvantage, either. but it depends on what you want to do.

hope this helps!

cheers,
John

[This message has been edited by john (edited 04-17-2001).]