PDA

View Full Version : Real-time texture modification



etienne.thomas31
01-28-2016, 03:59 AM
Hi everybody,

I'm trying to simulate the propagation of a fire onto a heightmap, i'm using QtCreator with C++ and my version of OpenGL is ES 2.0.
I've got my heightmap rendered, with texture and stuff, it's working fine.
But now i'm stuck, i don't know how to display a texture representing fire over my heightmap.
I've heard about the FBO, and it seems it might but what i'm looking for.
Unfortunately, i've been trying to use this but without any success. So i'm asking for your help.

So long i've been doing this :



//In initializeGL() function

textures = new GLuint[2];
glGenTextures(2,textures);

QImage background(":/terrains/paris_map_texture.png");
background= QGLWidget::convertToGLFormat(background);
glActiveTexture(GL_TEXTURE0); //switch to texture image unit 0
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, background.width(), background.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE, background.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0); //Bind a different texture to this unit

QImage sprite(":/terrains/fire.png");
sprite= QGLWidget::convertToGLFormat(sprite);

//FRAME BUFFER OBJECT
// GLuint FBOID[1];
glGenFramebuffers(1,FBOID);
glBindFramebuffer(GL_FRAMEBUFFER, FBOID[0]);
//TEXTURE FOR FRAME BUFFER OBJECT
glActiveTexture(GL_TEXTURE1); //switch to texture image unit 0
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sprite.width(), sprite.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE, sprite.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
glBindTexture(GL_TEXTURE_2D, 0); //Bind a different texture to this unit



So right here i've got two textures, i can both use them in GLSL, it's working fine.
If i understood well how FBO are working, if i bind a texture to a FBO, any modifiction i will do on the FBO will affect the texture bound it ?
What I want is to display the "sprite" fire texture, but only on some points of my heightmap. And these points will change every 2/3 seconds.
Any idea on how I can do that ? I don't know how to use the FBO in order to do that.

Thank you,
If you have any question which can help you to understand my problem don't hesitate.

Cordially,
Etienne