Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: texture stretch problem with opengl  (Read 2621 times)

0 Members and 1 Guest are viewing this topic.

KaboomKaboom

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
texture stretch problem with opengl
« 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



I am using this image


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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: texture stretch problem with opengl
« Reply #1 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.
Laurent Gomila - SFML developer

KaboomKaboom

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: texture stretch problem with opengl
« Reply #2 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

Im not sure where is the texture coords configuration there.


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: texture stretch problem with opengl
« Reply #3 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*