J3DI、Win7 和 Nvidia Geforce 之间的冲突

发布于 2024-11-17 18:56:28 字数 2548 浏览 4 评论 0原文

我在WIN 7 64位操作系统下使用J3DI(这是一个webGL库)做了一个球体 和 Nvidia Geforce GT330 M 作为显卡。

首先我用蓝色完成它并且它显示正确。

然后,我尝试在其上制作纹理,但球体如下图所示: http://s1.postimage.org/1ekqrgolg/earth.jpg

当它出现时在 Mac 中是这样的: http://s1.postimage.org/1eksf0138/error.jpg

那么,什么是问题?是来自操作系统、J3DI 还是来自显卡?

有关附加信息,我使用的着色器脚本: 注意:此代码取自 OpenGL 和 HTML5(来自 O'reilly 的视频课程) VertexShader:

  uniform mat4 u_modelViewProjMatrix;
  uniform mat4 u_normalMatrix;
  uniform vec3 lightDir;

  attribute vec3 vNormal;
  attribute vec4 vTexCoord;
  attribute vec4 vPosition;

  varying float v_Dot;
  varying vec2 v_texCoord;

  void main()
  {
    gl_Position = u_modelViewProjMatrix * vPosition;
    v_texCoord = vTexCoord.st;
    vec4 transNormal = u_normalMatrix * vec4(vNormal, 1);
    v_Dot = max(dot(normalize(transNormal.xyz), normalize(lightDir)), 0.3);
  }

PixelShader:

  #ifdef GL_ES
  precision highp float;
  #endif
  uniform sampler2D sampler2d;

  varying float v_Dot;
  varying vec2 v_texCoord;

  void main()
  {
    vec2 texCoord = vec2(v_texCoord.s, v_texCoord.t);
    vec4 color = texture2D(sampler2d, texCoord);
    color += vec4(0.1, 0.1, 0.1, 1);
    gl_FragColor = vec4(color.xyz * v_Dot, color.a);
  }

上下文函数是:

function(context){

    // setup VBOs
    context.enableVertexAttribArray(0);
    context.enableVertexAttribArray(1);
    context.enableVertexAttribArray(2);

    context.bindBuffer(context.ARRAY_BUFFER, context.sphere.normalObject);
    context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);

    context.bindBuffer(context.ARRAY_BUFFER, context.sphere.texCoordObject);
    context.vertexAttribPointer(1, 2, context.FLOAT, false, 0, 0);

    context.bindBuffer(context.ARRAY_BUFFER, context.sphere.vertexObject);
    context.vertexAttribPointer(2, 3, context.FLOAT, false, 0, 0);

    context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, context.sphere.indexObject);

    //constract the model-view * projection matrix
    var mvpMatrix = new J3DIMatrix4(context.perspectiveMatrix);
    mvpMatrix.setUniform(context, context.getUniformLocation(context.program, "u_modelViewProjMatrix"), false);
    //bind texture
    context.bindTexture(context.TEXTURE_2D, this.texture);
    context.drawElements(context.TRIANGLES, context.sphere.numIndices, context.UNSIGNED_SHORT, 0);
}

我真的很关心这个问题。

I have done a sphere using J3DI (which is a webGL library) under WIN 7 64bit as OS
and Nvidia Geforce GT330 M as graphic card .

firstly I have done it in blue color and it appeared correctly.

then, I tried to make a texture on it but the sphere appeared like in this image:
http://s1.postimage.org/1ekqrgolg/earth.jpg

while it has appeared in Mac like this :
http://s1.postimage.org/1eksf0138/error.jpg

so, what is the problem? is it from the OS, J3DI or from the graphic card?

for an additional information, the shader script i used this:
notice:this code has been taken from OpenGL and HTML5 (video course from O'reilly)
VertexShader:

  uniform mat4 u_modelViewProjMatrix;
  uniform mat4 u_normalMatrix;
  uniform vec3 lightDir;

  attribute vec3 vNormal;
  attribute vec4 vTexCoord;
  attribute vec4 vPosition;

  varying float v_Dot;
  varying vec2 v_texCoord;

  void main()
  {
    gl_Position = u_modelViewProjMatrix * vPosition;
    v_texCoord = vTexCoord.st;
    vec4 transNormal = u_normalMatrix * vec4(vNormal, 1);
    v_Dot = max(dot(normalize(transNormal.xyz), normalize(lightDir)), 0.3);
  }

PixelShader:

  #ifdef GL_ES
  precision highp float;
  #endif
  uniform sampler2D sampler2d;

  varying float v_Dot;
  varying vec2 v_texCoord;

  void main()
  {
    vec2 texCoord = vec2(v_texCoord.s, v_texCoord.t);
    vec4 color = texture2D(sampler2d, texCoord);
    color += vec4(0.1, 0.1, 0.1, 1);
    gl_FragColor = vec4(color.xyz * v_Dot, color.a);
  }

the context function is:

function(context){

    // setup VBOs
    context.enableVertexAttribArray(0);
    context.enableVertexAttribArray(1);
    context.enableVertexAttribArray(2);

    context.bindBuffer(context.ARRAY_BUFFER, context.sphere.normalObject);
    context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);

    context.bindBuffer(context.ARRAY_BUFFER, context.sphere.texCoordObject);
    context.vertexAttribPointer(1, 2, context.FLOAT, false, 0, 0);

    context.bindBuffer(context.ARRAY_BUFFER, context.sphere.vertexObject);
    context.vertexAttribPointer(2, 3, context.FLOAT, false, 0, 0);

    context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, context.sphere.indexObject);

    //constract the model-view * projection matrix
    var mvpMatrix = new J3DIMatrix4(context.perspectiveMatrix);
    mvpMatrix.setUniform(context, context.getUniformLocation(context.program, "u_modelViewProjMatrix"), false);
    //bind texture
    context.bindTexture(context.TEXTURE_2D, this.texture);
    context.drawElements(context.TRIANGLES, context.sphere.numIndices, context.UNSIGNED_SHORT, 0);
}

I'm really concern about this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在我安 2024-11-24 18:56:28

你快到了。在:

v_Dot = max(dot(normalize(transNormal.xyz), normalize(lightDir)), 0.3);

将末尾的 0.3 更改为 1.0,应该可以工作(编辑:至少对于 Windows,MAC 可能是过时的驱动程序)。

You're almost there. In:

v_Dot = max(dot(normalize(transNormal.xyz), normalize(lightDir)), 0.3);

Change 0.3 at the end to 1.0, that should work (edit: at least for Windows, MAC could be outdated drivers).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文