In my mousefunc i call a function bspline. It works like this: With your mouse you can put controllpoints and according to these points the bspline is drawn.So if you have drawn three points a curve between those points is displayed. By adding another point the old curve disappears and a new one appears. This new one lies now between the four points.This works just fine. BUT: This bspline curve is only displayed in one viewport.This viewport has a black border. This border disappears when my bspline is redrawn. This happens because of calling glutPostredisplay. Because in my glutDisplayFunc i call glClear(GL_COLOR_BUFFER_BIT). So it is the natural thing to happen. If i delete the glClear(GL_COLOR_BUFFER_BIT) in my displayfunc the border stays but the old curves stay too. Even if i say that the border should be redrawn nothing happens. I cant think of an alternative. Would appreciate it if you could help me...
Asked
Active
Viewed 241 times
1 Answers
1
In OpenGL the usual approach is to rerender the whole scene whenever some part of it changes. In your case changing the control points of the B-Spline should trigger a redisplay of the scene instead of perform drawing operations in the mouseclick handler function.
OpenGL has no geometry persistency, it just draws primitves to a pixelbased framebuffer. And as such you must use it.
To clarify, some pseudocode:
BSpline *b_spline;
void on_mouseclick(int x, int y)
{
float x_, y_;
transform_screen_to_scene(x,y, &x_, &y_);
bspline_add_control_point(b_spline, x_, y_);
trigger_redisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
setup_viewport_and_projection();
bspline_draw(b_spline);
swap_buffers();
}

datenwolf
- 159,371
- 13
- 185
- 298