sha*_*vey 3 iphone opengl-es cocos2d-iphone
我正在尝试使用glDrawArray和GL_TRIANGLE_STRIP渲染纹理网格,但绘制时会出现伪影,但在屏幕上分布不均匀.
这是我使用的代码:
void draw() {
glDisableClientState(GL_COLOR_ARRAY);
glBindTexture(GL_TEXTURE_2D, tex.name);
glPushMatrix();
glScalef(cell_size, cell_size, 1);
GLfloat vertices[w*8];
{ // populate only once and translate
int i = 0;
for (int x=0; x<w; x++) {
vertices[i++] = x; vertices[i++] = 0;
vertices[i++] = x; vertices[i++] = 1;
vertices[i++] = x+1; vertices[i++] = 0;
vertices[i++] = x+1; vertices[i++] = 1;
}
}
GLfloat texCoords[w*8];
const float off = 1.00f/16.0f;
for (int y=0; y<h; y++) {
int i = 0;
for (int x=0; x<w; x++) {
const int v = tiles[x+y*w];
const float boff = v*off;
texCoords[i++] = boff; texCoords[i++] = 0;
texCoords[i++] = boff; texCoords[i++] = 1;
texCoords[i++] = boff+off; texCoords[i++] = 0;
texCoords[i++] = boff+off; texCoords[i++] = 1;
}
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, w*4);
glTranslatef(0, 1, 0);
}
glPopMatrix();
}
Run Code Online (Sandbox Code Playgroud)
知道可能是什么问题吗?
我在OGL上有点生疏,但你应该改变纹理渲染参数,如下所示:
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
326 次 |
| 最近记录: |