使用#version 130加载纹理导致错误“版本'130'不受支持”

时间:2013-03-13 11:24:29

标签: macos opengl

我尝试设置简单的纹理: FP:

uniform sampler2D colorMap;

out vec4 vFragColor;
smooth in vec2 vVaryingTexCoords;


void main(void)
   { 
   vFragColor = texture(colorMap, vVaryingTexCoords.st);
   }

VB:

#version 130

in vec4 vVertex;
in vec2 vTexCoords;

smooth out vec2 vVaryingTexCoords;

void main(void) 
    { 
    vVaryingTexCoords = vTexCoords;
    gl_Position = vVertex;
    }

这是一个加载代码:

#ifdef linux
#include <cstdlib> 
#endif
#ifdef __APPLE__
#if IPHONE
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#define OPENGL_ES
#else
//#include "GL/glew.h"
#import <OpenGL/glext.h>  
#include <OpenGL/gl3.h>     // Apple OpenGL haders (version depends on OS X SDK version)
#endif
#include <unistd.h>
#endif
GLuint gltLoadShaderPairWithAttributes(const char *szVertexProg, const char *szFragmentProg, ...)
    {
    // Temporary Shader objects
    GLuint hVertexShader;
    GLuint hFragmentShader; 
    GLuint hReturn = 0;   
    GLint testVal;

    // Create shader objects
    hVertexShader = glCreateShader(GL_VERTEX_SHADER);
    hFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    // Load them. If fail clean up and return null
    // Vertex Program
    if(gltLoadShaderFile(szVertexProg, hVertexShader) == false)
        {
        glDeleteShader(hVertexShader);
        glDeleteShader(hFragmentShader);
        fprintf(stderr, "The shader at %s could ot be found.\n", szVertexProg);
        return (GLuint)NULL;
        }

    // Fragment Program
    if(gltLoadShaderFile(szFragmentProg, hFragmentShader) == false)
        {
        glDeleteShader(hVertexShader);
        glDeleteShader(hFragmentShader);
        fprintf(stderr,"The shader at %s  could not be found.\n", szFragmentProg);
        return (GLuint)NULL;
        }

    // Compile them both
    glCompileShader(hVertexShader);
    glCompileShader(hFragmentShader);

    // Check for errors in vertex shader
    glGetShaderiv(hVertexShader, GL_COMPILE_STATUS, &testVal);
    if(testVal == GL_FALSE)
        {
        char infoLog[1024];
        glGetShaderInfoLog(hVertexShader, 1024, NULL, infoLog);
        fprintf(stderr, "The shader at %s failed to compile with the following error:\n%s\n", szVertexProg, infoLog);
        glDeleteShader(hVertexShader);
        glDeleteShader(hFragmentShader);
        return (GLuint)NULL;
        }

    // Check for errors in fragment shader
    glGetShaderiv(hFragmentShader, GL_COMPILE_STATUS, &testVal);
    if(testVal == GL_FALSE)
        {
        char infoLog[1024];
        glGetShaderInfoLog(hFragmentShader, 1024, NULL, infoLog);
        fprintf(stderr, "The shader at %s failed to compile with the following error:\n%s\n", szFragmentProg, infoLog);
        glDeleteShader(hVertexShader);
        glDeleteShader(hFragmentShader);
        return (GLuint)NULL;
        }

    // Create the final program object, and attach the shaders
    hReturn = glCreateProgram();
    glAttachShader(hReturn, hVertexShader);
    glAttachShader(hReturn, hFragmentShader);


    // Now, we need to bind the attribute names to their specific locations
    // List of attributes
    va_list attributeList;
    va_start(attributeList, szFragmentProg);

    // Iterate over this argument list
    char *szNextArg;
    int iArgCount = va_arg(attributeList, int); // Number of attributes
    for(int i = 0; i < iArgCount; i++)
        {
        int index = va_arg(attributeList, int);
        szNextArg = va_arg(attributeList, char*);
        glBindAttribLocation(hReturn, index, szNextArg);
        }
    va_end(attributeList);

    // Attempt to link    
    glLinkProgram(hReturn);

    // These are no longer needed
    glDeleteShader(hVertexShader);
    glDeleteShader(hFragmentShader);  

    // Make sure link worked too
    glGetProgramiv(hReturn, GL_LINK_STATUS, &testVal);
    if(testVal == GL_FALSE)
        {
        char infoLog[1024];
        glGetProgramInfoLog(hReturn, 1024, NULL, infoLog);
        fprintf(stderr,"The programs %s and %s failed to link with the following errors:\n%s\n",
            szVertexProg, szFragmentProg, infoLog);
        glDeleteProgram(hReturn);
        return (GLuint)NULL;
        }

    // All done, return our ready to use shader program
    return hReturn;  
    }   

这是一个输出:

  

错误:0:5:'':不支持版本'130'   错误:0:10:'平滑':语法错误语法错误

我哪里错了。我是最后一个osx版本,它必须支持1.5 GLSL和3.2 gl遵循官方OpenGL描述:

https://developer.apple.com/graphicsimaging/opengl/capabilities/index.html

但是当我通过OpenGL扩展查看器检查时,它看起来只支持1.2版本。我是否需要任何后门方法来支持glsl 1.3?

enter image description here

1 个答案:

答案 0 :(得分:1)

OpenGL 3.2版只需要能够编译GLSL版本1.40和1.50。在Windows上,大多数OpenGL实现都会接受各种各样的着色语言版本,在MacOSX上,你将不得不坚持所需的。