'How to display a image use GTK3's GtkGlArea on win32 platform
Operation System: windows 11
BuildEnv: msys2 + mingw32
GTK Version: 3.24.33
I use GTK3's GtkGLArea widget to display a image on win32 platform, but it didn't work, the window's background color is changed,but image not display, code as follow:
static gboolean render(GtkGLArea *area, GdkGLContext *context)
{
//work, background color changed
glClearColor (0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
cairo_surface_t* surface = cairo_image_surface_create_from_png("./test.PNG");
unsigned char* data= cairo_image_surface_get_data(surface);
//not work
glRasterPos2f(-1,1);
glPixelZoom( 1, -1 );
glDrawPixels(
cairo_image_surface_get_width(surface),
cairo_image_surface_get_height(surface),
GL_BGRA,GL_UNSIGNED_BYTE,data);
cairo_surface_destroy(surface);
return TRUE;
}
static void activate(GtkApplication *app, gpointer user_data)
{
GtkWidget* window;
GtkWidget* gl_area;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "picplayer-gl");
gtk_window_set_default_size(GTK_WINDOW(window), 1920, 1080);
gl_area = gtk_gl_area_new();
gtk_container_add(GTK_CONTAINER(window),gl_area);
g_signal_connect(gl_area,"render",G_CALLBACK(render),NULL);
gtk_widget_show_all(window);
}
int main (int argc, char *argv[])
{
GtkApplication *app;
int status;
app = gtk_application_new("org.gtk3.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
When i use glfw instead of gtk3, the codes work well
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
