简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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