openGL中的128位纹理不显示(黑屏)

时间:2014-02-17 14:28:56

标签: opengl textures 128-bit

我像这样创建纹理:

GLuint PingPongShader::GenerateTexture()
{

float* pixels = new float[width*height * 4];
for(int i = 0; i < width * height; i+=4)
{
    pixels[i] = 1.0;
    pixels[i+1] = 1.0;
    pixels[i+2] = 1.0;
    pixels[i+3] = 1.0;
}
GLuint t;
glGenTextures(1, &t);
glBindTexture(GL_TEXTURE_2D, t);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, pixels);
delete[] pixels;
LogGLError();
return t;
}

我的显示功能如下:

void display()
{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);
    shader.BindCurrentTexture();
    shader.EnableShader();
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.0f, 0.0f);
        glVertex2f(-1.0f, -1.0f);

        glTexCoord2f(1.0f, 0.0f);
        glVertex2f(1.0f, -1.0f);

        glTexCoord2f(1.0f, 1.0f);
        glVertex2f(1.0f, 1.0f);

        glTexCoord2f(0.0f, 1.0f);
        glVertex2f(-1.0f, 1.0f);

    }
    shader.DisableShader();
    glDisable(GL_TEXTURE_2D);
    glutSwapBuffers();
}

着色器看起来像这样: 顶点:

varying vec2 texture_coordinate;

void main()
{
    // Transforming The Vertex
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader
    texture_coordinate = vec2(gl_MultiTexCoord0);
}

片段:

varying vec2 texture_coordinate; 
uniform sampler2D my_color_texture;

void main()
{
    // Sampling The Texture And Passing It To The Frame Buffer
    gl_FragColor = texture2D(my_color_texture, texture_coordinate);
}

不知怎的,我只是得到一个黑屏,即使像素都是1.0(白色)。我没有看到问题出在哪里:/

1 个答案:

答案 0 :(得分:0)

您正在使用已弃用的函数编写代码。在OpenGL 4.4中,您无法使用glBegin()和朋友。请使用VBO作为顶点和纹理坐标数据。您可以在现代OpenGL教程中查找它。您还可以使用glutInitContextVersion()请求较旧的OpenGL上下文。确保使用OpenGL 2.1或为版本&gt;启用complitability配置文件; 3.0。