OpenGL ES简单撤消最后绘图 [英] OpenGL ES Simple Undo Last Drawing

查看:182
本文介绍了OpenGL ES简单撤消最后绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何在iPhone屏幕上实现最后一个绘图操作的简单撤消。我首先准备帧缓冲区:

I am trying to figure out how to implement a simple "undo" of last drawing action on the iPhone screen. I draw by first preparing the frame buffer:

[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

然后我准备顶点数组并以这种方式绘制:

I then prepare the vertex array and draw this way:

glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
glDrawArrays(GL_POINTS, 0, vertexCount);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

如何简单撤消上一步操作?我认为必须有一种方法可以保存以前的状态或内置的OpenGL ES功能。

How do I simple undo this last action? There has to be a way to save previous state or an built-in OpenGL ES function, I would think.

谢谢

推荐答案

我知道迟到的答案,但是如果其他人遇到这个问题,我会发布这个。

Late answer I know, but incase anyone else comes upon this, I'll post this anyway.

您还可以选择在每次touchesBegan和touchesMoved调用时将点存储在数组中。如下所示:

You also have the option of storing the points in an array at every touchesBegan and touchesMoved call. As in here:

[currentStroke addObject:[NSValue valueWithCGPoint:point]];

当touchesEnded时,您可以将其移动到另一个可变数组,例如:

And when touchesEnded, you can move this to another mutable array, such as:

[allPoints addObject:allCurrentStroke];

然后,您可以遍历allPoints数组,将每个子数组传递给渲染函数。该方法与存储图像的方法相比具有优点和缺点。首先,它节省了硬盘空间......但是以内存为代价。使用GL_POINTS,你会发现在你点击撤消后需要时间来重绘你的图像...但是你可以轻松地一直撤消到第一次触摸!所以,这取决于你是否想要速度或灵活性...如果有人有更好的撤消方法,请告诉我!

Then, you can iterate through allPoints array, passing each subarray to the rendering function. This method has advantages and disadvantages over the method of storing images. First, it saves on hard drive space... however at a cost of memory. Using GL_POINTS, as you are, you will notice it will take time to redraw your image after you hit undo... however you can undo all the way to the first touch easily! So, it depends if you want speed or flexibility... If anyone has a better method to undo, please let me know!

这篇关于OpenGL ES简单撤消最后绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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