Click here to Skip to main content
15,032,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!

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 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!
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. :)

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900