SFML community forums

Help => Graphics => Topic started by: reDo on November 27, 2012, 08:21:14 pm

Title: Image and OpenGL does not work
Post by: reDo on November 27, 2012, 08:21:14 pm
Hi, I am using Image as texture source from .tga file but it does not work correctly. One texture is working great, but the second, that is loaded first, is showing only by going closer. Where can be the problem please? :-\
sf::Image image;
                image.loadFromFile(matProp.textureFile);
                GLuint generatedTex = 0;
                glGenTextures(1, &generatedTex);
                glBindTexture(GL_TEXTURE_2D, generatedTex);
                glTexImage2D(GL_TEXTURE_2D,
                             0,
                             GL_RGBA,
                             image.getSize().x,
                             image.getSize().y,
                             0,
                             GL_RGBA,
                             GL_UNSIGNED_BYTE,
                             image.getPixelsPtr());
                //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
                glGenerateMipmap(GL_TEXTURE_2D);
                matProp.texture = generatedTex;
(http://i45.tinypic.com/34g7hqv.png)
Title: Re: Image and OpenGL does not work
Post by: eXpl0it3r on November 27, 2012, 10:39:30 pm
It seems to me like clipping/lighting is set in a way that it turns black at a certain distance, but I've no idea how OpenGL works... ;D

Ehrm don't you want to use a real texture: sf::Texture?
There's a difference between sf::Image and sf::Texture; of course if you really want to use the pixel array you need to use a sf::Image, but sf::Texture has a bind() function (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php#ae4063cbdf35eb24645bf5f267ac5b78d), so you can easily use it with your OpenGL code. ;)
Title: Re: Image and OpenGL does not work
Post by: reDo on November 28, 2012, 06:52:42 am
I do not have any lighting there  :D . I had sf::Texture in the first, but I have to change quality so I have to use sf::Image.

// EDIT I have just changed the image size from 204x204 to 128x128 and it works good now :D.
Title: AW: Re: Image and OpenGL does not work
Post by: eXpl0it3r on November 28, 2012, 10:01:50 am
I do not have any lighting there
Well there's definitely some very basic lighting goong on, otherwise the top and left surface of a box wouldn't be darker than the front ine. ;)

// EDIT I have just changed the image size from 204x204 to 128x128 and it works good now :D.
Nof sure why that fixed it, but I'm glad it did. ;)
Title: Re: Image and OpenGL does not work
Post by: reDo on November 28, 2012, 10:31:14 am
No, I do not implement or use any prebuilded lighting, I am sure, I think it is caused by the mipmapping  ;)