difference of freeglut vs glew? - opengl

I've recently started learning OpenGL (> 3.3) & I've noticed a lot of examples & tutorials use both freeglut & glew, but don't really explain the difference at all. The best description I've found, after googling & reading ad nauseum, has been this OpenGL Related toolkits and APIs but found it lacking. I've even read the tag info on SO.
As someone really new to OpenGL I'm still trying to get a grasp of the different concepts. I've gotten to the stage of creating a basic program that uses glew, create context (on windows, VS2010), & draw really basic shapes, all without the need for explicitly including freeglut. So I don't understand why I would need it.
So my question then is, what's the difference between:
-freeglut
-glew
-(& glfw)
What can one do that the other can't?

The OpenGL Extension Wrangler (GLEW) is used to access the modern OpenGL API functions(version 3.2 up to latest version).If we use an ancient version of OpenGL then we can access the OpenGL functions simply including as #include <GL/gl.h>.But in modern OpenGL, the API functions are determined at run time, not compile time. GLEW will handle the run time loading of the OpenGL API.About GLEW see here
GLFW or freeglut will allow us to create a window, and receive mouse and keyboard input in a cross-platform way. OpenGL does not handle window creation or input, so we have to use these library for handling window, keyboard, mouse, joysticks, input and other purpose.
GLFW and freeglut are alternative for us according to our need we can choose any one but GLEW is different from them which is used for run time loading of the OpenGL API.

I'm using both of them for some work at my university.
GLEW is a "cross-platform open-source C/C++ extension loading library" (from its website), while freeglut is a window manager that replaces the default OpenGL Utility Toolkit (GLUT) library.
So, as you see, both different have different purposes. The point of using freeglut is that it's still maintained, while the default GLUT isn't, so if you want bug fixes and new features you should use it :)

Related

Query about opengl, glut, glew

Is there not a simple sdk for opengl why there are glut or glew and what are the written using? Which one should I use? There are so many frameworks out there that it is so confusing? Why there isn't just one sdk for opengl?
why there are glut or glew and what are the written using?
GLUT, GLFW and similar frameworks exist, because the system level interfaces to create a window and a OpenGL context are extremely versatile in what they can do, but it also takes a lot of code, just to create a window and them some more to create the OpenGL context. …and then some lots more of code to also do things like UI event management and so on.
These system level APIs are that verbose, because on a system level, you don't want to pin down what you can and can not do with these APIs.
So the three calls
glutInitDisplayMode(…);
glutCreateWindow(…);
glutMainLoop();
encapsulate about 1.5k lines of code dealing with just the system. But then with GLUT you don't get nice buttons, menu bars and the likes. For that you'd use a different framework, like Qt, which has even more code, but uses the same system level APIs as GLUT does. Same goes for GLFW and so on.
GLEW we have, because OpenGL can be extended and the system level interface for extending it is again down for minimalism and flexibility.
Why there isn't just one sdk for opengl?
Because in the end OpenGL is a system level API and the "SDK" comes ready-to-use with your regular system default compiler.
If you want to, you can create OpenGL programs without GLEW, GLUT and so on. But it is tedious.

Do Libraries like GLUT & GLFW have the same functionality as SDL?

I was watching this video about OpenGL 3 - https://www.youtube.com/watch?v=XMgfddy7S7Q
And while talking about libraries to work with OpenGL (at 3:00) he mentions GLFW, freeGLUT and GLUT to use to create the window.
But can they handle input and sound as well like SDL?
And if so should I be using SDL? Or is GLFW more tuned for making games specifically in OpenGL?
No, GLUT and GLFW are frameworks that manage OpenGL context creation and windowing (which includes input) mostly. GLUT has a few components that are actually designed to draw things, but by in large it is there to setup GL only.
SDL, on the other hand, includes sound which neither GLFW nor GLUT do but also includes utilities to load resources such as image files. It is a much more end-to-end solution, whereas GLFW and GLUT are only designed to facilitate rendering/windowing. To do the same thing using GLFW, you would need to throw in some libraries such as SOIL (or work directly with libpng, libjpeg, etc.) and also find an audio library.
You do not need any of these things to make a game in truth. I interact directly with OpenGL (WGL/GLX/CGL) on Windows, Linux and OS X in my work but the extra time necessary to debug and maintain each of these platforms at such a direct level can be a real nuisance. If writing extra code specific to each platform you run on is unappealing then you should definitely consider GLFW, etc.

Modern OpenGL with SDL / loading library

Is it possible to learn ''modern'' OpenGL with SDL2.0, without using a loading wrapper?
I've read that I had to use an OpenGL loading library in order to use a function like glGenVertexArrays.
But if that is the case, which loading library should I use? GLEW doesn't seem to be maintained.
GLFW seems to be new, but if I use that, SDL is not needed any more right?
GLEW (which very much is maintained) and GLFW serve very different purposes. GLEW is an extension wrangler which allows you to access non-standard functionality, and in some cases, standard functionality which isn't exposed by the default development environment. The most common example of the latter is developing on Windows, where the standard OpenGL header hasn't been updated for any functionality subsequent to OpenGL 1.x.
GLFW on the other hand is an abstraction which is designed to allow you to create windows and OpenGL contexts on a variety of supported platforms without having to write code specific to that platform. The process of setting up a window on OSX is very different from that of setting up one on Microsoft Windows, and this is what GLFW shields you from. In this regard GLFW is a subset of the functionality of SDL, which attempts to do the same thing, but with a larger focus, allowing access to audio output and and game device inputs as well.
Whether or not you have to use a loading library such as GLEW with either SDL or GLFW is mostly dictated by the platform you're trying to target and the OpenGL functionality you want to use. If you're attempting to use modern OpenGL, i.e. 3.x or 4.x, and you're working with a platform that doesn't have full support for it in it's OpenGL headers, then you're probably going to have to rely on GLEW to fill in that gap for you.

Combine WGL with GLUT for shapes under Windows 7 OpenGL. Missing GLUT INIT?

I'm working with OpenGL using Win32 API. Therefore I'm using wgl (Wiggle). Everything is fine. Except if I want to use some shapes from the FREEGLUT library. For example, the teapot. I was looking at the source code of freeglut, and it seems that when I issue a
glutSolidTeaPot(1.0); ,it exists the program because of the macro: FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" ); which calls fgerror, which has an exit(1).
Therefore, the symptom that I'm getting is obvious. When I ran the OPENGL program without any GLUT commands (like the teapot) it works great. If I use the teapot, it exits.
It is clear to me, that I'm missing initialization. The question is if I can initialize (and how) glut to be used for the shapes in my wgl context ... If this is not possible, I guess I could create the shapes myself. It is just faster to use those if possible.
All the examples that I have found so far point in how to initialize glut when you are working with glut only.
I'm using Windows 7 64, Visual Studio 2012, NVIDIA 330m , FreeGlut
FreeGLUT is not intended to be used in part. It is a system for creating and managing an OpenGL rendering context. It has utilities functions, but it's primary purpose is to create and manage a window. So if you're not using FreeGLUT to create and manage OpenGL, you don't get to use it for other things too.
While It seems that combining GLUT and WGL (Wiggle) is not possible (and rightly so), I have look at the code and it seems that this could be change to make it work. Of course, why make it work? Because of the additional utilties that GLUT (FreeGlut) has... like creating a sphere...
A better approach is to create a modern library to do all of this... Of course, you have some of the geometry libraries outthere, but I haven't check them.
I'm talking something more like the AUX library, but up to date.

Alternative to GLUT

GLUT is a very old framework for OpenGL, and there seems to be a lot of negative attitude towards it. I hear SDL is an alternative, though to my understanding it does not handle the 3d component of OpenGL. What is a good option (which preferably has good documentation so it is easily learnable) that can do what GLUT does and provide more functionality, eg. to make a complete 3d game? I prefer not to use pre-made game engines, I'd much rather build my own code from scratch.
orginal GLUT is very old and I would not recommend it. But the new version of it: http://freeglut.sourceforge.net/ is quite interesting framework. Is is as simple as GLUT but adds more features: mouse scroll, new geometry objects, etc, etc.
last version of this library is from January 2012
here is a useful link with several frameworks for opengl: http://www.opengl.org/resources/libraries/windowtoolkits/
If you want to make w "whole" project I suggest combining more libraries:
http://www.opengl.org/wiki/Related_toolkits_and_APIs#Context.2FWindow_Toolkits
http://glsdk.sourceforge.net/docs/html/index.html
SOIL for texture loading
If you are to use modern OpenGL GLFW is the best option out there to manage context, window creation, user input. The lib is very active with constant new releases.
Just wanted to add that my consideration to move from GLUT and from FREEGLUT was the lack of ability to define color, stencil, depth bits and MSAA samples for created context. GLFW allows you doing this.
SDL can create windows with OpenGL context (see the SDL_WINDOW_OPENGL window flag), so you can use the OpenGL functions. So can SFML, and probably Allegro too.
I personally recommend SFML, especially version 2 (which is in development), as I find it very easy to set-up and start using, both generally and for OpenGL.