Reputation: 94
I am building a GUI with GTK3 and I placed GTK_GL_AREA
in it.
This GTK_GL_AREA
is connected to some "render" and "realize" signals.
Anyway when I launch the GUI some parts of the window become black as soon as I hover the mouse over the window. If, then, I hover the mouse over the button widgets they show up again, but neutral parts of the window remains black.
If I expand the window all shows up for a while, but if I hover the mouse over the window it goes black again.
This phenomenon gets worse when I continuously redraw in the GTK_GL_AREA
calling gtk_gl_area_queue_render()
and does not happen when I disable GTK_GL_AREA signals.
I attach some screenshots to let you understand what I described above.
Hope you could give me some hints to avoid this behaviour.
PS. Even when I saw the full window I needed to overlap another window on the GTK one since pressing the print button it became black just before the screenshot acquisition.
EDIT: I am sorry for not having showed you the code in order to reproduce what I meant. The following is a simple code with a GTK_GL_AREA and two buttons. It compiles without any error but when I hover the mouse over one of those buttons some part of the window become blank (in this image on the left how the window should appear, on the right how it appears as soon as I pass the mouse on the lower button).
//file main.cpp
//to compile -> g++ main.cpp -o main `pkg-config --cflags --libs gtk+-3.0` -lGL -lglfw -lglut -lGL -lGLU -lGLEW
#include <iostream>
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <GL/glew.h>
/*Signals prototypes*/
void on_upper_button_clicked (GtkButton *b);
void on_lower_button_clicked (GtkButton *b);
void on_realize(GtkGLArea *area);
gboolean render(GtkGLArea *area, GdkGLContext *context);
/* Widgets declaration*/
GtkWidget *main_window;
GtkWidget *upper_button;
GtkWidget *lower_button;
GtkGLArea *glarea;
GtkBox *box_gl;
/* GLADE builder*/
GtkBuilder *builder;
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
builder = gtk_builder_new_from_file("test.ui");
/* Widgets initialization*/
main_window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
upper_button = GTK_WIDGET(gtk_builder_get_object(builder, "upper_button"));
lower_button = GTK_WIDGET(gtk_builder_get_object(builder, "lower_button"));
glarea = GTK_GL_AREA(gtk_builder_get_object(builder, "glarea"));
/*Signals connection*/
g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect (upper_button, "clicked", G_CALLBACK (on_upper_button_clicked), NULL);
g_signal_connect (lower_button, "clicked", G_CALLBACK (on_lower_button_clicked), NULL);
g_signal_connect (glarea, "realize", G_CALLBACK (on_realize), NULL);
g_signal_connect (glarea, "render", G_CALLBACK (render), NULL);
gtk_widget_show(main_window);
/*gtk_main*/
gtk_main();
return 0;
}
void on_upper_button_clicked (GtkButton *b)
{
printf("UP\n");
}
void on_lower_button_clicked (GtkButton *b)
{
printf("DOWN\n");
}
void on_realize (GtkGLArea *area)
{
gtk_gl_area_make_current (GTK_GL_AREA (area));
return;
}
gboolean render(GtkGLArea *area, GdkGLContext *context)
{
gtk_gl_area_make_current (GTK_GL_AREA (area));
gdk_gl_context_make_current (context);
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return TRUE;
}
And this is the *.ui code generated with GLADE.
<!-- file test.ui -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="main_window">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box_gl">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="upper_button">
<property name="label" translatable="yes">UP</property>
<property name="width_request">60</property>
<property name="height_request">60</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<signal name="clicked" handler="on_upper_button_clicked" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkGLArea" id="glarea">
<property name="width_request">300</property>
<property name="height_request">210</property>
<property name="visible">True</property>
<property name="app_paintable">True</property>
<property name="can_focus">False</property>
<signal name="realize" handler="on_realize" swapped="no"/>
<signal name="render" handler="render" swapped="no"/>
</object>
</child>
<child>
<object class="GtkButton" id="lower_button">
<property name="label" translatable="yes">DOWN</property>
<property name="width_request">60</property>
<property name="height_request">60</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<signal name="clicked" handler="on_lower_button_clicked" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</interface>
Even with this small code I encounter the problem I reported above. I have a more complex code in which I draw a cube in the GTK_GL_AREA. If needed I will post it too.
Upvotes: 0
Views: 600
Reputation: 1
Try running it with another program. Some parsers break unexplainably and its always good to have another. You also could try updating said parser
Upvotes: 0