我正在学习流体力学(和Haxe),并遇到了这令人敬畏的项目,并认为我会尝试扩展到它,以帮助我学习。这里可以看到原始项目的演示。
到目前为止,我已经创建了一个包含不同形状的项目的边菜单。当用户单击其中一个形状时,单击画布,所选图像应印在染料上。然后,用户将移动鼠标,探索艺术等。
为了实现这一点,我做了以下工作:
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;
});在此调用之后,在update函数中,我有以下内容:
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中定义
发布于 2019-03-16 13:16:32
writeToTexture in gltoolbox是GLTexture。对于snow和snow_web,在snow.modules.opengl.GL中将其定义为:
typedef GLTexture = js.html.webgl.Texture;因此,我们只是在这里处理一个js.html.webgl.Texture,或者在本地JS中处理WebGLTexture。
这意味着,是的,这绝对不是texSubImage2D()的target,常量的有效值。
指定活动纹理的绑定点(目标)的
GLenum。
从这个描述中可以明显看出,这个参数实际上并不适用于纹理本身--它只是提供了一些关于如何使用活动纹理的信息。
接下来的问题是如何设置“活动”纹理。bindTexture()可用于此。
https://stackoverflow.com/questions/55196844
复制相似问题