Problems compiling shader source within osg application

岁酱吖の 提交于 2019-12-11 10:55:09

问题


I have an OSG application that I want to texture map a full screen quad in the finalDrawCallback because I need everything in my scene to be rendered before the texturing is done. This is why I have to use the openGL calls instead of the osg calls for the program and shaders to execute.

Specifically I seem to have an issue with compiling both the vert and frag shaders. When I call glGetShaderiv(shader, GL_COMPILE_STATUS, &param), my param value doesn't change or is undefined. Which, according to its documentation says that an error was produced. However, when I call glGetError() to check, openGL reports GL_NO_ERROR.

Here is the setup function

    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, &screenTexture);
    glBindTexture(GL_TEXTURE_2D, screenTexture);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

    GLuint vs = glCreateShader(GL_VERTEX_SHADER);
    const GLchar* vs_source = shaderLoadFile("vert.glsl");

    glShaderSource(vs, 1, &vs_source, NULL);
    glCompileShader(vs);
    checkShader(vs);

    GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
    const GLchar* fs_source = shaderLoadFile("frag.glsl");

    glShaderSource(fs, 1, &fs_source, NULL);
    glCompileShader(fs);
    checkShader(fs);

    prog = glCreateProgram();
    glAttachShader(prog, vs);
    glAttachShader(prog, fs);

    glLinkProgram(prog);
    glUseProgram(prog); 

And helper functions for reading the shader source:

FILE *f = fopen(file, "rb");
if (f == NULL)
{
    std::cout<<"Error: Unable to locate shader files.\n";
    exit(-1);
    return NULL;
}

fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, 0, SEEK_SET);
char* ret = new char[size+1];
fread(ret, size, 1, f);
fclose(f);
ret[size] = '\0';
return ret;

And the Shaders themselves

    //vertex shader
void main() 
{
    glTexCoord[0] = gl_MultiTexCoord0;
}
     //frag shader
uniform sampler2D screenTex;
void main()
{
    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); 
}

Edit: I just figured this out. It seems the problem was that I had no graphics context when making these calls.


回答1:


It seems the problem was that I had no graphics context when making these calls. I believe this explains the reason no error was being produced but the shaders failed compiling.



来源:https://stackoverflow.com/questions/8610534/problems-compiling-shader-source-within-osg-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!