1

笔记:

挖了一圈,结果发现glCreateProgram()一直返回 0。一旦我弄清楚这一点,我会发布一个修复程序。有知道是什么原因的小伙伴请留言^^

context被正确创建。

context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

谢谢。


此文件正在正确加载。它被保存为 cl.vsh

它加载正常,但在编译阶段失败。

这是 cl.vsh 中的代码

attribute vec4 position;
attribute vec3 normal;

uniform mat4 modelViewProjectionMatrix;
uniform mat4 modelViewMatrix;
uniform mat3 normalMatrix;

uniform float time;

varying vec3 eyespaceNormal;
varying vec4 eyespacePosition;
varying vec3 noiseVector;


void main()
{

    int i = 0;
//    vec3 translation = vec3(1.0, 1.0, 1.0) * time / 20.0;
//    noiseVector = position.xyz + translation;
//    
//    eyespaceNormal = normalMatrix * normal;
//    eyespacePosition = modelViewMatrix * position;
//    gl_Position = modelViewProjectionMatrix * position;
}

这是编译部分。shaderString是 cl.vsh 的确切代码

 GLint status;
    const GLchar *source;

    source = 
      (GLchar *)[shaderString UTF8String];
    if (!source)
    {
        NSLog(@"Failed to load vertex shader");
        return NO;
    }

    *shader = glCreateShader(type);
    glShaderSource(*shader, 1, &source, NULL);
    glCompileShader(*shader);

    glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);

    if (status != GL_TRUE)
    {
        GLint logLength;
        glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
        if (logLength > 0)
        {
            GLchar *log = (GLchar *)malloc(logLength);
            glGetShaderInfoLog(*shader, logLength, &logLength, log);
            NSLog(@"Shader compile log:\n%s", log);
            free(log);
        }
    }   

打印日志_

(lldb) p log
(GLchar *) $0 = 0x17420000
(lldb) po log
[no Objective-C description available]
(lldb) p *log
(GLchar) $2 = '\0'
4

1 回答 1

7

经过一番挖掘,我意识到我需要将我的上下文设置为当前上下文。FML。这是问题

[EAGLContext setCurrentContext:context];

问题现在已解决。

于 2013-10-31T16:28:22.593 回答