分类存档: opengles

opengles2.0中快速定位贴图是否正确读入

学习opengles2.0中的着色器,结果在贴图那里遇到困难了。

贴图是全黑,无法确认是贴图加载错误还是着色器错误。

可以用以下代码生成测试贴图。

GLuint CreateSimpleTexture2D( )
{
// Texture object handle
GLuint textureId;

// 2×2 Image, 3 bytes per pixel (R, G, B)
GLubyte pixels[4 * 3] =
{
255,   0,   0, // Red
0, 255,   0, // Green
0,   0, 255, // Blue
255, 255,   0  // Yellow
};

// 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, 2, 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 );

return textureId;

}

opengles学习

今天看明白了android sdk中的hellogl2的源码。

gles2.0中使用着色器,一个最简单的gles2.0中至少必须要两个着点器,一个顶点着色器,一个片断着色器。

以下是画线:

glVertexAttribPointer(_postion, 3, GL_FLOAT, false, 0, gTriangleVertices);
glEnableVertexAttribArray(_postion);
glVertexAttribPointer(_color,3,GL_FLOAT,false,0,colors);
glEnableVertexAttribArray(_color);
glDrawArrays(GL_LINES, 0, 2);