gpt4 book ai didi

ios - UV 更改后纹理不再渲染

转载 作者:行者123 更新时间:2023-11-29 04:59:32 27 4
gpt4 key购买 nike

我打算编写一个纹理图集管理器,但我遇到了问题。当我修改原始 UV 坐标时,我的程序不再渲染任何内容?这是我的抽奖代码:

- (void)drawFrame {
[(EAGLView *)self.view setFramebuffer];

//GLfloat aspectRatio = self.view.bounds.size.height/self.view.bounds.size.width;
float m[16] = {2/self.view.bounds.size.width, 0, 0, 0, 0, 2/self.view.bounds.size.height, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1 };

CGSize imageSize = CGSizeMake(512, 512);
CGRect drawBounds = CGRectMake(0, 0, 106, 126);

GLfloat x = (1/imageSize.width) * drawBounds.size.width;
GLfloat y = (1/imageSize.height) * drawBounds.size.height;

static const GLfloat vertices[] = {
-53.0f, -63.0f,
53.0f, -63.0f,
-53.0f, 63.0f,
53.0f, 63.0f,
};

GLfloat texCoords[] = {
0.0, 0.0,
x, 0.0,
0.0, y,
x, y
};

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glUseProgram(program);

[[TextureLibrary sharedTextureLibrary] bindTexture:@"bounce" toSlot:GL_TEXTURE0];

glUniform1f(uniforms[UNIFORM_TEXTURE], 0);
glUniformMatrix4fv(UNIFORM_MVP_MATRIX, 1, GL_FALSE, m);

glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertices);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_TEXTURE_POSITION, 2, GL_FLOAT, 0, 0, texCoords);
glEnableVertexAttribArray(ATTRIB_TEXTURE_POSITION);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


[(EAGLView *)self.view presentFramebuffer];
}

但是,它可以正常工作,如下所示:

GLfloat texCoords[] = {
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};

帮忙?

最佳答案

只是猜测,但 OpenGL 认为 (0, 0) 是图像的左下角。您的图形是否可能位于左上角,因此您显示的区域实际上来自纹理的透明部分?

如果是这样,那么您可以调整纹理坐标或调整纹理矩阵堆栈,使 (0, 0) 位于左上角。

关于ios - UV 更改后纹理不再渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7277928/

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