View Full Version : glut issues

04-05-2012, 10:03 AM

Typically when using glut, one will create a window, set callbacks, and then call glutMainLoop(). (As far as I understand the specs (http://www.opengl.org/resources/libraries/glut/spec3/spec3.html).)

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.

04-06-2012, 12:57 AM
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.

04-08-2012, 03:26 AM
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.

04-09-2012, 10:22 AM
LOL, I didn't expect this. So to summarize: GLUT just has a horrible design. I'll go use something else, thanks.

Dark Photon
04-10-2012, 06:42 AM
GLUT is designed for little test/demo programs. It's great for that. For most serious apps, you quickly grow beyond it.