OpenGL 3.3 on OSX with FreeGLUT - macos

I am using the following configuration
Mac OSX v 10.9.1
Intel HD graphics 4000 1024 MB.
My goal is to use OpenGL 3.3 using FreeGLUT, Is there a way to achieve that?
glxinfo gives me:
OpenGL vendor string: Intel Inc.
OpenGL renderer string: Intel HD Graphics 4000 OpenGL Engine
OpenGL version string: 2.1 INTEL-8.18.29
OpenGL shading language version string: 1.20,
and the programs where I try to open a 3.3 context gives me errors.
However this site https://developer.apple.com/graphicsimaging/opengl/capabilities/ states that HD 4000 should support 4.1. Is that only for glsl or is there any way to use FreeGLUT? The reason I want to use freeGlut is because the course I am taking right now requires the assignments to compile on their computers, and they are using FreeGlut, and I would like to be able to work from home.

MacOS X supports OpenGL-3.2 and later contexts only if you request a core context. You have to initialize FreeGLUT in addition with
glutInitContextVersion(3,2); /* or later versions, core was introduced only with 3.2 */
glutInitContextProfile(GLUT_CORE_PROFILE);
Another solution is given at https://stackoverflow.com/a/13751079/524368

Related

How to upgrade OpenGL on Ubuntu?

I'm running ubuntu 20.04.5 on an HP EliteBook 850. lspci shows the VGA:
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
glxinfo gives:
OpenGL version string: 3.0 Mesa 21.2.6
How can I upgrade OpenGL to at least version 3.2? I followed the procedure described at this link, but afterward glxinfo still shows OpenGL 3.0. Is there a concise guide somewhere describing the correct procedure?
Thanks!

OpenGL 4.1(?) under Mavericks

I've just upgraded my MacBook Pro to Mavericks (MacOS 10.9), including Xcode.
According to Apple's "OpenGL Capabilities Table", this version has support
for OpenGL 4.1, but a call to glGetString(GL_VERSION) returns "1.2" and my GLSL
3.30 shader, which begins with "#version 330" refuses to load, saying that
version is not supported.
Do I need to do something to Mavericks to enable 4.1 support?
When you request your pixel format using one of the lower-level APIs on OS X, you need to add the following to your attribute list in order to use a core profile:
CGL:
kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core
NSOpenGL:
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core
Now, while the particular constant is named ...3_2Core, what it actually means is request a context that removes all deprecated features and supports at least OpenGL 3.2 (a core profile, in other words). You can get a 4.1 or 3.3 context using this same constant; in all honesty, including an actual version number in the constant was probably a poor choice.
If you do not specify this when you request your pixel format, OS X will give you kCGLOGLPVersion_Legacy or NSOpenGLProfileVersionLegacy respectively. And this will limit you to OpenGL 2.1 functionality.
If you are using a higher-level framework, then you will need to consult your API reference. However, be aware that on OS X you must have a core profile context to access anything newer than OpenGL 2.1.
Use the OpenGL library GLFW the latest version is 3.0.4...
right after you initialize glfw init
if (!glfwInit())
{
printf("glfwInit() fail to initualize. \n");
glfwTerminate();
exit(-1);
}
after you initialize glfwInit() include these 4 lines of code. these four line of code will enable you to use the highest version supported by you OS. on mac its opengl 4.1
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
then create your window.
_Window = glfwCreateWindow(width, height, title, 0, 0);
check to make sure it was created.
if (!_Window) {
printf("Display window fail to create. \n");
glfwTerminate();
exit(-1);
}
then make it you current window using the following.
glfwMakeContextCurrent(_Window);
after you make it your cureent window all thats left to be done is to create you main loop.
while (!glfwWindowShouldClose(_Window))
{
........
glfwSwapBuffers(_Window);
glfwPollEvents();
}
make sure you includ glfwPollEvents(); in the loop this makes it possible to use the close botton to quit the window. if you having trouble compiling the library in xcode just message me on here and i will send you a copy of the library.
I struggled a long time on this, and finally succeeded on using any glsl version supported by the graphics card.
There are several main points:
Use CORE PROFILE
Set the MAJOR.MINOR to version of GL you want to use
If not the newest version of GL used, you have to enable FORWARD COMPATIBILITY.
for example, as pointed out by #kanthonye, if you are using glfw, and use gl version 3.2, these lines are needed:
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
http://support.apple.com/kb/HT5942
the site title is "Mac computers: OpenCL and OpenGL support in OS X Mavericks -
Learn about the OpenGL and OpenCL versions that are supported by your computer in OS X Mavericks."
If you're using LWJGL (as of version 2.90), there's a mild gotcha in the javadoc header of ContextAttribs:
... This extension is not supported on MacOS X. However, in order to enable the GL 3.2 context on MacOS X 10.7 or newer, an instance of this class must be passed to LWJGL. The only valid configuration is ContextAttribs(3, 2, CONTEXT_CORE_PROFILE_BIT_ARB), anything else will be ignored.
If you are using SDL as your high level API there are a number of things you need to do to get 4.1 support.
First of all make sure you have SDL2 2.0.1 (or later I guess). For instance using brew:
brew update
brew upgrade sdl2
Secondly, you need to specifically tell SDL to request a core profile like so
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
Thirdly a quirk in how a core profile is requested on the mac actually requires you to request 3.2 to get 4.1 (!). I think this has been fixed in the SDL2 repository but not been released yet.
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

GLFW opens OpenGL 3.2 context but Freeglut can't - why?

I am working on a Mac, I've got FreeGlut compiled and installed, but I can't seem to get the OpenGL 3.2 context with it. However, I can get it without any problem while using GLFW.
So in GLFW, this code works perfectly fine:
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwOpenWindow(500, 500, 8, 8, 8, 8, 24, 8, GLFW_WINDOW)
But with FreeGlut, this code fails(on glutCreateWindow):
glutInitContextVersion (3, 2);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutInitWindowSize (width, height);
glutInitWindowPosition (300, 200);
int window = glutCreateWindow (argv[0]);
The error it fails with is:
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 34 (X_UngrabKey)
Serial number of failed request: 29
Current serial number in output stream: 29
I am running on MacOS X 10.8 Mountain Lion, with Intel HD4000 graphics, having installed XQuartz as my X11 server,and having compiled and installed FreeGlut 2.8 from sources.
Does anyone know what might be the issue?
In 10.8 and 10.7 GL 3.2 is available if you explicitly call for it when setting up the GL context. Apple calls this the "Core Profile" to distinguish from the "Legacy Profile" which is GL 2.1.
I ran into this issue with Wine on OSX, it does not support OpenGL 3.2. My understanding is that the X11 server (either Apple X11 or XQuartz) currently does not implement the 3.2 support, nor is there a switch to flip somewhere to enable it. It could be for compatibility concerns since 3.2 profile will break some existing GL applications
This post suggests using GLFW (or maybe Apple's GLUT.framework if there is still such a thing)
This page explains the GL stack on OSX and confirms the 2.1 issue with GLX.
Freeglut is an extended implementation of the SGI GLUT Toolkit, and ( with a few exceptions around obsolete hardware ) implements the same functions.
Unfortunately, this includes a number of features that would break in a strictly CORE/FORWARD COMPATIBLE implementation.
Typically, if you request a context WITHOUT specifying a version or profile, you will get the best that the combination of driver and GL toolkit can offer, which is normally a compatibility profile, rather than core profile.
Note that the only thing you lose through using a compatibility profile is the supposed checking for deprecated functions. All new core function should work without issue.
This problem with freeglut is not restricted to Apple, it also manifests under Linux using some Gallium drivers. It is not clear that there is any short-term intent to rectify this, so if you need to use CORE/FORWARD COMPATIBLE, you should probably switch to GLFW or SDL.
You need to include the flag. usually under the Version. It should look something like this:
glutInitContextFlag(GLUT_FOWARD_COMPATIBLE);

GLUT on OS X with OpenGL 3.2 Core Profile

Is it possible to use GLUT on OS X Lion or OS X Mountain Lion using core profile (so I can use GLSL 1.50)?
Can I use the built in GLUT or do I need to use a third-part library such as FreeGLUT?
And is there any simple 'Hello world' applications available for OS X with either an XCode project or a make-file?
You need at least Mac OS X Lion (OS X 10.7 or higher) for the basic support of OpenGL 3.2. To use the OpenGL 3.2 Core Profile, just add
glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | ... | ...);
in your main-function. You can check it by
std::printf("%s\n%s\n",
glGetString(GL_RENDERER), // e.g. Intel HD Graphics 3000 OpenGL Engine
glGetString(GL_VERSION) // e.g. 3.2 INTEL-8.0.61
);
GLUT does not support OpenGL 3.2, as it provides no functionality to specify the desired OpenGL context version. Also, GLUT's functionality relies on APIs that are not available with the OpenGL 3.2 Core Profile.
You have to switch to FreeGLUT or GLFW.
flyx is wrong, OpenGL 3.2 is the version that added core and compatibility profiles (not 3.3). However, Apple just doesn't support compatibility profiles at all (no reason, they just don't). GLUT comes in xcode as a framework and you can use it that way. So you can do it in a completely non-standard, platform specific way.

Enabling OpenGL Core Profile in QT4 on OS X

I just upgraded to Lion and am trying to get some practice coding with GLSL 1.50, however I can't get my code to run above OpenGL 2.1 thus I get "version '150' is not supported" errors when trying to compile my shaders.
The set up is as follows:
I am using 2 x 2.8Ghz Quad-Core Xeons with a GeForce 8800GT in OS X 10.7.2 and using QT creator 2.3 & QT version 4.7.
To set up my OpenGL context I use a class derived from QGLWidget.
As I plan to have a second QGLWidget with a similar setup, my aim has been to change the default format for my QGLWidget(s) like so:
QApplication app(argc, argv);
QGLFormat f;
f.setVersion(3, 2);
f.setProfile(QGLFormat::CoreProfile);
QGLFormat::setDefaultFormat(f);
GUIVolumePanel* pvp = new GUIVolumePanel(prc, x, y, z);
std::tr1::shared_ptr<GUIMainWindow> prog(new GUIMainWindow(pvp));
However this appears to have no effect on my OpenGL context and I am at a loss as to figure out why.
I Googled it and found
http://developer.qt.nokia.com/forums/viewthread/8047
which leads me to think 4.7 does not support it directly yet. There is some code posted there that might get you going as a work around. You might also try qt 4.8 rc.
Given that Lion came out after qt 4.7 was out I would not expect it to work right off.

Resources