View Full Version : Not using glutSwapBuffers
01-16-2012, 08:02 PM
Hi. When I am trying to draw something it would not draw.
It would expect me to swaf the buffers.
However, it is very inconvinient as it will swap the buffer not once for the specific data I want but for everything.
How can write on the top buffer without swapping the buffers.
note: I have already swapped the buffers in other places. I am doing stuff on the front buffer now.
01-17-2012, 06:27 AM
drawing to the front buffer is not recommended on Windows (7) platform because of the driver model.
What is it you are actually trying to do that requires drawing to the front buffer?
Would drawing to a FrameBufferObject be what you want to do - as that is supported and very well on many implementations.
01-17-2012, 06:53 AM
sorry about the terminology.
I have drawn and now i need to use glutSwapBuffers(); to bring the thing to front. But since the function is called from the mouse function, the buffers swap each time i click. But i dont want that to happen.
How can i avoid it?
01-17-2012, 08:21 AM
You gave yourself the answer:
But since the function is called from the mouse function, the buffers swap each time i click. But i dont want that to happen.
Don't call it from the mouse function. It's your code; if something's not being called from the right place, change it.
You should only swap buffers at the end of your drawing routine.
01-17-2012, 09:03 AM
Yea but I have to since the function should be called when clicked. or should I make a new function? I will try it.
01-17-2012, 09:08 AM
What you want is to have FreeGLUT call your display function when you click the mouse button. To do that, you call glutPostRedisplay. This tells FreeGLUT to call the display function when it gets the chance to do so.
01-17-2012, 11:04 AM
I dont quite get it:
if (checknewgame == true)
int holder = checkcirclenumber( x ,y);
} in my mouse function
void draw_userselected(int n)
if ((selected %4) == 0)
cor = computepoints( selected);
if (n ==1)
draw_colorcircles (cor.x, cor.y, 1, 0, 0,0.2);
else if (n ==2)
draw_colorcircles (cor.x, cor.y, 0, 0, 0,0.2);
else if (n ==3)
draw_colorcircles (cor.x, cor.y, 1, 1, 0,0.2);
else if (n ==4)
draw_colorcircles (cor.x, cor.y, 0, 1, 0,0.2);
else if (n ==5)
draw_colorcircles (cor.x, cor.y, 0, 0, 1,0.2);
else if (n ==6)
draw_colorcircles (cor.x, cor.y, 1, 1, 1,0.2);
this is the drawinf function. what should I change?
01-17-2012, 04:57 PM
Generally you should draw everything and swapbuffers every frame; it's the most efficient way, gives you the cleanest code, and your GPU will thank you for it. Tricks to get around it, like drawing to the front buffer or using an FBO, will only cause trouble longer term or introduce unnecessary complexity to solve what is really a very very simple problem.
So, the way forward from here is to rearchitect your code. If you want to draw something when the mouse is clicked, in your click event you just set a flag. Optionally also store the click location. Then when in your normal drawing routine you check if that flag is set and - if so - draw the object.
If you want multiple such objects you store each in a list of some kind (an std::vector would be perfect for this) and iterate through the list drawing them all.
Every frame: check input, record input events, draw entire scene, swap buffers.
Don't worry overmuch about performance at this stage - doing so is definitely in the realm of premature optimization (I bet you wouldn't even notice any difference anyway). Even a low-end GPU from a few years back is capable of drawing the kind of scene I bet you're drawing at a coupla thousand frames per second.
01-17-2012, 06:25 PM
in my mouse function
Your mouse function should not be drawing anything at all. If things need to be drawn, your drawing function should draw them. Your mouse function should store whatever information you need to draw things at the proper place.
You should store `holder` in a global or something, then use `glutPostRedisplay` to cause your display code to be executed. That is where you should call `draw_userselected`
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.