简体   繁体   English

webgl纹理图像源更新

[英]webgl texture image source updating

I make a small project in webgl, I have a texture drawn on a cube, for the moment no problem :) 我在webgl中做了一个小项目,在立方体上绘制了一个纹理,目前没有问题:)

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. 我想做的是,在图像更新时更新纹理而不更新html页面。

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. 我尝试过其他解决方案,如SetInterval或不保存缓存的meta ...但是暂时不起作用。

What I just want is a simple function who force the "re-load" of the image in .jpg periodically. 我只想要一个简单的函数,该函数会定期强制.jpg中的图像“重新加载”。 Can you help me ?? 你能帮助我吗 ??

Thanks a lot for you future answers ! 非常感谢您将来的回答! Have Fun !! 玩得开心 !!

If you already have a textured cube you just call gl.texImage2D with the new image to update the texture 如果您已经具有纹理立方体,则只需使用新图像调用gl.texImage2D即可更新纹理

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

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM