2014-01-17 1 views
1

GTK는 카이로를 사용하여 그림을 그립니다. 그래서 저는 X11 대신에 이미지 (svg, png, ...)를 쓰는 hello world 앱을 만들려고합니다. - 이미지가 비어 있습니다. - 실제 목표 인 X11을 실행하지 않고 시작하면 "** (a.out : 9021) 오류가 발생합니다 : 경고 ** : X를 열 수 없습니다. 디스플레이 "GTK + 창을 이미지로 렌더링하려고 시도합니다.

코드 초안입니다!

#include <string> 
#include <iostream> 
#include <thread> 
#include <chrono> 
#include <cmath> 

#include <cairo.h> 
#include <cairommconfig.h> 
#include <cairomm/context.h> 
#include <cairomm/surface.h> 
#include <gtk/gtk.h> 
#include <gdk-pixbuf/gdk-pixbuf.h> 

int main(int argc, char *argv[]) 
{ 

    gtk_init(&argc, &argv); 
    GtkWidget *window; 
    GtkWidget *button; 
    // GtkWidget *main_window = gtk_initialize(); 

    window = gtk_offscreen_window_new(); 

    button = gtk_button_new_with_label ("Hello World"); 
    gtk_container_add (GTK_CONTAINER (window), button); 
    gtk_widget_show (window); 
    GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(window)); 
    std::cout << "gdk window: " << gdk_window << std::endl; 
    cairo_surface_t * surfp = gdk_offscreen_window_get_surface(gdk_window); 
    std::cout << "Created Window will now draw to png" << std::endl; 

    std::string filename = "image.svg"; 
    double width = 600; 
    double height = 400; 

    Cairo::SvgSurface srfobj(surfp); 

    Cairo::RefPtr<Cairo::SvgSurface> refptr(&srfobj); 

    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(refptr); 

    cr->save(); // save the state of the context 
    cr->show_page(); 

    std::cout << "Wrote SVG file \"" << filename << "\"" << std::endl; 
    std::chrono::milliseconds dura(200); 
    std::this_thread::sleep_for(dura); 

    return 0; 
} 
  • 왜이 코드가 작동하지 않습니다?
  • X11을 실행하지 않고도 gtk 앱을 실행할 수 있습니까? 아니면 그냥 경고를 무시해야합니까?
+1

아마도 : http://stackoverflow.com/questions/4944441/how-to-draw-any-gtk-widget-on-top-of-cairo-surface – drahnr

답변

1

두 질문에 대한 대답은 당신이 출력의 일종없이 GTK + 응용 프로그램을 실행할 수 없다는 것입니다 사용할 수 있습니다. XServer가 필요한 gtk-x11을 사용하고 있습니다. DirectFB 백엔드에서 운이 좋을지 모르지만, 더 이상 유지 관리되는지 여부를 모르기 때문에 나는 숨을 멈추지 않을 것입니다.

Gtk가 XServer없이 실행되지 않으므로 결과 이미지가 비어 있습니다.

관련 문제