【发布时间】:2014-12-17 11:24:23
【问题描述】:
在创建纹理 (http://www.webglacademy.com/#5) 的 webglacademy 第 5 篇教程之后,重点是将纹理加载到可行的立方体对象上。
看结果——
谁能告诉我为什么纹理看起来像这样,而它应该完全适合立方体的一面?
这里的演示 - http://kgpk.esy.es/WebGL/(按住鼠标按钮并拖动移动立方体;鼠标滚轮放大/缩小)
使用的纹理 - http://kgpk.esy.es/WebGL/texture.png
代码 - http://kgpk.esy.es/WebGL/WEBGL.js(纹理在 f_IniatializeTextures 函数 [第 209 行] 中加载,该函数使用 f_GetTexture 函数 [第 255 行] 加载纹理,纹理在 f_Animate 函数[第 427 行] 处被投入流中
顶点和片段可以在函数 f_InitializeShaders [line 215] 中找到
base.m_ShaderVertex = [
"attribute vec3 position;", // The position of the point.
"uniform mat4 Pmatrix;", // Projection matrix.
"uniform mat4 Vmatrix;", // Movement matrix from object reference to view reference.
"uniform mat4 Mmatrix;", // Movement matrix.
"attribute vec2 uv;",
"varying vec2 vUV;",
"void main(void) {",
"gl_Position = Pmatrix * Vmatrix * Mmatrix * vec4(position, 1.0);",
"vUV = uv;", // Set color.
"}"
].join("\n");
base.m_ShaderFragment = [
"precision mediump float;",
"uniform sampler2D sampler;",
"varying vec2 vUV;",
"void main(void) {",
"gl_FragColor = texture2D(sampler, vUV);", // Assign the color to pixel with total opaque.
"}"
].join("\n");
谢谢。
【问题讨论】:
-
是否有任何控制台错误?您永远不会缓冲 UV 数据。你有你的位置和索引缓冲区,但 UV 缓冲区不存在。看看:learningwebgl.com/blog/?page_id=1217(第5课)
-
别介意前面的评论,我被代码弄糊涂了。跟着教程走,他们可能错过了标记一些东西。
标签: javascript textures webgl