【发布时间】: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 内部定义
【问题讨论】: