SFML community forums

Help => Graphics => Topic started by: Zzuumog on May 31, 2012, 05:08:35 am

Title: SFML -> OpenGL Texture Conversion Not Displaying
Post by: Zzuumog on May 31, 2012, 05:08:35 am
Problem:
Instead of displaying a texture, it displays a white quad.

Description of Problem:
I'm trying to display a simple texture onto a simple 2D square. Unfortunately, I seem to be having a great deal of difficulty and I'm not quite sure why. What I'm doing is using sf::Image and then taking the data and turning it into a OpenGL texture. The drawing goes perfectly and it displays a rectangle properly, however, my problem is that rather than displaying the texture I've specified, it displays white.

Code for loading the texture and converting it is here:
sf::Image Image;
if (!Image.loadFromFile(path)) {
    printf("An error occurred in loading the texture.");
}

glGenTextures(1, &FinalTexture);
glBindTexture(GL_TEXTURE_2D, FinalTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image.getSize().x, Image.getSize().y, 0, GL_RGB, GL_UNSIGNED_BYTE, Image.getPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
 

FinalTexture is defined as:
GLuint FinalTexture;
 

Method of binding & drawing
glBindTexture(GL_TEXTURE_2D, FinalTexture);
        glBegin(GL_QUADS);
            glTexCoord2f(0.f, 0.f); glVertex2f(0.f, 0.f);
            glTexCoord2f(1.f, 0.f); glVertex2f(32.f, 0.f);
            glTexCoord2f(1.f, 1.f); glVertex2f(32.f, 32.f);
            glTexCoord2f(0.f, 1.f); glVertex2f(0.f, 32.f);
        glEnd();
 

Image is loaded properly from what I've gathered using a Sprite

SFML Version: SFML 2.0 RC

Does anyone see anything wrong with what I'm doing? I've looked at quite a few example of OpenGL texture loading and this is what I've ascertained from them.

~Thanks
Title: Re: SFML -> OpenGL Texture Conversion Not Displaying
Post by: Laurent on May 31, 2012, 08:14:13 am
GL_RGB should be GL_RGBA, your source image has an alpha channel.

Don't hesitate to play with the OpenGL example, which does exactly what you want -- and works.
Title: Re: SFML -> OpenGL Texture Conversion Not Displaying
Post by: Zzuumog on May 31, 2012, 08:38:18 pm
Thank you, sir, for your help. Switching to gluBuild2DMipmaps fixed the problem for me.
Title: Re: SFML -> OpenGL Texture Conversion Not Displaying
Post by: Laurent on May 31, 2012, 09:31:18 pm
Ah, true. If you use mipmaps (GL_LINEAR_MIPMAP_LINEAR) then you must build them :)

But you shouldn't need it for 2D drawing.