简体   繁体   中英

Why won't OSX Mavericks compile my GLSL Shader?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM