Strange Render Issue after Window resize

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 :slight_smile:

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

Have you compared your code carefully with the ebassi example from

If you dont know, he is the GTK dev, so he knows how to do it.

I assume you just start with D lang, so I wonder why you choose D instead for Example Nim or Rust? Because you think that D GTK support is best? Well that may be true, but I think Rust community is very active too, and I try to support Nim with gintro package…

Hi @StefanSalewski, thanks for your answer!

Yes, I know @ebassi from a long time, I’ve been a eager reader of his blog!

I will definitely check the example you provided, I already looked at it some time ago but I’ll compare my event handling with his.

Regarding the choice of D, well I just wanted something like C/C++, so a familiar language, rather than a new approach, like Rust, which btw I think it’s a great thing, especially for his memory safety and ease of multi threaded programming, to just start out and actually make something with GTK.

Finding the right tool or technology is very difficult, every time you start with something you discover a new approach/paradigm/framework/language that might be a better suit for your project.

I chose D because I saw a Youtube video of a DConf (annual meeting of DLang) in which the author of Tilix (the terminal with tiles) stated that D + GTK would have been a better approach to UI programming than GTK + Vala (which was the language I started programming with) and after a couple of weeks (I tried Vala while working on Akira and D working on my OpenGL project) I have to say that D is a very comfortable language, it’s easy, immediate and overall effective.

In the end, though, I think that the language is not the most important thing, using the UI Library properly is.

I would be happier to find a good “Programming in GTK” resource/book/blogpost rather than a “Programming (in GTK) with X Language” which, in the end, is going to be a language reference plus some basic library usage.

In my opinion Vala is also good, but it is not as fully fledged as D or even Rust. It tries to be high level but sometimes it bothers you with low level stuff that might slow you down.

D is a fairly good compromise, when you understand the basics you can be truly effective.

Btw, I’ll compare my result with @ebassi glarea example and then I’ll update this discussion!

Thanks for the hints!

A quick update: I was able to solve the issue!

My problem was that I was calling the linkGeometry() function (which uploads new data to the GPU and binds the VBO and VBO) before the queueDraw() function.

I simply moved that function call inside the drawCanvas() function, which is in turn inside the Widget’s render() routine.

I think that between the queueDraw() and render() call something happens by means of some OpenGL reset procedure or something. And this happens in particular during the resize phase of the Widget.

The right approach is edit the data model and then call the render function with takes care of uploading new geometry and run the pipeline.

So definitely not a GTK+ related issue in the end!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.