[英]Why isn't this texture repeating in iOS OpenGL ES 2.0?
I have a class which renders a textured 2D shape onto the screen in iOS. 我有一个类,可在iOS屏幕上呈现带纹理的2D形状。 If I use texture coordinates less than 1.0, the texture scales appropriately to match the coordinates.
如果我使用的纹理坐标小于1.0,则纹理会适当缩放以匹配坐标。 However, if I use texture coordinates of more than 1.0, the texture scales correctly, but doesn't repeat itself as I expected.
但是,如果我使用的纹理坐标大于1.0,则纹理会正确缩放,但不会像我期望的那样重复自身。 Instead, it just draws the texture once and repeats the edge pixels across the rest of the shape (I do hope that makes sense :/ )
取而代之的是,它只绘制一次纹理,并在形状的其余部分重复边缘像素(我希望这是有意义的:/)
Is there a way to turn on Repeating Textures in OpenGL ES 2.0 with GLKit? 有没有办法使用GLKit在OpenGL ES 2.0中启用“重复纹理”?
The rendering function is: 渲染功能为:
-(void)render
{
// If we have a texture set, setup the Texture Environment Mode
if (texture != nil) {
self.effect.texture2d0.envMode = GLKTextureEnvModeReplace;
self.effect.texture2d0.target = GLKTextureTarget2D;
self.effect.texture2d0.name = texture.name;
}
// Perform any Transformations on the Sprite
GLKMatrix4 modelViewMatrix = GLKMatrix4Multiply(
GLKMatrix4MakeTranslation(self.position.x, self.position.y, 0.0f),
GLKMatrix4MakeRotation(GLKMathDegreesToRadians(self.rotation), 0, 0, 1)
);
self.effect.transform.modelviewMatrix = modelViewMatrix;
// Prepare to Draw
[self.effect prepareToDraw];
// Setup the Vertices
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
// Setup the Texture Coordinates
if (texture != nil) {
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.texCoords);
}
// Enable Alpha Blending for Transparent PNGs
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Draw the Triangle Strip from the Vertex Array
glDrawArrays(GL_TRIANGLE_STRIP, 0, self.numVertices);
// Disable Alpha Blending
glDisable(GL_BLEND);
// Disable Texture Environment
if (texture != nil) {
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
}
glDisableVertexAttribArray(GLKVertexAttribPosition);
}
When you're creating your texture you can set the mode used for handling the edges. 创建纹理时,可以设置用于处理边缘的模式。 Set the mode to REPEAT instead of CLAMP_TO_EDGE (which is apparently the default), like this:
将模式设置为REPEAT而不是CLAMP_TO_EDGE(显然是默认模式),如下所示:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
You need to use glTexParameter to set GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_REPEAT. 您需要使用glTexParameter将GL_TEXTURE_WRAP_S和GL_TEXTURE_WRAP_T设置为GL_REPEAT。
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.