Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7547797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:32:41+00:00 2026-05-30T09:32:41+00:00

I am making a paint application using OpenGl framework and I’m stuck at UNDO/REDO

  • 0

I am making a paint application using OpenGl framework and I’m stuck at UNDO/REDO option..
The code I implemented is like this:

  -(void)undo_called
{

artbrushAppDelegate *app=(artbrushAppDelegate *)[[UIApplication sharedApplication]delegate];
mbrushscale=app.brushscale;
brushimage=app.brush_image;
Erase=YES;
[self playRayundo];
 }


-(void)playRayundo
{
artbrushAppDelegate *app=(artbrushAppDelegate *)[[UIApplication sharedApplication]delegate];
glColor4f(app.r1g,
          app.b1g,
          app.g1g,
          0);
NSLog(@"%f",app.r1g);


if(undo != NULL)
{
    for(int l = 0; l < [undo count]; l++)
    {
        //replays my writRay -1 because of location point
        for(int p = 0; p < [[undo objectAtIndex:l]count]-1; p ++)
        {
            [self drawErase:[[[undo objectAtIndex:l]objectAtIndex:p]CGPointValue] toPoint:[[[undo objectAtIndex:l]objectAtIndex:p + 1]CGPointValue]];
        }
    }
}

Erase=NO;
glColor4f(app.rg,
          app.bg,
          app.gg,
          kBrushOpacity);

  }



 -(void) drawErase:(CGPoint)start toPoint:(CGPoint)end

 {
    static GLfloat*     eraseBuffer = NULL;
    static NSUInteger   eraseMax = 64;

NSUInteger          vertexCount = 0,
count,
i;

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

// Convert locations from Points to Pixels
CGFloat scale = 1.0;//self.contentScaleFactor;
start.x *= scale;
start.y *= scale;
end.x *= scale;
end.y *= scale;

// Allocate vertex array buffer
if(eraseBuffer == NULL)
    eraseBuffer = malloc(eraseMax * 2 * sizeof(GLfloat));

// Add points to the buffer so there are drawing points every X pixels      
count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / kBrushPixelStep), 1);

for(i = 0; i < count; ++i) 
{
    if(vertexCount == eraseMax) 
    {
        eraseMax = 2 * eraseMax;
        eraseBuffer = realloc(eraseBuffer, eraseMax * 2 * sizeof(GLfloat));
    }

    eraseBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count);
    eraseBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count);
    vertexCount += 1;
  }

  [self ChangebrushPic:brushimage];

 //the erase brush color  is transparent.

glEnable(GL_POINT_SPRITE_OES);
glTexEnvf(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);
glPointSize(64/mbrushscale);

// Render the vertex array

glVertexPointer(2, GL_FLOAT, 0, eraseBuffer);
glDrawArrays(GL_POINTS, 0, vertexCount);


// Display the buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

// at last restore the  mixed-mode
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

 }

This code is not efficient and it has so many faults..Have a look at images before and After Undo.

Before: http://imageshack.us/photo/my-images/577/screenshot20110714at121.png/

After: http://imageshack.us/photo/my-images/200/screenshot20110714at121.png/

So i want to Save image in buffer every time user’s Touch ends and call previous image on UNDO..Can anyone help me how to Store image in buffer and retrieve back on UNDO?? I tried to find its sample code but could not find..

Thanks..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:32:42+00:00Added an answer on May 30, 2026 at 9:32 am

    Ok. I am posting answer to my own Question as so many people seem to refer this question.

    There is an application named TouchPainter and its source code is available. It contains drawing, color blending, Undo/Redo (Amazing..!!), Save/Open drawings..

    Note : It may require very deep level knowledge of Objective C and design pattern (I still do not know what design pattern is. But I found it so I am sharing..). The whole application’s source code is explained in this book “Apress.Pro Objective-C Design Patterns for iOS”.

    I hope it will be helpful to you.. 🙂 Good luck..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a Win32 application with OpenGL in the main window (not using GLUT).
I have been making paint application and i have implemented successfully drawing with paint
I'm using C++ and GDI+ I'm going to be making a vector drawing application
I'm making a WPF application using MVVM pattern. I found sometimes Task is significantly
I'm making a test application for listing movies in a Navigation Based Application using
I am making and application to send data using sockets from an android device
i'm making kinda ms paint application, that draws conture and fill inside.I wrote recursive
I am making a linux application using C++ and it will print info out
I'm making a little web application using PHP and JavaScript and I've come to
I really have a strange situation. I'm making a Linux multi-threaded C application using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.