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

懵懂的女人 提交于 2019-12-12 01:29:30

问题


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. 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. But the problem is time interval! I want it to happen slow. How to set a time interval for this?*


回答1:


By default GLKViewController provides you with an animation loop which calls update based on the preferredFramesPerSecond property. (The rate actually used is in the framesPerSecond property).

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. 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.

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.



来源:https://stackoverflow.com/questions/15407033/load-a-two-texture-for-a-single-image-at-a-regular-interval-of-time-glkit-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!