Hi all,
First of all, I’m new to GTK+ development , I started using it since I wanted to evaluate Dlang for a UI project.
At the same time, I’m starting experimenting with OpenGL.
I’m also new to this Forum, so hello everybody
I created a very basic template application that uses GLArea to create a canvas widget (I’m planning to create a blog post series about that when I’ll have a deeper understandng of the topic).
Everything works fine, it is actually a lot better than using GLFW, simpler and easier, especially with D, which has been a fortunate choice, IMHO.
I’m facing a strange issue with render. I’m able to render the scene properly by using this.queueDraw()
after some changes in the model (e.g updated vertices position).
But when I try to change the scene inside a ButtonPress
callback, I’m not able to get the screen repainted on the first iteration of the function.
And everytime I resize the function (so everytime the OnResize
callback gets called) the screen is not repainted but after the first iteration of the click callback.
I dont’ know if this problem is related with GTK+ or with OpenGL, but the issue is present only after the resize callback gets called.
Maybe it is something related to the way queueDraw()
event is handled? The render function gets called always, both in case the new triangle is drawn or not.
Here is the portion of the “incriminated” code that doesn’t work properly.
bool click(Event event, Widget widget) {
float vertex_x = event.motion.x / (this.width / 2) - 1.0;
float vertex_y = (this.height - event.motion.y) / (this.height / 2) - 1.0;
writefln("x: %f y: %f", vertex_x, vertex_y);
this.userVertices ~= vertex_x;
this.userVertices ~= vertex_y;
count++;
if (count == 3) {
this.vertices = this.userVertices;
// Send new vertices to the GPU
this.linkGeometry();
// Redraw screen
this.queueDraw();
this.userVertices = [];
count = 0;
}
return true;
}
void resize(int newWidth, int newHeight, GLArea area) {
this.width = newWidth;
this.height = newHeight;
}
bool render(GLContext ctx, GLArea a) {
makeCurrent();
// Issue draw commands to the GPU
drawCanvas();
glFlush();
return true;
}
Thanks for the help!
Giacomo