You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Texture::Draw(Texture::Pixels) changes the Texture matrix, but Texture::Bind(Texture::Normalized) does not! So the OpenGL uv coordinates are completely off when drawing a Normalized texture after a Pixel-mapped one.
Here's some simple code to reproduce the problem:
#include<SFML/Graphics.hpp>
#include<SFML/OpenGL.hpp>voidDrawQuad(float size)
{
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(-size, -size);
glTexCoord2f(0, 4); glVertex2f(-size, size);
glTexCoord2f(4, 4); glVertex2f( size, size);
glTexCoord2f(4, 0); glVertex2f( size, -size);
glEnd();
}
intmain()
{
sf::Texture texture;
if(!texture.loadFromFile("resources/texture.jpg")) return EXIT_FAILURE;
texture.setRepeated(true);
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.draw(sf::CircleShape()); // to initialize view etc.while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
glLoadIdentity();
glTranslatef(100, 100, 0);
// Bind with type pixels
texture.bind(sf::Texture::Pixels);
DrawQuad(100);
glTranslatef(250, 0, 0);
// Bind normalized - does not work, looks just the same!
texture.bind(sf::Texture::Normalized);
DrawQuad(100);
glTranslatef(250, 0, 0);
// only after manually resetting the texture matrix it works:glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
DrawQuad(100);
window.display();
}
return EXIT_SUCCESS;
}
The text was updated successfully, but these errors were encountered:
Okay. I ran into this when I used OpenGL while also using SFML for 2D rendering (happens with sf::Sprite and sf::Text, for example) - I did not want to do pop/pushGLStates() because that does more than required (and thus is slower), but it took me a while to figure out that resetting the Texture matrix is required.
I do. I meant in my GL code. In order for glTexCoord2f() to work as expected, I need to reset the texture matrix first:
while (window.isOpen())
{
<<event code>>
// SFML Draw code - this could also be after the OpenGL part
window.draw(sprite);
// 3D setup//without resetting the texture matrix, the UV coordinates would be wrong.glMatrixMode(GL_TEXTURE);
glLoadIdentity();
<< more OpenGL setup - Depth Buffer enabling, projection matrix etc. >>
glEnable(GL_TEXTURE_2D);
texture.bind(sf::Texture::Normalized); // does not change the matrix
<< draw something textured >>
glTexCoord2f(0, 1); [...]
// 2D/SFML Setup
window.resetGLStates();
window.display();
}
But from what you explained this is the intended behaviour. Is it documented anywhere?
The Texture::Draw(Texture::Pixels) changes the Texture matrix, but Texture::Bind(Texture::Normalized) does not! So the OpenGL uv coordinates are completely off when drawing a Normalized texture after a Pixel-mapped one.
Here's some simple code to reproduce the problem:
The text was updated successfully, but these errors were encountered: