cannot use GLSL 330 on mac mavericks - macos

I'm trying to learn OpenGL and the material is using #version 330 in shaders. I can compile it successfully, but when I try to run it, it complains Version 330 is not supported.
In my source code, I use free glut and OpenGL framework in Xcode. If I also include these two lines of code
glutInitContextVersion(3,1);
glutInitContextFlags(GLUT_CORE_PROFILE);
it cannot be compiled.
My mac is MacBook Pro Mid 2012. It should support OpenGL4.1 according to apply.
So how can I compile version 330 shaders?

OS X requires that you request a 3.2 core profile in order to receive a 3.3 or later context. This is because 3.2 finally removed the functionally that was deprecated in 3.0.
So if you want to use a #version 330 shader then your code should look like this:
glutInitContextVersion(3,2);
glutInitContextFlags(GLUT_CORE_PROFILE);
EDIT Apparently X11 doesn't support OpenGL higher than 2.1 on OS X. As such, I suggest you switch to GLFW.

Related

How to enable OpenGL 3.X in Mac OS?

Previously I'm using OpenGL on Mac via glew 2.1.0 and JUCE5, but it can only access OpenGL 2.1 APIs. I can't believe that my Macbook Air (Intel Graphics) bought on 2018 can only provide this, and I'm tired to maintain two sets of API calls and shaders for 2.1 and 3.X separately. Then I tried to replace all #include <GL/glew.h> with #include <OpenGL/gl3.h>, then link with OpenGL framework directly. However, the program still failed to compile a #version 130 shader (it claims not supported).
Here I want to know that:
Does all recent Apple devices (after 2010) capable for OpenGL 3.0?
How to turn on OpenGL 3.0 support on MacOS?
Finally I found the way: I have to enable it on JUCE side. When JUCE's OpenGL context is created, I must explicitly set expected OpenGL version by setOpenGLVersionRequired( juce::OpenGLContext::openGL3_2 ) before using it.
IMPORTANT: this would still lead failure to a compile to #version 130 shader, as Apple would strictly deprecate all old features prior to specified API version. A simple workaround is to dynamically prepend a version declaration according to system type, as GLSL 1.3.0 features is mostly included by GLSL 1.5.0.

OpenGL and GLSL on macOS Catalina

It's quite a few years now that I develop and maintain an OpenGL app on macOS. Even on Catalina it runs beautifully and fast. Now I need to add a particles feature and use glDrawElementsInstancedARB. The extensions GL_ARB_draw_instanced and GL_ARB_instanced_arrays are present.
As I have read on the web, this command has to be used together with a GLSL shader, so I tried to develop a GLSL shader too. The problem: the shader won't compile. I get an error on the first line
layout (location=0) in vec3 position;
also, the max version allowed is
#version 130
while the GLView app (freely available on the MAS) tells me
CORE: OpenGL version 4.1 ATI-3.10.18
COMPATIBILITY: OpenGL version 2.1 ATI-3.10.18
and glGetString(GL_SHADING_LANGUAGE_VERSION) returns
GLSL Version: 1.20
I know that Apple has just deprecated OpenGL.
Anyway, do you think is a way to compile my shader?
Should I need to install something extra? If so, should my users install something extra too?

Unable to link OpenGL compatibility profile (EXT symbols not recognized)

I decided to use GLEW for handling extensions instead of requesting core profile and having to migrate my code.
I would like to add support for FBO's through the EXT profile as a first step.
The problem is gcc will not link my code (OSX 10.10), it does not recognize any gl*EXT() functions. For instance, glBindFrameBufferEXT()
flags as undefined symbol. (glBindFrameBuffer() was also
unrecognized...)
I link against GLEW and have tried using GLEXT or GLFW with compatibility profile, but nothing works! Am I missing a library? How do I tell gcc to use the right GL profile? Am I obliged to migrate to core profile?
In MacOS X GLEW is not doing a lot, because there are not a lot of OpenGL extensions on MacOS X and due to the way OpenGL is integrated in MacOS X all functions of the OpenGL version supported by the available framework are immediately available
… or not, if you're using an extension function that's not supported by MacOS X's OpenGL implementation.
MacOS X is the weird duckling in the OpenGL family: OpenGL is used at a very low level in the OS's core graphics routines, to OpenGL is very well supported by the OS. But it's built so deep into the OS that it hardly can be updated without updating the whole OS.
Solution: Don't use that extension. FBOs have been introduced with OpenGL-3.3 so you've to create a 3.3 core profile context and can use the functions (without the …EXT) directly.

How do I upgrade my OpenGL from 2.1 to 3.3 on Mac OSX?

I am trying to program OpenGL 3 in C on my Macbook Pro.
My graphics card is NVIDIA GeForce 320M 256 MB, but I have OpenGL 2.1 According to wikipedia, I should be able to use OpenGL 3.3:
However, when I run glxinfo | grep -i opengl, I get OpenGL version string: 2.1 NVIDIA-8.24.16 310.90.9.05f01.
How do I go about upgrading it? I am running Mavericks.
Technically, you cannot get a (windowed) OpenGL 3.2 context programming purely in C on OS X.
You have to use part of Cocoa (an Objective-C framework) called NSOpenGL; AGL (deprecated C-based API) as well as the really old X server implementation (XQuartz) are perpetually limited to OpenGL 2.1.
Apple's own implementation of GLUT wraps NSOpenGL (FreeGLUT does not), and so do GLFW, SDL, etc. They have small portions that are written in Objective-C to interface with NSOpenGL and this allows them to create window-based OpenGL 3.2+ render contexts even in C software.
Now, the problem here is actually that glxinfo uses XQuartz, which does not support OpenGL 3.2+. I would suggest you use the OpenGL Extension Viewer on the Mac App store if you want detailed info about your OpenGL capabilities.
Since you're just starting out with OpenGL development on OS X, I would also suggest you have a look here for a quick overview of the various APIs.
You cannot upgrade your graphics drivers since they are provided by Apple. But your system should support OpenGL 3.3 ( https://developer.apple.com/opengl/capabilities/ ). When creating a OpenGL context you must request a CoreProfile mode. If you are using GLUT this can be done this way:
GLUT on OS X with OpenGL 3.2 Core Profile

OSX and OpenGL 4.x compatibility

I'm working on a portable application that should run on OSX-Lion as well.
From what I read here OpenGL/GLSL support seems to be 3.2/150 can someone confirm this?
My application requires at least GLSL ver 400. Is there a way to have it running on Lion? Some cards (i.e. ATI HD6770) are OpenGL 4.1 compliant. Does it mean it can go only as far as 3.2/150 under OSX?
confirmed by alternate source, osx opengl 4.x support is still TBA

Resources