简体   繁体   English

定期在单个图像上加载两个纹理-GLkit openglES

[英]Load a two texture for a single image at a regular interval of time - GLkit openglES

I used the below code to load the texture on a object. 我使用以下代码将纹理加载到对象上。

- (void)ldText:(UIImage *)Image
{
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    CGImageRef cgImage = Image.CGImage;
    float Width = CGImageGetWidth(cgImage);
    float Height = CGImageGetHeight(cgImage);
    CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, CFDataGetBytePtr(data));
}

The texture is getting mapped properly. 纹理已正确映射。

I need to load two textures now. 我现在需要加载两个纹理。 And the textures should get changed at regular interval of time. 并且纹理应该定期更改。 Is it possible? 可能吗? Can Some one guide me how to proceed from here? 有人可以指导我如何从这里继续吗?

* Update: I loaded another texture with Image2, with the function ldText2. * 更新: 我使用功能ldText2使用Image2加载了另一个纹理。 And updating it in each "update view". 并在每个“更新视图”中对其进行更新。 Now I get two textures on the same object and getting changed whenever the "update" function is called. 现在,我在同一个对象上获得了两个纹理,并且每当调用“更新”函数时都将对其进行更改。 I interchange the texture1 and texture2 each time when the "Update" function is called. 每次调用“更新”功能时,我都会互换Texture1和Texture2。 But the problem is time interval! 但是问题是时间间隔! I want it to happen slow. 我希望它发生的慢。 How to set a time interval for this? 如何为此设置时间间隔? * *

By default GLKViewController provides you with an animation loop which calls update based on the preferredFramesPerSecond property. 默认情况下,GLKViewController为您提供了一个动画循环,该循环基于preferredFramesPerSecond属性调用更新。 (The rate actually used is in the framesPerSecond property). (实际使用的速率在framesPerSecond属性中)。

You could gain some control by setting the preferred rate, but you are more likely to want to turn off the animation loop if you want the display to remain static for more than a fraction of a second. 您可以通过设置首选速率来获得一些控制权,但是如果您希望显示器保持静态超过一秒钟的时间,则更有可能希望关闭动画循环。 To do this, set the paused property to YES , and override resumeOnDidBecomeActive to return NO . 为此,请将paused属性设置为YES ,并重写resumeOnDidBecomeActive以返回NO You will then need to make sure display gets called on the view at the appropriate times, either by doing so explicitly or by making sure the enableSetNeedsDisplay property on the view is set to YES , and invalidating the view. 然后,您需要确保在适当的时间在视图上调用display ,方法是显式地执行此操作,或者确保将视图上的enableSetNeedsDisplay属性设置为YES ,并使视图无效。

If you want to keep the animation loop active for other reasons, then Matic Oblak's suggestion of using a delayed selector execution can be applied to either change the texture, or to set a flag to trigger the update method to change the texture. 如果由于其他原因要使动画循环保持活动状态,则可以应用Matic Oblak关于使用延迟选择器执行的建议来更改纹理,或设置标志以触发update方法来更改纹理。

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

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