我的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);
}
哪些部分不正确?请帮帮我!
答案 0 :(得分: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
}