gpt4 book ai didi

iphone - glDrawArray 工件

转载 作者:行者123 更新时间:2023-12-03 19:39:16 26 4
gpt4 key购买 nike

我尝试使用 glDrawArray 和 GL_TRIANGLE_STRIP 渲染纹理网格,但绘制时存在伪影,但在屏幕上分布不均匀。

Screenshot of the problem.

这是我使用的代码:

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();

}

知道可能是什么问题吗?

最佳答案

我对 OGL 有点生疏,但你应该更改纹理渲染参数,如下所示:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

关于iphone - glDrawArray 工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6838432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com