OpenGL Basics: Glut vs. Nehe's framework

Started by
12 comments, last by Adam Hamilton 18 years, 1 month ago
Hi all, Looking for a little generic advice here. I'm coding a tetris clone for my first graphical C++ game. I've got my data structures almost all coded, and I'm starting to think about how I'm going to link everything together with the graphics display. I've looked at two basic methods to get the graphics set up. The first would be to modify the framework which is listed in Nehe's tutorials. The second would be to use the Glut utilities which are described in the red book. I'm leaning towards using the glut because it just seems cleaner and simpler to get everything set up, but I have some concerns. I will be coding up a 'game state' structure which will contain (among other things) whether the game is active, the options, the score, the board, the active piece, the next piece etc. One thing which I was planning on putting in there is a function pointer to a display function so I can pass the game state to the main "display" routine and then call a seperate display function using that pointer depending on whether the game is in the startup splash, the options menu, the actual game itself, etc. From the red book, the function definition for the display function is:

void glutDisplayFunc(void (*func)(void));
so I can see no way to feed in a method for checking which screen to display unless I just declare the game state as a global, which I'd rather not do if I can help it. Is using global variables how that is typically done, or am I overlooking something? Thanks again! This site has made the process significantly less frustrating.
Advertisement
Glut is mostly used for smaller projects because as you've seen, its callback system is kind of limiting for larger programs.

Another option you can look into is SDL for this. On NeHe's site, you can scroll down on lesson 1, and grab the Linux/SDL port. (It will work on Windows too though).

SDL is not so limiting as Glut, but you still don't have to deal with all the awful Win32 setup code.

Good Luck.
Nehe's framework uses Win32 doesnt it? If i was going to use OpenGL id make my best effort to keep it cross platform, so using SDL or Glut might be best.

I seem to remember having similar problems with Glut and its lack of flexibility. I have never build an application that uses both SDL and OpenGL, but the work required to setup an SDL window is so easy its got to be worth a look =)
"Leave it to the computer programmers to shorten the "Year 2000 Millennium Bug" to "Y2K." Isn't that what caused this problem in the first place?"
GLFW is a really nice framework for OpenGL.
Are you going to have multiple windows in your game or just one?

What is wrong with in your display function, calling other functions through a switch or even through a second function pointer?

I, uh, used a global variable for my game state whenever I made a game.
Quote:Original post by nprz
Are you going to have multiple windows in your game or just one?

What is wrong with in your display function, calling other functions through a switch or even through a second function pointer?

I, uh, used a global variable for my game state whenever I made a game.


Thanks for the input, all!

I'm planning on just one window for this game. It's going to be yet another tetris clone.

I could use a switch, but I'd still need to use global variables to get the information to switch against into glutDisplayFunc. I personally don't like using global variables unless there is no other option. I've botched up entirely too many Matlab assignments by using scripts instead of functions and inadvertantly overwriting my globals.

I saw SDL a few days ago, and was planning on checking it out a bit once I got a bit further with NeHe's tutorials and the Redbook (found them first after all...). I'll look at GLFW also, thanks!

I'm probably going to modify the NeHe code for this game. The code I've got now creates a window and has seperate functions for update graphics and check for inputs. That should be all I need. There is always the next game for the other stuff.
You can work around global variables by having a global function which returns a a file scope variable. It is ok to have one filescope pointer to some kind of singleton application root structure or class, and a single global function to get that pointer. In C++ you could use static class member instead of filescope variables.
I would recommend against writing your own OpenGL Framework like NeHe has done. Some of the benefits of using an already written dedicated library include:
  • Cross platformability
    Many already written libraries provide dedicated cross platform. This means you can usually compile for Windows, Linux and Mac without having to change much in your code.
  • Easily upgradable
    All you'd have to do to update the library would be to overwrite your existing LIB and DLL files.
  • Documentation
    There is loads of tutorials and documentation available for dedicated libraries.
Although it might be tempting to roll your own framework or base it off of NeHe's, the best solution is to use an already existing dedicated framework.

I've had experience with GLFW, FreeGLUT and SDL when it comes to rendering in OpenGL and have to say all three are great solutions. Try a number of different ones and see which one you like. The great thing about the framework is that it allows you to seperate your game and engine code into a nice managable interface. Good luck!
Rob Loach [Website] [Projects] [Contact]
OK. I feel like a n00b again.

I can't figure out how to compile GLFW.

From the readme.html:
Quote:
A top level makefile can be found in the root directory of the GLFW distribution that has been designed to work with several compilers. If you simply enter the GLFW root directory in a shell and type make (or nmake or gmake, depending on the name of your make tool), and a list should appear with the currently supported options for systems and compilers.

For example, one of the options is to compile GLFW for Windows with the LCC-Win32 C compiler. To do that, type make win32-lcc in the shell (as specified in the previously mentioned list). That will compile the GLFW static link library and the supplied example programs. For Windows compilers, a Win32 DLL will also be compiled.


I tried make, nmake, and gmake from a dos prompt, as well as simply running the compile.bat file. The instructions aren't exactly superclear for non-CS types.

Can someone explain in kiddy terms what I'm supposed to do?

Thanks,

EDIT: Running Windows XP with Microsoft Visual Studio .net if that makes a difference.
EDIT2: uhm. Looks like it only supports MSVC 6.X
Am I SOOL?
Afaik GLFW comes with prebuild libraries. Did you change the GLFW code?
There should be a dll and/or lib that you can use.

I think I downloaded the gnu stuff just for building the example programs.
Writing errors since 10/25/2003 2:25:56 AM

This topic is closed to new replies.

Advertisement