简体   繁体   English

OpenGL Es 2纹理缩放问题

[英]OpenGL Es 2 texture zooming issue

i am working on OpenGL ES 2.0 for my project,what im trying to do is just give auto zoom of the texture by giving scale value to model matrix.But the problem is,while zooming the texture the edges of texture not maintain the smooth motion instead the edges move step by step motion...can any one give me the solution.... 我正在为我的项目开发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];
}

This is my render function 这是我的渲染功能

If I have understood your description, it sounds like you need to adjust your texture filtering. 如果我了解您的描述,听起来您需要调整纹理过滤。

While _backGroundTxe is still bound during the process where you first create it try adding: 尽管_backGroundTxe在您第一次创建它的过程中仍然被绑定,请尝试添加:

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Alternatively, if you want the texture to look smooth when it zooms out far, you may want to try this instead: 或者,如果希望纹理在缩小时看起来平滑,则可以尝试以下方法:

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

This is a nice introduction to OpenGL texture filtering: http://www.learnopengles.com/android-lesson-six-an-introduction-to-texture-filtering/ It's for Android/Java, but it's trivial to translate it to iOS/C++, just omit all the " GLES20. " 这是OpenGL纹理过滤的不错介绍: http : //www.learnopengles.com/android-lesson-six-an-introduction-to-texture-filtering/适用于Android / Java,但是将其转换为iOS却很简单。 / C ++,只需省略所有“ GLES20”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM