开发者

clash between J3DI, Win7 and Nvidia Geforce

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.vertexAttrib开发者_JAVA百科Pointer(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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜