【问题标题】:Printing an image to a dye based application将图像打印到基于染料的应用程序
【发布时间】:2019-03-16 12:35:52
【问题描述】:

我正在学习流体动力学(和 Haxe),遇到了 this 很棒的项目,我想我会尝试扩展到它来帮助我学习。可以在here 看到原始项目的演示。

到目前为止,我已经创建了一个包含不同形状的项目的侧边菜单。当用户单击其中一个形状,然后单击画布时,所选图像应印在染料上。然后用户将移动鼠标并探索艺术等。

为了实现这一点,我做了以下工作:

import js.html.webgl.RenderingContext;

function imageSelection(): Void{        

    document.querySelector('.myscrollbar1').addEventListener('click', function() {
    // twilight image clicked
    closeNav(); 
    reset(); 
    var image:js.html.ImageElement = cast document.querySelector('img[src="images/twilight.jpg"]');
    gl.current_context.texSubImage2D(cast fluid.dyeRenderTarget.writeToTexture, 0, Math.round(mouse.x), Math.round(mouse.y), RenderingContext.RGB, RenderingContext.UNSIGNED_BYTE, image);
    TWILIGHT = true;  

});

在这个调用之后,在更新函数中,我有以下内容:

override function update( dt:Float ){

        time = haxe.Timer.stamp() - initTime;
        performanceMonitor.recordFrameTime(dt);
        //Smaller number creates a bigger ripple, was 0.016
        dt = 0.090;//@!
        //Physics
        //interaction
        updateDyeShader.isMouseDown.set(isMouseDown && lastMousePointKnown);
        mouseForceShader.isMouseDown.set(isMouseDown && lastMousePointKnown);

        //step physics
        fluid.step(dt);

        particles.flowVelocityField = fluid.velocityRenderTarget.readFromTexture;

        if(renderParticlesEnabled){
            particles.step(dt);
        }

//Below handles the cycling of colours once the mouse is moved and then the image should be disrupted into the set dye colours.

}

但是,尽管项目已构建,但我似乎无法将图像印在画布上。我检查了控制台日志,可以看到以下错误:

WebGL:INVALID_ENUM:texSubImage2D:无效的纹理目标

假设我的第一个参数是不允许的,这是否安全?

我已经读到纹理目标是第一个参数,INVALID_ENUM 特别意味着其中一个gl.XXX 参数对于该特定功能完全是错误的。

查看文件writeToTexture 声明如下:public var writeToTexture (default, null):GLTexture;。 WriteToTexture 是常规 webgl 句柄的包装器。

我正在使用Haxe version 3.2.1 和Snow 来构建项目。 WriteToTexture 在 HaxeToolkit\haxe\lib\gltoolbox\git\gltoolbox\render 内部定义

【问题讨论】:

    标签: webgl haxe


    【解决方案1】:

    gltoolbox 中的writeToTexture 是GLTexture。对于snow 和snow_web,这在snow.modules.opengl.GL 中定义为:

    typedef GLTexture = js.html.webgl.Texture;
    

    所以我们只是在这里处理js.html.webgl.Texture,或者在本机JS 中处理WebGLTexture。

    这意味着是的,这绝对不是texSubImage2D() 的target、which is specified to take one of the gl.TEXTURE_* constants 的有效值。

    GLenum 指定活动纹理的绑定点(目标)。

    从这个描述中,很明显该参数实际上并不是针对纹理本身的——它只是提供了一些关于如何活动纹理应该被使用的信息。 p>

    然后问题就变成了如何设置“活动”纹理。 bindTexture() 可以用于此。

    【讨论】:

    • 啊,好的,感谢您如此详细地澄清。我想我必须想办法在点击画布时用染料渲染图像!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    相关资源
    最近更新 更多