Hi,
I'm having a small problem in an application, mixing OpenGL and normal SFML draw calls. As soon as I generate a texture (in my case a 3D texture) in OpenGL, it overrides the SFML texture I've loaded. Drawing the texture to the screen (even without any other OpenGL calls than those to generate the texture) just shows a slice of the 3D texture instead.
Minimal code to reproduce:
int main(int argc, char* argv[]) {
sf::RenderWindow window(sf::VideoMode(1280, 720));
GLenum glew_status = glewInit();
if (glew_status) {
std::cout << "GLEW could not be initialized: " << glewGetErrorString(glew_status) << std::endl;
return -1;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glEnable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_3D);
sf::Texture material_texture;
material_texture.loadFromFile("assets/materials/specular.png");
// volume_data, volume_width, volume_height, volume_depth are read from file
GLuint volume_texture;
glGenTextures(1, &volume_texture);
glBindTexture(GL_TEXTURE_3D, volume_texture);
glTexStorage3D(GL_TEXTURE_3D, 1, GL_R16, volume_width, volume_height, volume_depth);
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, volume_width, volume_height, volume_depth, GL_RED, GL_UNSIGNED_SHORT, (void*)volume_data);
while (window.isOpen()) {
sf::Event event;
if (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
break;
}
}
window.clear(sf::Color::Black);
sf::Sprite material(material_texture);
window.draw(material);
window.display();
}
return 0;
}
It's hard to tell since I've tried various combinations. Basically pushing/poping before and after calling OpenGL code, with the recent one looking like this:
int main(int argc, char* argv[]) {
sf::RenderWindow window(sf::VideoMode(1280, 720));
GLenum glew_status = glewInit();
if (glew_status) {
std::cout << "GLEW could not be initialized: " << glewGetErrorString(glew_status) << std::endl;
return -1;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glEnable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_3D);
// volume_data, volume_width, volume_height, volume_depth are read from file
GLuint volume_texture;
glGenTextures(1, &volume_texture);
glBindTexture(GL_TEXTURE_3D, volume_texture);
glTexStorage3D(GL_TEXTURE_3D, 1, GL_R16, volume_width, volume_height, volume_depth);
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, volume_width, volume_height, volume_depth, GL_RED, GL_UNSIGNED_SHORT, (void*)volume_data);
window.pushGLStates();
sf::Texture material_texture;
material_texture.loadFromFile("assets/materials/specular.png");
while (window.isOpen()) {
sf::Event event;
if (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
break;
}
}
window.clear(sf::Color::Black);
sf::Sprite material(material_texture);
window.draw(material);
window.display();
}
return 0;
}
I've also tried the opposite, pushing the gl state after creating the window and popping it after creating the texture but to no effect.