View Full Version : Rendering a vertex after main program is running
12-19-2007, 06:45 PM
Greetings all. I will first start out by saying that yes I am a newbie with OpenGL so I do apologize for the easy question.
I have looked around online and the forums here and have not really found an answer. My question is, is there a way to draw a vertex (I believe that is the correct term) AFTER the program is already running and being displayed on the screen?
To put it simple, what I am doing is writing a program that pops up an image and then draws a series of lines over it. Unfortunately I can only get it to draw the lines before it pops up the program window.
If anyone can point me to a tutorial or something of the sort online it would be greatly appreciated. Again sorry for the newbie question, I just started working with OpenGL just recently - although I am having lots of fun with it.
12-19-2007, 10:41 PM
Your question is indeed strange... of course you can draw after the window is visible, this is what all games etc. are doing. I can imagine that something went entirely wrong with your program, but it is hard to imagine what the source of your confusion may be.
If you use double buffering, just clear the buffers (using Clear), draw a new scene and show it by swapping the buffers. If you don't use doubel buffering, be sure to call Flush.
Maybe you could post your rendering code?
12-19-2007, 11:56 PM
Ahh, sorry about not posting code. This is what I have (keep in mind it probably looks bad as I am very new at this):
glBegin( GL_QUADS );
Basically what it is doing is drawing a box (GL_QUADS) and then waiting 2 seconds and then drawing lines on top of the box.
Doing what you suggested worked for the most part. For now I just used sleep() to make it wait before it draws the lines on the image. Unfortunately after those 2 seconds, it flashes the lines really quick, then they disappear for another two seconds, and then they finally show up again. Is there another way to have the lines draw a few seconds after without having to use sleep()? as it seems to be a rather unconventional way to do so.
Sorry about this, as I said I'm very new to this, although I am slowly getting the hang of it (I think, haha). Thanks again for any and all help.
12-20-2007, 01:38 AM
Ah, ok, I see :)
I assume that this code runs inside the glut rendering loop. It is important to know, that it is repeated contineously, every several miliseconds. Basically one draws series of frames, just like in the movies. Maybe by now you already understood what you are doing wrong: you draw the box, show it (using SwapBuffers), then wait, draw the line, show it -- and then you repeat it all over again! Hence the "flashing" you observe.
If you want to show the lines after a delay, you will have to incorporate some sort of timer in your code -- but draw it monolitically (without frame change in between). Something like this
// clear the buffer <- important!
glClear(GL_COLOR_BUFFER_BT || GL_DEPTH_BUFFER_BIT);
... draw the box ...
if (... gettime() > starttime() + 2 sec ... ) ... draw the lines ...
Hope it helps
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.