我有256 * 256的纹理,一切都很好,但是试图在整个四边形上映射整个纹理的部分被破坏了。
我的四边形从左到右仅为1/5纹理,其余为黑色,这意味着没有纹理
纹理部分一般都像它一样工作
glFrontFace 未受影响(默认)
纹理创建:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
GLfloat quad_pos[] =
{
0.5, 0.5, 0.0,
-0.5, 0.5, 0.0,
0.5,-0.5, 0.0,
-0.5,-0.5, 0.0
};
//Maybe i need 5 and 6 verticles tex coords?
GLfloat quad_tex[]=
{
0.0, 1.0,
0.0, 0.0,
1.0, 1.0,
1.0, 0.0
};
GLfloat quad_col[]=
{
0.0, 1.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 1.0
};
//In draw_quad method()
//Binding texture and setting uniforms/attributes skipped
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
顶点着色器
attribute vec4 av_col;
attribute vec4 av_pos;
attribute vec2 av_tex;
varying vec4 vv_col;
varying vec2 vv_tex;
uniform mat4 um_mvp;
void main()
{
vv_col = av_col;
vv_tex = av_tex;
gl_Position = um_mvp * av_pos;
}
片段着色器
precision lowp float;
uniform sampler2D us_tex;
varying vec4 vv_col;
varying vec2 vv_tex;
void main()
{
gl_FragColor = (vv_col * texture2D(us_tex, vv_tex));
}
如果将tex coords改为
GLfloat quad_tex[]=
{
0.0, 0.2,
0.0, 0.0,
0.2, 0.2,
0.2, 0.0
};
Quad将完全纹理化并着色,但纹理将被过度缩放(Minecraft像素样式)。
答案 0 :(得分:1)
Quad将完全纹理化并着色,但纹理将被过度缩放(Minecraft像素样式)
听起来好像您启用了默认GL_NEAREST
过滤功能。请尝试使用GL_LINEAR
:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml