0

我的 fragment.txt 和 vertex.txt 类型有问题:

我的 Fragmentshader.frag 是:

#version 330

uniform Sampler2D TexImg;
out vec4 frag_colour;
in vec2 Pass_Texcoord;

void main () {
 vec4 color = Texture2D(TexImg ,Pass_Texcoord);
 frag_colour = vec4 (1.0, 0.0, 0.0, 1.0);
}

我的 Vertexshader.frag 是:

#version 330

in vec3 Pos;
in vec3 Texcoord;
out vec2 Poss_Texcoord;

void main () 
{

    gl_Position = vec4(Pos,1.0);
    Poss_Texcoord = vec2(Texcoord,1.0);

}

哪些部分不正确?请帮助我!

4

1 回答 1

1

我已经为你更正了你的着色器并评论了它们的所有错误。

片段着色器:

#version 100                     // OpenGL ES 2.0 uses different version numbers

uniform Sampler2D TexImg;

varying vec2      Pass_Texcoord; // Use varying instead of in for FS inputs
//out vec4        frag_colour;   // Invalid in OpenGL ES 2.0

void main ()
{
  // Interestingly, you do not use this value anywhere so GLSL will treat this as
  //   a no-op and remove this when it comes time to compile this shader.
  vec4 color = texture2D (TexImg, Pass_Texcoord); // Also, use texture2D

  // You must write to gl_FragData [n] or gl_FragColor in OpenGL ES 2.0
  gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);
}

顶点着色器:

#version 100                     // OpenGL ES 2.0 uses different version numbers

attribute vec3 Pos;              // Use attribute instead of in for vtx. attribs
attribute vec3 Texcoord;         // Use attribute instead of in for vtx. attribs

varying   vec2 Poss_Texcoord;    // Use varying instead of out for VS outputs

void main () 
{
  gl_Position   = vec4 (Pos,      1.0);

  /* Constructing a vec2 from 4 components is invalid
  Poss_Texcoord = vec2 (TexCoord, 1.0); */
  Poss_Texcoord = Texcoord.st;   // Use this instead
}
于 2013-09-16T23:50:47.287 回答