我正在为我的项目开发OpenGL ES 2.0,我试图做的只是通过给模型矩阵赋予比例值来自动缩放纹理。但问题是,在缩放纹理时,纹理的边缘不能维持平滑的运动而不是边缘一步一步地移动...任何人都可以给我解决方案......
(void)render:(CADisplayLink*)displayLink {
_currentScale++;
glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
GLKMatrix4 aspect = [animations getActualScaleForImage:inputImage.size withPortSize:CGSizeMake(self.frame.size.width, self.frame.size.height)];
aspect = GLKMatrix4Scale(aspect,1 + (_currentScale/3000), 1 + (_currentScale/3000) , 0);
glUniformMatrix4fv(_modelViewUniform, 1, 0, aspect.m);
glViewport(0, 0, self.frame.size.width, self.frame.size.height);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,_backGroundTxe);
glUniform1i(_textureUniform, 0);
glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glVertexAttribPointer(_texCoordSlot, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 7));
glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
[_context presentRenderbuffer:GL_RENDERBUFFER];
}
这是我的渲染功能
答案 0 :(得分:0)
如果我理解了您的描述,听起来您需要调整纹理过滤。
虽然在您首次创建它的过程中仍然绑定了_backGroundTxe,但请尝试添加:
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
或者,如果您希望纹理在向外缩放时看起来很平滑,您可能想要尝试这样做:
glGenerateMipmaps(GL_TEXTURE_2D);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
这是对OpenGL纹理过滤的一个很好的介绍:http://www.learnopengles.com/android-lesson-six-an-introduction-to-texture-filtering/它适用于Android / Java,但将它转换为iOS / C ++是微不足道的,只省略所有“ GLES20。”