glut issues

Hi,

Typically when using glut, one will create a window, set callbacks, and then call glutMainLoop(). (As far as I understand the specs.)

But how am I supposed to perform initialization (shader, …) without global/static variables?

I just don’t get the system behind this, hope you can help me here.

And what forbids you to use global/static variables ?
Abusing globals is bad practice, but a few pointers to the actual data of your scene should be ok.

Some programming teachers tell their students to never, ever use a single global variable. That is, IMHO, a typical case of “those who can, do, those who can’t, teach”. Do these people ever write real programs? Don’t listen to such nonsense. CSc puritans will just make things harder.

With no globals, you have to pass all data as function parameters. Does that sound efficient? But you can do it like this:

  • Pack global data in records/objects, one global record for all globals of a certain kind. This makes it easier to see that you are accessing a global.
  • Mark global variables as such. I use a “g” prefix.
  • You can use getter/setter functions to access sensitive globals, so you can insert breakpoints to see when they are used.
  • Use “local globals”, static variables “global” within a single unit.

Also, start by hacking your code to work. Make it messy, break any rules you want. Then you clean it up, consider what variables need to be global and which ones to pass as parameters, how to repackage and optimize, and document. Rewrite to a final version once you know how to do it. Writing the code “perfect” according to some academic ideal at the first round is premature optimization.

LOL, I didn’t expect this. So to summarize: GLUT just has a horrible design. I’ll go use something else, thanks.

GLUT is designed for little test/demo programs. It’s great for that. For most serious apps, you quickly grow beyond it.