Создание wGl-контекста openGL для каирской графики

Я пытаюсь создать фиктивный контекст, чтобы выполнить рендеринг с помощью cairo-gl, а затем скопировать эту поверхность в буфер изображения поверхности.

Приведенный ниже код является всего лишь тестом, поэтому я могу оценить, работает ли OpenGL.

Вот что я делаю, но я всегда получаю сообщение об ошибке при создании cairo_device. Ошибка выдается в _cairo_gl_dispatch_init_buffers.

РЕДАКТИРОВАТЬ: На самом деле Каир не может получить _cairo_gl_get_version и _cairo_gl_get_flavor.

HDC hdc = GetDC((HWND)pGraphics->GetWindow());

PIXELFORMATDESCRIPTOR pfd = {
    sizeof(PIXELFORMATDESCRIPTOR),   // size of this pfd  
    1,                     // version number  
    PFD_DRAW_TO_WINDOW |   // support window  
    PFD_SUPPORT_OPENGL |   // support OpenGL  
    PFD_DOUBLEBUFFER,      // double buffered  
    PFD_TYPE_RGBA,         // RGBA type  
    24,                    // 24-bit color depth  
    0, 0, 0, 0, 0, 0,      // color bits ignored  
    0,                     // no alpha buffer  
    0,                     // shift bit ignored  
    0,                     // no accumulation buffer  
    0, 0, 0, 0,            // accum bits ignored  
    32,                    // 32-bit z-buffer  
    0,                     // no stencil buffer  
    0,                     // no auxiliary buffer  
    PFD_MAIN_PLANE,        // main layer  
    0,                     // reserved  
    0, 0, 0                // layer masks ignored  
};
//HDC  hdc;
int  iPixelFormat;

// get the best available match of pixel format for the device context   
iPixelFormat = ChoosePixelFormat(hdc, &pfd);

// make that the pixel format of the device context  
SetPixelFormat(hdc, iPixelFormat, &pfd);


////// create a rendering context  
HGLRC hglrc = wglCreateContext(hdc);

// Test openGL

cairo_surface_t *surface_gl;
cairo_t *cr_gl;
cairo_device_t *cairo_device = cairo_wgl_device_create(hglrc);

surface_gl = cairo_gl_surface_create_for_dc(cairo_device, hdc, 500, 500);
cr_gl = cairo_create(surface_gl);

cairo_set_source_rgb(cr_gl, 1, 0, 0);
cairo_paint(cr_gl);

cairo_set_source_rgb(cr_gl, 0, 0, 0);
cairo_select_font_face(cr_gl, "Sans", CAIRO_FONT_SLANT_NORMAL,
    CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr_gl, 40.0);

cairo_move_to(cr_gl, 10.0, 50.0);
cairo_show_text(cr_gl, "openGL test");

cairo_surface_write_to_png(surface_gl, "C:/Users/Youlean/Desktop/imageGL.png");

cairo_destroy(cr_gl);
cairo_surface_destroy(surface_gl);

0 ответов

Другие вопросы по тегам