What is it with OpenGL tutorials?

This is a discussion on What is it with OpenGL tutorials? within the Game Programming forums, part of the General Programming Boards category; Every single OpenGL tutorial i've come across is SATURATED with global variables. It's disgusting. I can't learn from that garbage. ...

  1. #1
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    What is it with OpenGL tutorials?

    Every single OpenGL tutorial i've come across is SATURATED with global variables. It's disgusting. I can't learn from that garbage. Ugh. Ick.

    I shouldn't have to sign away the good programming principles i've learned just so I can learn OpenGL.

    I downloaded a basic tutorial which setup an OpenGL window and drew a triangle...
    It had SEVEN global variables.

    I quickly elminated four of them by adding some parameters to functions and using some standard Win32 API calls.

    I'm going to wrap initializing OpenGL in a nice flexable class so I never have to deal with this garbage again.

    Before I'll be able to do anything I know i'm going to want to wrap everything into a neat little package. Down with C! Up with C++!

    PLUS I have a very big hunk of garbage on my shelf called "OpenGL Superbible"
    Worst. Book. Ever.

    It's almost like once OpenGL is introduced, you can forget everything about design and structure and just hack new modules on until the cows come home.

    /rant
    Last edited by Eibro; 06-28-2003 at 02:33 PM.

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    http://nehe.gamedev.net/opengl1.asp

    this site is very good.

    /*edit: whats so bad about GV's anyway?*/

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I don't see any need for a global HWND or HINSTANCE variable.

    Anywhere you need the hInstance of the process (not very often), you can call GetModuleHandle()

    And i've never needed to make the window handle (hWnd) a global. Messages are handled in the callback, almost all interaction takes place in the callback, and the first parameter is your hWnd...

    There are others, but i'll leave it at that.

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    the program u helped me with has

    g_hDC as a global, and its used in a function to hold the value of the hDC variable so that when hDC is alterd the DC it had before was stored in another variable, but i see no reason why it couldn't have been declared in the function.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    The reason why they use globals is to make it a bit easyer to
    focues on the the real thing, opengl. You can always change it
    to your liking if you understand the things explained

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Graphics programming often uses globals for speed....though in your apps you may not need it yet.....

    Just think like this.....in your example, you call GetModuleHandle ....this pushes 4 bytes onto the stack (NULL) and then calls the function...the system code returns the base module address (HINSTANCE) and then returns.....you may then need to assign that to a local variable (a MOV instruction)...and then you have your handle....with the global, you cut all that out......also, if you need to pass that HINSTANCE to another func...that's another 4 bytes on the stack for the call....

    Often globals are bad news....but in certain circumstances they come in handy

  7. #7
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: What is it with OpenGL tutorials?

    Originally posted by Eibro
    Every single OpenGL tutorial i've come across is SATURATED with global variables. It's disgusting. I can't learn from that garbage. Ugh. Ick.

    I shouldn't have to sign away the good programming principles i've learned just so I can learn OpenGL.

    I downloaded a basic tutorial which setup an OpenGL window and drew a triangle...
    It had SEVEN global variables.

    I quickly elminated four of them by adding some parameters to functions and using some standard Win32 API calls.

    I'm going to wrap initializing OpenGL in a nice flexable class so I never have to deal with this garbage again.

    Before I'll be able to do anything I know i'm going to want to wrap everything into a neat little package. Down with C! Up with C++!

    PLUS I have a very big hunk of garbage on my shelf called "OpenGL Superbible"
    Worst. Book. Ever.

    It's almost like once OpenGL is introduced, you can forget everything about design and structure and just hack new modules on until the cows come home.
    Agreed, Eibro. When I first started programmng in OpenGL, I went to NeHe and I was really disgusted. I stopped going pretty quickly. The best reference I've found has been MSDN's documentation. It's not exactly meant to be a learning tool (just a reference), but that's really what I learned off of. Just make sure you understand the very basic concepts of drawing in OpenGL and it's simple to branch off from there using msdn for a reference. As long as you are experienced with C++ and design (which I know you are), it shouldn't be a problem.

    Originally posted by Fordy
    Graphics programming often uses globals for speed....though in your apps you may not need it yet.....
    "Globals for speed" is an ignorant excuse. The speed difference between global and local variables is very minute. The use of global variables as an "optimization of speed" just limits the modularity of functions and doesn't pull in a noticeable gain (even if the variable is used thousands of times per second). The only really valid reason for not wanting things being put on the stack is if you are worried about a large amount of data being repeatedly tossed there. If that's the problem, then you just make the object static in the function it is declared.

  8. #8
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    What i think is a lot worse than global variables is calling OpenGL from the windows API. You take a porttable, cleanly designed API, and then waste all it's goodness by depending on a big, nasty, non-portable WinAPI. Use something like glut or SDL and get away from WinAPI's bloatedness and non-portability, and likely, the globals needed to quickly get hacked **** working due to the massive size of the api is gone.

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Big,Nasty Win32?
    Win32 aint no big nasty API!grr
    I take OpenGL because i just like it,and that it has portability
    is fine with me, im not going to use it however.

  10. #10
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    The book i am using starts from winapi and goes out to be just opengl, thats code from the beginning.

  11. #11
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Thanks for your input everyone.
    Graphics programming often uses globals for speed....though in your apps you may not need it yet.....

    Just think like this.....in your example, you call GetModuleHandle ....this pushes 4 bytes onto the stack (NULL) and then calls the function...the system code returns the base module address (HINSTANCE) and then returns.....you may then need to assign that to a local variable (a MOV instruction)...and then you have your handle....with the global, you cut all that out......also, if you need to pass that HINSTANCE to another func...that's another 4 bytes on the stack for the call....

    Often globals are bad news....but in certain circumstances they come in handy
    Yes, I took into consideration how many times the global hInstance variable was used, and it was around 2. There are very few WinAPI functions commonly used which take an instance handle. Had hInstance been used many times, I probably would have left it global.

    Agreed, Eibro. When I first started programmng in OpenGL, I went to NeHe and I was really disgusted. I stopped going pretty quickly. The best reference I've found has been MSDN's documentation. It's not exactly meant to be a learning tool (just a reference), but that's really what I learned off of. Just make sure you understand the very basic concepts of drawing in OpenGL and it's simple to branch off from there using msdn for a reference. As long as you are experienced with C++ and design (which I know you are), it shouldn't be a problem.
    Everyone pushes the NeHe tutorials as the best thing for learning OpenGL. When I couldn't stand looking at his/her code it kinda turned me off of OpenGL for awhile (I took up the WinAPI, SDL and read a few books by Scott Meyers) but now i'm back.
    I'll try out the MSDN reference, hopefully it'll prove more useful than these tutorials that i've been finding. Thanks a bunch.

  12. #12
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    check out opengl game programming by dave astle(among others), very good.

  13. #13
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I wanted to get that book, but when I went to chapters they didn't have it. So I came home, went on the net and read some reviews for OpenGL books... Superbible had nothing but praise.
    So I ordered it off amazon; what a big mistake that was. As soon as I saw void main() I let out a big sigh and closed the book.

    On a good note; I *finished* MY OpenGL OO Framework. NeHe eat your heart out!
    It's certainly minimal, but not complete.
    Last edited by Eibro; 01-11-2003 at 10:05 PM.

  14. #14
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786

    Re: Re: What is it with OpenGL tutorials?

    Originally posted by Polymorphic OOP
    "Globals for speed" is an ignorant excuse.


    You may see it as ignorant, but often that's why people do it.

    At learning stage, as I said, its probably not needed.

  15. #15
    Registered User PotitKing's Avatar
    Join Date
    Dec 2001
    Posts
    28

    PORTABILITY NOT IMPORTANT ??!!!

    Travis Dane:
    Portability is the most important thing there is. Without portability, there would be one language for each platform.

    Why not use SDL or GLUT? These are very good API's and as a Linux programmer,I use SDL because I want everyone to be able to use my program/game, not just other Linux users, and I wouldn't use WinAPI if I was using Windows either. Not caring about portability is just selfish.

    *thankyou*
    % gcc -v
    Configured with: FreeBSD/i386 system compiler
    Thread model: posix
    gcc version 3.3.3 [FreeBSD] 20031106

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL tutorials
    By ThWolf in forum Game Programming
    Replies: 10
    Last Post: 09-12-2006, 02:19 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. 3ds max -> opengl? any tutorials?
    By genghis in forum Game Programming
    Replies: 1
    Last Post: 06-23-2002, 01:46 PM
  4. OpenGL Tutorials
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 10-14-2001, 04:13 PM
  5. OpenGL Tutorials
    By BubbleMan in forum Game Programming
    Replies: 3
    Last Post: 09-23-2001, 01:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21