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

Author Topic: Cannot draw textured quads after drawing a sprite  (Read 1336 times)

0 Members and 1 Guest are viewing this topic.

ThisGuy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Cannot draw textured quads after drawing a sprite
« 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;
}
 

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Cannot draw textured quads after drawing a sprite
« Reply #1 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>?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ThisGuy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Cannot draw textured quads after drawing a sprite
« Reply #2 on: January 31, 2013, 08:40:08 pm »
Thanks for your help!
I solved my problem by using pushGLStates() & popGLStates().