Draw red example triangle
This commit is contained in:
@@ -17,6 +17,11 @@
|
||||
#include <gtk-graph-view.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <shimatta-opengl-program.h>
|
||||
#include <shimatta-opengl-colored-triangle.h>
|
||||
|
||||
#ifndef SHADER_DIRECTORY
|
||||
#define SHADER_DIRECTORY "/usr/share/gtk-graph-view/shaders"
|
||||
#endif
|
||||
|
||||
struct _GtkGraphView {
|
||||
GtkBox super;
|
||||
@@ -29,6 +34,9 @@ typedef struct {
|
||||
*/
|
||||
GtkWidget *gl_area;
|
||||
GdkRGBA background_color;
|
||||
ShimattaOpenglProgram *passthrough_prog;
|
||||
ShimattaOpenglGraphics *test;
|
||||
|
||||
} GtkGraphViewPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GtkGraphView, gtk_graph_view, GTK_TYPE_BOX)
|
||||
@@ -59,6 +67,9 @@ static gboolean gl_render(GtkGLArea *gl_area, GdkGLContext *context, GtkGraphVie
|
||||
|
||||
gl_area_set_clear_color(gl_area, &priv->background_color);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
shimatta_opengl_graphics_draw(priv->test);
|
||||
|
||||
glFlush();
|
||||
|
||||
return TRUE;
|
||||
@@ -91,6 +102,16 @@ static void gtk_graph_view_set_property(GObject *obj, guint property_id, const G
|
||||
}
|
||||
}
|
||||
|
||||
void gtk_graph_view_dispose(GObject *obj)
|
||||
{
|
||||
GtkGraphView *graph_view = GTK_GRAPH_VIEW(obj);
|
||||
GtkGraphViewPrivate *priv = gtk_graph_view_get_instance_private(graph_view);
|
||||
|
||||
if (priv->gl_area)
|
||||
gtk_gl_area_make_current(GTK_GL_AREA(priv->gl_area));
|
||||
g_clear_object(&priv->passthrough_prog);
|
||||
}
|
||||
|
||||
static GParamSpec *gtk_graph_view_properties[N_PROPERTIES] = {NULL};
|
||||
|
||||
/**
|
||||
@@ -104,6 +125,7 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *klass)
|
||||
oclass = G_OBJECT_CLASS(klass);
|
||||
oclass->set_property = gtk_graph_view_set_property;
|
||||
oclass->get_property = gtk_graph_view_get_property;
|
||||
oclass->dispose = gtk_graph_view_dispose;
|
||||
|
||||
gtk_graph_view_properties[PROP_BG_COLOR] =
|
||||
g_param_spec_boxed("background-color", "background color", "Background color of Graph View",
|
||||
@@ -112,11 +134,38 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *klass)
|
||||
g_object_class_install_properties(oclass, N_PROPERTIES, gtk_graph_view_properties);
|
||||
}
|
||||
|
||||
static void gl_area_realize(GtkGLArea *area, gpointer data)
|
||||
static void gl_area_realize(GtkGLArea *area, GtkGraphView *graph_view)
|
||||
{
|
||||
(void)data;
|
||||
gtk_gl_area_make_current(area);
|
||||
GtkGraphViewPrivate *priv;
|
||||
char error_text[512];
|
||||
int status;
|
||||
const vec3 color = {1.0f, 0.0f, 0.0f};
|
||||
const vec3 vertecies[3] = {
|
||||
{-0.5f, 0.0f, 0.0f},
|
||||
{0.5f, 0.0f, 0.0f},
|
||||
{0.0, 0.5f, 0.0f},
|
||||
};
|
||||
|
||||
gtk_gl_area_make_current(area);
|
||||
priv = gtk_graph_view_get_instance_private(graph_view);
|
||||
|
||||
priv->passthrough_prog = shimatta_opengl_program_new_from_file(SHADER_DIRECTORY"/passthrough3d.vertex.glsl",
|
||||
NULL,
|
||||
SHADER_DIRECTORY"/monochrome.fragment.glsl");
|
||||
status = shimatta_opengl_program_compile(priv->passthrough_prog, error_text, sizeof(error_text));
|
||||
if (status) {
|
||||
g_warning("Error compiling shader: %s", error_text);
|
||||
}
|
||||
|
||||
priv->test = shimatta_opengl_colored_triangle_new(priv->passthrough_prog, color, vertecies);
|
||||
shimatta_opengl_graphics_realize(priv->test);
|
||||
}
|
||||
|
||||
static void gl_area_resize(GtkGLArea *area, GtkGraphView *graph_view)
|
||||
{
|
||||
(void)graph_view;
|
||||
|
||||
gtk_gl_area_queue_render(area);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +182,7 @@ static void gtk_graph_view_init(GtkGraphView *obj)
|
||||
priv->gl_area = gtk_gl_area_new();
|
||||
g_signal_connect(priv->gl_area, "render", G_CALLBACK(gl_render), obj);
|
||||
g_signal_connect(priv->gl_area, "realize", G_CALLBACK(gl_area_realize), obj);
|
||||
g_signal_connect(priv->gl_area, "resize", G_CALLBACK(gl_area_resize), obj);
|
||||
gtk_container_add(GTK_CONTAINER(obj), priv->gl_area);
|
||||
gtk_box_set_child_packing(GTK_BOX(obj), priv->gl_area, TRUE, TRUE, 0, GTK_PACK_START);
|
||||
gtk_widget_show(priv->gl_area);
|
||||
|
Reference in New Issue
Block a user