Question

I create the texture like this:

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;
}

My display function looks like this:

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();
}

The shader looks like this: Vertex:

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);
}

Fragment:

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);
}

Somehow I'm only getting a black screen, even though the pixels are all 1.0 (white). I don't see where the problem is :/

Pas de solution correcte

Autres conseils

You are writing code using deprecated functions. In OpenGL 4.4 you can't use glBegin() and friends. Please use VBO for vertex and texture coordinate data. You can look it up in a modern OpenGL tutorial. You can also request older OpenGL context using glutInitContextVersion(). Make sure to use OpenGL 2.1 or enable complitability profile for versions > 3.0.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top