-1

I'm having a problem where my textures are being rendered far darker than they actually are, and with a black outline, similar to this question: OpenGL Textures form SDLSurface goes too dark, However that solution isn't working for me, my rendering code is thus:

void BackgroundImage::render(int tile, Point2I offset)
{
//textures are being loaded in another thread.
    texture_mutex.lock();
    glEnable(GL_TEXTURE_2D);
    if(!textures[tile].bind())
    {
        glDisable(GL_TEXTURE_2D);
        texture_mutex.unlock();
        return;
    }

    static GLint vertices[] =
    {
                   0, -Tile::size.y, 0,
        Tile::size.x, -Tile::size.y, 0,
        Tile::size.x,             0, 0,
                   0,             0, 0
    };

    static GLfloat texCoord[] =
    {
        0, 1,
        1, 1,
        1, 0,
        0, 0
    };

    static GLubyte indices[] =
    {
        0, 1, 2,
        0, 2, 3
    };

    glPushMatrix();
    glTranslatef(offset.x, -offset.y, 0);

    glDisable(GL_BLEND);
    glDisable(GL_LIGHTING);
    glDisable (GL_COLOR_MATERIAL);
    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
    glColor3f(1.0f, 1.0f, 1.0f);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer  (3, GL_INT, 0, vertices);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);

    glPopMatrix();

    glDisable(GL_TEXTURE_2D);
    texture_mutex.unlock();
}

Furthermore, the images get darker with every frame rendered until they go completely black (rendered using white as the clear color).

Community
  • 1
  • 1
Patrick Jeeves
  • 371
  • 2
  • 16
  • Are you rendering something else on top of that background? – 1201ProgramAlarm Nov 01 '16 at 16:53
  • @1201ProgramAlarm no, this is the only thing being rendered. – Patrick Jeeves Nov 01 '16 at 17:25
  • Is there OpenGL calls outside that function in the draw loop? – pleluron Nov 01 '16 at 18:22
  • @pleluron there's the standard affair of `glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);`, `glLoadIdentity();` pushing and translating a matrix, but that's it. I tried to eliminate all other variables. – Patrick Jeeves Nov 01 '16 at 18:26
  • I also tried using memset to set every byte of the texture data to 0x88, the color I got was closer to 0x55. (to ensure the texture wasn't just being loaded wrong). – Patrick Jeeves Nov 01 '16 at 18:33
  • I would say it's an issue with your windowing library using the sRGB color space but it shouldn't get darker every frame... – pleluron Nov 01 '16 at 19:42
  • @pleluron Well I'm using Qt, and I thought it couldn't be related to that because it wasn't this dark earlier this month, but when I open any Qt application in valgrind I get bunches of errors from the gpu driver, about using uninitialized values. Could it be that? – Patrick Jeeves Nov 01 '16 at 20:00
  • Also by 'dark', I mean it looks completely black, but if i copy a screenshot into photoshop I can change the levels and reveal that the textures are there. – Patrick Jeeves Nov 01 '16 at 20:15

1 Answers1

0

I found the problem, when loading the texture in the other thread I didn't unbind the texture from the texture slot, instead I just had a slot that I thought the shader couldn't 'see', for lack of a better word. After unbinding it it renders correctly.

Patrick Jeeves
  • 371
  • 2
  • 16