OpenGL渲染时为什么会出现白屏

问题描述 投票:0回答:0

我将首先展示我正在使用的系统和 OpenGL 版本!

  • Debian GNU/Linux 9

  • opengl 3.1 台面 18.3.6

我遇到的问题:

代码是在Debian系统下使用qt 5.11版本编写的。 渲染RGBA(RGBA RGBA)数据格式时,显示白屏

显示出错的代码: 问题出在代码的最底层! “glUseProgram”函数返回1282!

const char * vertex_shader =
    "attribute vec4 vertexIn;"
    "attribute vec2 textureIn;"
    "varying vec2 textureOut;"
    "void main(void)"
    "{"
    "   gl_Position = vertexIn;"
    "   textureOut = textureIn;"
    "}";

const char * fragment_shader_ARGB =
    "precision highp float;"
    "varying vec2 textureOut;"
    "uniform sampler2D tex_0;"
    "void main(void)"
    "{"
    "   vec3 rgb; "
    "   rgb.r = texture2D(tex_0, textureOut).r;"
    "   rgb.g = texture2D(tex_0, textureOut).g;"
    "   rgb.b = texture2D(tex_0, textureOut).b;"
    "   gl_FragColor = vec4(rgb, 1.0);"
    "}";

//Create vertex shaders
GLint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertex_shader, nullptr);
glCompileShader(vertexShader);

//Create a fragment shader
GLint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

glShaderSource(fragmentShader, 1, &fragment_shader_ARGB, nullptr);
glCompileShader(fragmentShader);

//Create a shader program object and bind the shader
GLuint shader_programme = glCreateProgram();
glAttachShader(shader_programme, vertexShader);
glAttachShader(shader_programme, fragmentShader);

//Delete a shader
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
        
//Associate a generic vertex attribute index with a named attribute variable
glBindAttribLocation(shader_programme, VERTEX_ATTRIB, "vertexIn");
glBindAttribLocation(shader_programme, TEXTURE_ATTRIB, "textureIn");

//Link shader
glLinkProgram(shader_programme);
glUseProgram(shader_programme);
std::cout<<"glUseProgram: "<<glGetError()<<std::endl;    //After verification, the return value here is 1282

//Gets the uniform variable location
m_iTextureUniform_0 = glGetUniformLocation(shader_programme, "tex_0");   //the return value "m_iTextureUniform_0 " is -1

这是我看到OpenGL helpbook上说的error value的解释,但是我不知道这是为什么:

GL_INVALID_OPERATION(1282):Set when the state for a command is not legal for its given parameters.

我猜是因为没有使用glUseProgram函数导致的,但我不知道为什么会这样,请帮助我,非常感谢!

同样的代码,我在Windows 11系统QT 5.15下可以正常运行,Windows 11系统的OpenGL版本是4.6.

c++ qt opengl opengl-es
© www.soinside.com 2019 - 2024. All rights reserved.