Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing variable to function registered with glutDisplayFunc()

447 views
Skip to first unread message

Vijay

unread,
Apr 13, 2002, 4:13:08 PM4/13/02
to
Hi All,
I want to pass a variable to the function registered with
glutDisplayFunc(), for e.g DrawGLScene in
glutDisplayFunc(&DrawGLScene). I dont want to make the variable
global. Any ideas ?

Thanks in advance,
Vijay

Mehdi Berrada

unread,
Apr 14, 2002, 6:18:46 AM4/14/02
to
Not sure of what you want to do but :

void MyDisplayFunc(int Myarg)
{
...

glutSwap...
}

void display()
{
MyDisplayFunc(MyArg);
}

glutDisplayFunc(display);

is it what you want ?

"Vijay" <vde...@me.iitb.ac.in> wrote in message
news:b0119feb.02041...@posting.google.com...

dr karron

unread,
Apr 14, 2002, 1:07:47 AM4/14/02
to
Make a global pointer with context info for your display.
One variable, lots of context.

Else you have to load a context var in glut and pass it.

I think you are objecting to having lots of global/static vars clutting up
your name space.
You can do it cleanly with a single static pointer you load with the context
frame for when you run display.
You can clear the pointer to refresh your context when you start building
your scene before your display,
or build it while you display...

dB

"Mehdi Berrada" <mehd...@wanadoo.fr> wrote in message
news:a9aoua$he$1...@wanadoo.fr...

Vijay

unread,
Apr 14, 2002, 1:24:43 AM4/14/02
to
Actually I want to do something like that. but the variable Myarg
which is being passed to MydisplayFunc belongs to function main. So it
cannot be done the way you have suggested. Any other way ?


"Mehdi Berrada" <mehd...@wanadoo.fr> wrote in message news:<a9aoua$he$1...@wanadoo.fr>...

Greg Fruth

unread,
Apr 15, 2002, 12:57:34 PM4/15/02
to
vde...@me.iitb.ac.in (Vijay) wrote in message news:<b0119feb.02041...@posting.google.com>...

> Actually I want to do something like that. but the variable Myarg
> which is being passed to MydisplayFunc belongs to function main. So it
> cannot be done the way you have suggested. Any other way ?
>

If you really are desperate to avoid global variables,
perhaps you can modify GLUT to do what you want. The
source code is readily available.

You could also use some form of IPC to communicate from
your main() to your display function (shared memory, a
socket, etc.) Seems like a lot of trouble for little
gain, however.

HTH

Geoffrey Egnal

unread,
Apr 15, 2002, 4:45:48 PM4/15/02
to
Maybe use glutMaster (or any other object oriented glut system), and
put the global variable in an object. Not sure if this solves your
problem.


Vijay (vde...@me.iitb.ac.in) wrote:
: Hi All,

: Thanks in advance,
: Vijay

--
Geoff

Jens Olav Nygaard

unread,
Apr 15, 2002, 5:26:42 PM4/15/02
to

> Vijay (vde...@me.iitb.ac.in) wrote:
> : Hi All,
> : I want to pass a variable to the function registered with
> : glutDisplayFunc(), for e.g DrawGLScene in
> : glutDisplayFunc(&DrawGLScene). I dont want to make the variable
> : global. Any ideas ?
>
> : Thanks in advance,
> : Vijay

And how do you want to pass the value through this
parameter to the function? I mean, from where?
Are you really sure this is what you want?

J.O.


--
Jens Olav Nygaard, Research Scientist
SINTEF Applied Mathematics, Geometric Modelling

Jens Olav Nygaard

unread,
Apr 15, 2002, 5:28:24 PM4/15/02
to
oops, didn't realize there were plenty of good
responses to this already...
0 new messages