SFML community forums

Help => Graphics => Topic started by: ThisGuy on January 31, 2013, 06:25:34 pm

Title: Cannot draw textured quads after drawing a sprite
Post by: ThisGuy on January 31, 2013, 06:25:34 pm
I would like to know why the following code does not show a textured quad after it draws a sprite.
Instead it replaces the sprite's texture with the texture which was meant for the quad.

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <Windows.h>
#include <GL\GL.h>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "test", sf::Style::Close);
       
        sf::Texture spriteTexture, testTexture;
        sf::Sprite sprite;

        spriteTexture.loadFromFile("sprite.png");
        testTexture.loadFromFile("texture.png");

        sprite.setTexture(spriteTexture);
       
        glEnable(GL_TEXTURE_2D);

        while(window.isOpen())
        {
                window.clear();
                window.draw(sprite);

                testTexture.bind();

                glBegin(GL_QUADS);
                        glTexCoord2f(0, 0);
                        glVertex2f(-1, -1);

                        glTexCoord2f(1, 0);
                        glVertex2f(0, -1);

                        glTexCoord2f(1, 1);
                        glVertex2f(0, 0);

                        glTexCoord2f(0, 1);
                        glVertex2f(-1, 0);
                glEnd();

                window.display();
        }

        return 0;
}
 
Title: Re: Cannot draw textured quads after drawing a sprite
Post by: Nexus on January 31, 2013, 06:29:24 pm
Take a look at the OpenGL example distributed with SFML, it shows how to combine both. For example, you have to push/pop OpenGL states.

Why do you need <Windows.h>?
Title: Re: Cannot draw textured quads after drawing a sprite
Post by: ThisGuy on January 31, 2013, 08:40:08 pm
Thanks for your help!
I solved my problem by using pushGLStates() & popGLStates().