Nic*_*ick 2 c graphics opengl-es opengl-es-2.0
我正在使用OpenGL ES 2.0为嵌入式设备开发应用程序.
这是我的片段着色器:
varying vec2 v_texCoord;
uniform sampler2D s_texture;
void main() {
gl_FragColor = texture2D(s_texture, v_texCoord);
}
Run Code Online (Sandbox Code Playgroud)
我正确设置了纹理.出于某种原因,调用glTexImage2D
不会产生我正在寻找的结果.纹理完全是黑色的,而不是填充我提供的数据.
这是我创建纹理的方式:
GLuint textureId;
// 2x2 Image, 3 bytes per pixel (R, G, B)
GLubyte pixels[6 * 3] =
{
255, 0, 0, // Red
0, 255, 0, // Green
0, 0, 255, // Blue
255, 255, 0, // Yellow
0, 255, 255,
255, 0, 255
};
// Use tightly packed data
glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
// Generate a texture object
glGenTextures ( 1, &textureId );
// Bind the texture object
glBindTexture ( GL_TEXTURE_2D, textureId );
// Load the texture
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, 3, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels );
// Set the filtering mode
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
Run Code Online (Sandbox Code Playgroud)
之后,我像这样绑定纹理:
samplerLoc = glGetUniformLocation ( userData->programObject, "s_texture" );
glActiveTexture ( GL_TEXTURE0 );
glBindTexture ( GL_TEXTURE_2D, textureId );
// Set the sampler texture unit to 0
glUniform1i ( samplerLoc, 0 );
Run Code Online (Sandbox Code Playgroud)
我确认顶点和纹理坐标是绑定的,并在调试时传递给着色器.因此,它必须是一个问题s_texture
或glTexImage2D
功能本身.
归档时间: |
|
查看次数: |
4477 次 |
最近记录: |