OpenGL ES:在像素绘画应用程序中撤消 [英] OpenGL ES: Undo in a Pixel Painting App

查看:162
本文介绍了OpenGL ES:在像素绘画应用程序中撤消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款应用程序,允许用户使用OpenGL ES绘制像素化图像,但我不知道如何实现撤消功能。
我怎么能这样做?我想过为每个像素使用一个图像并将其添加到一个数组中。基本上,我如何存储我用作像素的矩形?

I'm currently working on an app that allows the user to draw pixelated images using OpenGL ES, but I don't know how to implement an undo function. How could I do it? I thought of using an image for every pixel and adding it to an array. Basically, how can I store the rectangles I use as pixels?

推荐答案

你可以尝试:

    NSData *data = [NSData dataWithBytes:vertexBuffer length:vertexCount * sizeof(GL_FLOAT) * 2] ;
if (self.vertexBuffers == nil) self.vertexBuffers = [[NSMutableArray alloc] init];
[self.vertexBuffers addObject:data];

save every draw point to a array;

if undo 




  1. 清除旧的缓冲区

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);


  • 数组中删除点数;

    for (int i = 0; i < 50; ++i)
    {
    [self.vertexBuffers removeLastObject];
    }
    


  • 渲染

  • render

    for (NSData *point in self.vertexBuffers)
    {
        NSUInteger count = point.length / (sizeof(GL_FLOAT) * 2);
        glVertexPointer(2, GL_FLOAT, 0, point.bytes);
        glDrawArrays(GL_POINTS, 0, count);
    }
    


  • 显示缓冲区

     glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
     [context presentRenderbuffer:GL_RENDERBUFFER_OES];
    


  • 其他解决方案:
    你可以每次绘制内容时都从OpenGL ES上下文中获取图像,并将其作为图像文件保存在应用程序的包中。这样可以节省应用程序的运行内存。
    按下撤消时,您只需将之前保存的图像绘制到上下文中就可以了。

    other solution: You can grab an image from OpenGL ES context everytime you draw something and save in application's bundle as image file. This saves application's run memory. When undo is pressed you just draw previous saved image into the context and that's it.

    参见 OpenGL ES简单撤消最后绘图

    这篇关于OpenGL ES:在像素绘画应用程序中撤消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆