我尝试设置简单的纹理: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 支持吗?