Click here to Skip to main content
Rate this: bad
good
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 20:53pm
prison310
Rate this: bad
good
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.
  Permalink  
Comments
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
good
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:
 
myDrawFunc
vector pos1, pos2
 
glLoadIdentity
glTranslatef(pos1)
-- do the steps to draw object1
..
..
..

 
glLoadIdentity
glTranslatef(pos2)
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 | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2014
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