Tutorial :OpenGL: Fire event on new geometry creation



Question:

In specific I am working in linux environment. This is an opengl application. Upon a calculation of certain geometries, I want to be able to fire an event whenever a new geometry is created. Is there any .NET equivalent of events in C ??

Thanks, Vishnu


Solution:1

With gnome libraries or gtk+ (which is built on top of it)? You can do it all yourself with function pointers, but this is the only "standard" C library that I've personally used that standardized events and callbacks. There's probably others out there, too.


Solution:2

Events in C are implemented using function callbacks. The linked question has a couple answers that address how to code callbacks.


Solution:3

To translate from .NET land:

An "event" is simply the calling of a function. To make this configurable, you need to give the thing that generates the "event" a function pointer. The function pointer is called, and is the thing that is "done" when the "event" occurs.

A thing to "do" is a function in C and C++.

If you only want to "do" one thing upon an "event". You'd pass in a pointer to your function, which is the thing you want to "do" upon your "event" as a function pointer to the thing that causes the "event." This is called a callback. Other posts have lots of examples on how this works.

If you need to "do" multiple things on an "event", you'll need to use a signal/slot implementation like boost::signal. Or if OpenGL has something similar, I'd use that. In that case, you have multiple callbacks.


Solution:4

Though I can't say I'd really recommend using them, a possible alternative to callbacks would be signals.

You can use signal to say how a particular signal should be handled, and raise to send a particular signal. Note, however, that there are serious restrictions on what you can do in a signal handler. Lots of code isn't really written to deal well with signals, and quite a bit of it assumes that almost any signal implies such a serious problem that continued execution after a signal may be problematic.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »