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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您的基本设置是否正确。您应该使用大纹理作为画布。任何用户绘画操作都应该只影响该纹理(您将使用 glTexSubImage2D 更新该纹理)。然后在每一帧上,您应该在屏幕上重新绘制该纹理。
一个简单的 N 步撤消系统将包含 N 个纹理/画布的循环列表。
I'm not sure you've got the basic setup right. You should be using a big texture acting as the canvas. Any user painting operations should affect only this texture (which you will be updating with glTexSubImage2D). Then on every frame you should redraw this texture on the screen.
A simple N-steps undo system would consist on a circular list of N textures / canvases.
你可以尝试:
清除旧的
缓冲区
从
数组中删除点;
渲染
显示
缓冲区
其他解决方案:
每次绘制内容时,您都可以从 OpenGL ES 上下文中获取图像,并将其作为图像文件保存在应用程序包中。这节省了应用程序的运行内存。
当按下撤消按钮时,您只需将之前保存的图像绘制到上下文中即可。
请参阅 OpenGL ES 简单撤消上次绘图
you can try :
clear old
buffer
remove point from
array;
render
display
buffer
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.
See OpenGL ES Simple Undo Last Drawing