Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: glut issues

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2011
    Location
    Germany
    Posts
    10

    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.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,580

    Re: glut issues

    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.

  3. #3
    Intern Newbie
    Join Date
    Jan 2010
    Location
    Linköping, Sweden
    Posts
    46

    Re: glut issues

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2011
    Location
    Germany
    Posts
    10

    Re: glut issues

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

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,126

    Re: glut issues

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •