webgl texture image source updating

1.9k Views Asked by At

I make a small project in webgl, I have a texture drawn on a cube, for the moment no problem :)

But the fact is, that the image is periodly updated keeping the same name. And what I'd like to do, it's to update the texture when the image update without updating the html page.

I have tried different solution as the SetInterval or the meta which doesn't save the cache... but it doesn't work for the moment.

What I just want is a simple function who force the "re-load" of the image in .jpg periodically. Can you help me ??

Thanks a lot for you future answers ! Have Fun !!

2

There are 2 best solutions below

1
On BEST ANSWER

If you already have a textured cube you just call gl.texImage2D with the new image to update the texture

gl.bindTexture(gl.TEXTURE_2D, textureToUpdate);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, newImage);
0
On

Without code it's hard to give you an exact solution to your problem.

            drawingContext.bindTexture(drawingContext.TEXTURE_2D, webGLTexture);

            drawingContext.texImage2D(drawingContext.TEXTURE_2D,
                                        0,
                                        drawingContext.RGBA,
                                        width,
                                        height,
                                        0,
                                        drawingContext.RGBA,
                                        drawingContext.UNSIGNED_BYTE,
                                        newData);

            drawingContext.activeTexture(drawingContext.TEXTURE0);
            drawingContext.uniform1i(webGLUTextureLoc, 0);

            // This will most likely be different for you.
            drawingContext.drawArrays(drawingContext.TRIANGLE_FAN, 0, 4);