2

This shader program compiles perfectly fine

#version 120
void main()
{
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

But when I try switching to version 330 or 400 it throws a 'not supported' error

#version 400
void main()
{
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

I need to use the 'in' and 'out' functionality to go along with the book I'm using to learn OpenGL and the latest Mac is supposed to support up to 4.1. I even downloaded the apple graphics developer tools to use the OpenGL Shader Builder for help and it won't compile anything more than 1.2 either.

genpfault
  • 51,148
  • 11
  • 85
  • 139
jtman
  • 113
  • 2
  • 6
  • pretty sure `gl_FontColor` and `gl_TexCoord` are not needed/removed in GL 4.0, instead you want to use vertex attribute. – yngccc Jan 07 '14 at 19:42
  • 3
    You hit the trifecta with that shader. Not a single line of code in the 3.30 / 4.00 shader is valid. This is because on OS X, any version of GLSL > 1.20 is implicitly **core**. You cannot use compatibility profile constructs like `gl_MultiTexCoord0` or `ftransform (...)`. You might as well get into the habit of writing your shaders that target OS X as `#version 330 core`. This will help you remember that your feature set is limited, and will also prevent you from making changes to the shaders on other platforms that ultimately render them incompatible with OS X. – Andon M. Coleman Jan 07 '14 at 19:42
  • 1
    Ok, forget the rest of the shader, one liners won't even compile, one line '#version 120' compiles and '#version 330' returns ERROR:0:1:version '330' is not supported. What am I missing? Do I need to update this Mac? It is less than a month old. – jtman Jan 07 '14 at 19:54
  • 4
    Like I said, if you want to use a version of GLSL > 1.20, you need a core profile context. I am not convinced you have taken the necessary steps to acquire one. By default on OS X, you get an OpenGL 2.1 (GLSL 1.20) implementation. Unless you ask for a core profile, any GLSL shader newer than this is going to refuse to compile. This is why you should get in the habit of writing `#version 330 core`. But changing the version directive in your shader alone is insufficient, you need to get a 3.2+ core profile when you create your window with whatever framework/API you are using. – Andon M. Coleman Jan 07 '14 at 20:00
  • 1
    Ok, I think I am beginning to understand. Trying to use the OpenGL Shader Builder provided by Apple Developer Tools I cannot get the {#version 330 core} to compile either. So you are saying when I use GLEW I need to somehow get a 3.2+ profile with the window. I guess I was thinking that using Apple's provided tool for building shaders would support me on that. – jtman Jan 07 '14 at 20:16
  • Though I'm getting deprecated functionality warnings, this solution provided a solution to my problems.[http://stackoverflow.com/a/13751079/1042022] Doing this in my project yielded the ability to compile up to OpenGL 4.1 as I expected. (Which, buy the way, was the solutions Andon suggested.) Thank you. – jtman Jan 08 '14 at 16:43
  • Apple should really just stop distributing the OpenGL Shader Builder. It seems like a helpful tool but it's just a tar pit for noobs (like myself) to get stuck in. – drewish Dec 24 '14 at 06:29

1 Answers1

3

I am assuming you are using NSOpenGLView. I could not compile any > V1.20 shaders until I configured the OpenGL profile to use the 3.2 core. The pixelFormat property on the NSOpenGLView (or its subclass, if you are subclassing it) must be set with the right attributes.

If you are subclassing NSOpenGLView and have added it to a view in Interface Builder, you can add the following code to the subclass' -awakeFromNib method:

- (void) awakeFromNib
{
    NSOpenGLPixelFormatAttribute attributes [] = {
        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
        (NSOpenGLPixelFormatAttribute)0
    };

    NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
    [self setPixelFormat:pf];
}

There are other ways to set up the pixel format if you are creating the view programatically (such as -initWithFrame:pixelFormat:).

Also, see Apple's GLEssentials example code, there is quite a bit going on in there but it does utilize the more recent versions of OpenGL and has the exact code snippet above in it.

dbrwn
  • 131
  • 5