GLArea dans la place

This commit is contained in:
Adrien Bourmault 2023-01-26 01:07:07 +01:00
parent 0a494a6b21
commit 64fa82a741
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
4 changed files with 61 additions and 55 deletions

View File

@ -146,3 +146,4 @@ void ui_set_stack(const char *mode);
void ui_send_notification(const char *message);
void ui_send_internal_notification(const char *message);
void ui_close_internal_notification(void);
void ui_setup_glarea();

View File

@ -212,6 +212,7 @@ void graphics_draw(void)
float v[16];
float p[16];
/* Compute the model view projection matrix using the
* rotation angles specified through the GtkRange widgets
*/
@ -222,7 +223,7 @@ void graphics_draw(void)
compute_i(m);
compute_i(v);
glClearColor(0, 0, 0, 1);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Use our shaders */

View File

@ -107,10 +107,16 @@
<object class="GtkStackPage">
<property name="name">run</property>
<property name="child">
<object class="GtkLabel">
<property name="halign">center</property>
<property name="label" translatable="yes">&lt;b&gt;Main zone: run mode&lt;/b&gt;</property>
<property name="use-markup">True</property>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkGlArea" id="run_glarea">
</object>
</child>
<child>
<object class="GtkBox" id="run_controls">
</object>
</child>
</object>
</property>
</object>

View File

@ -143,56 +143,6 @@ static void on_close_window(GtkWidget *widget)
rotation_angles[Z_AXIS] = 0.0;
}
void on_activate(GtkApplication *app, gpointer user_data)
{
GtkWidget *window, *box, *button, *controls;
int i, minor=4, major=0;
window = gtk_application_window_new(app);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 600);
gtk_window_set_title(GTK_WINDOW(window), "GemGL (essais pour Gem-graph en OpenGL)");
g_signal_connect(window, "destroy", G_CALLBACK(on_close_window), NULL);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, FALSE);
gtk_widget_set_margin_start(box, 12);
gtk_widget_set_margin_end(box, 12);
gtk_widget_set_margin_top(box, 12);
gtk_widget_set_margin_bottom(box, 12);
gtk_box_set_spacing(GTK_BOX(box), 6);
gtk_window_set_child(GTK_WINDOW(window), box);
gl_area = gtk_gl_area_new();
gtk_gl_area_set_required_version( GTK_GL_AREA(gl_area), minor, major);
gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major);
gtk_widget_set_hexpand(gl_area, TRUE);
gtk_widget_set_vexpand(gl_area, TRUE);
gtk_widget_set_size_request(gl_area, 100, 200);
gtk_box_append(GTK_BOX(box), gl_area);
// We need to initialize and free GL resources, so we use
// the realize and unrealize signals on the widget
//
g_signal_connect(gl_area, "realize", G_CALLBACK(on_realize), NULL);
g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_unrealize), NULL);
// The main "draw" call for GtkGLArea
g_signal_connect(gl_area, "render", G_CALLBACK(on_render), NULL);
controls = gtk_box_new(GTK_ORIENTATION_VERTICAL, FALSE);
gtk_box_append(GTK_BOX(box), controls);
gtk_widget_set_hexpand(controls, TRUE);
for(i = 0; i < N_AXIS; i++)
gtk_box_append(GTK_BOX(controls), create_axis_slider(i));
button = gtk_button_new_with_label("Fermer");
gtk_widget_set_hexpand(button, TRUE);
gtk_box_append(GTK_BOX(box), button);
g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_destroy), window);
gtk_widget_show(window);
}
/* -------------------------------------------------------------------------- */
struct _GemGraphClientWindow
@ -209,6 +159,8 @@ struct _GemGraphClientWindow
GtkRevealer *toast_revealer;
GtkToggleButton *toast_close_button;
GtkLabel *toast_text;
GtkGLArea *run_glarea;
GtkBox *run_controls;
};
G_DEFINE_FINAL_TYPE (GemGraphClientWindow,
@ -257,6 +209,12 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass)
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
toast_text);
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
run_glarea);
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
run_controls);
}
static void gem_graph_client_window_init(GemGraphClientWindow *self)
@ -264,6 +222,8 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self)
gtk_widget_init_template(GTK_WIDGET(self));
window = self;
ui_setup_glarea();
}
/* -------------------------------------------------------------------------- */
@ -339,3 +299,41 @@ void ui_close_internal_notification(void)
gtk_revealer_set_reveal_child(window->toast_revealer, false);
}
void ui_setup_glarea()
{
int i, minor=4, major=0;
GtkWidget * controls;
gint height;
gint width;
gl_area = GTK_WIDGET(window->run_glarea);
controls = GTK_WIDGET(window->run_controls);
gtk_widget_set_hexpand(gl_area, TRUE);
gtk_widget_set_vexpand(gl_area, TRUE);
gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER);
gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER);
gtk_widget_set_size_request(gl_area, 500, 500);
// We need to initialize and free GL resources, so we use
// the realize and unrealize signals on the widget
//
g_signal_connect(gl_area, "realize", G_CALLBACK(on_realize), NULL);
g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_unrealize), NULL);
// The main "draw" call for GtkGLArea
g_signal_connect(gl_area, "render", G_CALLBACK(on_render), NULL);
gtk_widget_set_hexpand(controls, TRUE);
for(i = 0; i < N_AXIS; i++)
gtk_box_append(GTK_BOX(controls), create_axis_slider(i));
gtk_gl_area_set_auto_render(window->run_glarea, true);
gtk_widget_show(GTK_WIDGET(gl_area));
gtk_gl_area_set_required_version( GTK_GL_AREA(gl_area), minor, major);
gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major);
}