Click here to Skip to main content
11,579,093 members (64,645 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ OpenGL
i am developing a paint like application using opengl with c++. But everytime i draw an object using mouse the previous image or object is lost. how can i solve this please help!
Posted 23-Jun-11 19:53pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is the default behaviour and should be kept this way. You need to redraw your full "model" for each screen. This means that when the user draws a line, instead of immediately drawing, you should keep its properties in memories (along with all previous lines drawn) and trigger a refresh of the screen (in OpenGL, you would most probably have a main loop that refreshes the screen at a specific rate).
In your draw function, you would then need to redraw all your elements.
CPallini at 24-Jun-11 3:50am
[Moved on behalf of the OP]tnx for the replay but how can i store the properties of the drawings properly for later use?
give some clue!
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

From what I understand, each time openGL draws a frame, it culls whatever was there last time. So each frame you need to specify the location/transformation of each object + camera + lights.

In order to display more than 1 object, you'll need a way of storing information about this object that can be used when drawing it.

So, each time you create an object with the mouse, save all the information needed to draw it & add this information to a list(that you create and maintain) of all objects in the scene.

Then when it comes time to draw the scene, just step through the list of created objects, transforming & drawing each one as you go.

simple openGlut pseudocode may resemble:

vector pos1, pos2

-- do the steps to draw object1

do the steps to draw object2

I'm only _very_ new to this, having first tried my hand at openGL earlier this week. But this is the understanding that I (think?!) I have.
Cheers. Smile | :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Peter Leow 135
1 Frankie-C 115
2 OriginalGriff 113
3 Richard MacCutchan 85
4 Afzaal Ahmad Zeeshan 85
0 OriginalGriff 933
1 Sergey Alexandrovich Kryukov 740
2 Abhinav S 573
3 F-ES Sitecore 420
4 Dave Kreskowiak 419

Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100