SFML community forums

Help => General => Topic started by: KaboomKaboom on May 20, 2017, 10:01:05 am

Title: texture stretch problem with opengl
Post by: KaboomKaboom on May 20, 2017, 10:01:05 am
Hello. Pretty new here. Anyway I am learning opengl using SFML instead of GLEW and GLFW. Find it pratical to use this. I have a problem on texture tho. Stretching. here is the image

(https://s10.postimg.org/fyfbwg945/sfml.png) (https://postimg.org/image/fyfbwg945/)

I am using this image
(https://learnopengl.com/img/textures/container.jpg)

The size of the original is 512x512. But on my screen its really small but stretch so bad.. Anyway to fix this? thanks


Here is my code
int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);


        sf::Shader shader;
        sf::Clock clock;

        sf::Texture texture;

        if (!texture.loadFromFile("container.jpg", sf::IntRect(10, 10, 200, 200))) {

        }



        sf::VertexArray quad2 = getQuad2();


        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                sf::Time elapsed = clock.getElapsedTime();


                float greenValue = (sin(elapsed.asSeconds())) + 0.5f;
       
                sf::Texture::bind(&texture);
                sf::Shader::bind(&shader);
                shader.setParameter("ourColor", 0.0f, greenValue, 0.0f, 1.0f);
                //window.draw(vertices,6,sf::Quads, &shader);
                window.draw(quad2, &shader);
                window.display();

                clock.restart();
        }

        return 0;
}
Title: Re: texture stretch problem with opengl
Post by: Laurent on May 20, 2017, 11:30:55 am
The way you compute your texture coordinates is probably wrong, but since you don't show it, we can't help.

Many things don't make sense in the rest of your code, so I suggest to read carefully the tutorials, documentation and examples.
Title: Re: texture stretch problem with opengl
Post by: KaboomKaboom on May 20, 2017, 01:57:17 pm
Sorry about the code. I was experimenting with SFML. Anyway this is the link where I base my texture settings

https://www.sfml-dev.org/tutorials/2.4/graphics-sprite.php (https://www.sfml-dev.org/tutorials/2.4/graphics-sprite.php)

Im not sure where is the texture coords configuration there.

Title: Re: texture stretch problem with opengl
Post by: Hapax on May 20, 2017, 04:14:33 pm
The only thing you draw to the window is "quad2", the vertex array, so the creation of that vertex array could be a part of this problem (what does getQuad2 do?).

Your shader doesn't seem to actually ever be loaded so you're drawing the vertex array with an empty shader.