static xcb_gc_t getFontGC(xcb_connection_t *connection,
                          xcb_screen_t *screen,
                          xcb_window_t window,
                          const char *fontName) {

  xcb_font_t font = xcb_generate_id(connection);
  xcb_void_cookie_t fontCookie = xcb_open_font_checked(connection,
                                                      font,
                                                      strlen(fontName),
                                                      fontName);
  testCookie(fontCookie, connection, "can't open font");

  xcb_gcontext_t gc = xcb_generate_id(connection);
  uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
  uint32_t value_list[3];
  value_list[0] = screen->black_pixel;
  value_list[1] = screen->white_pixel;
  value_list[2] = font;

  xcb_void_cookie_t gcCookie = xcb_create_gc_checked(connection,
                                                     gc,
                                                     window,
                                                     mask,
                                                     value_list);
  testCookie(gcCookie, connection, "can't create gc");

  fontCookie = xcb_close_font_checked(connection, font);
  testCookie(fontCookie, connection, "can't close font");

  return gc;
}
Пример #2
0
static void
cursor_set (xcb_connection_t *c,
            xcb_screen_t     *screen,
            xcb_window_t      window,
            int               cursor_id)
{
  uint32_t             values_list[3];
  xcb_void_cookie_t    cookie_font;
  xcb_void_cookie_t    cookie_gc;
  xcb_generic_error_t *error;
  xcb_font_t           font;
  xcb_cursor_t         cursor;
  xcb_gcontext_t       gc;
  uint32_t             mask;
  uint32_t             value_list;

  font = xcb_generate_id (c);
  cookie_font = xcb_open_font_checked (c, font,
                                       strlen ("cursor"),
                                       "cursor");
  error = xcb_request_check (c, cookie_font);
  if (error) {
    fprintf (stderr, "ERROR: can't open font : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }

  cursor = xcb_generate_id (c);
  xcb_create_glyph_cursor (c, cursor, font, font,
                           cursor_id, cursor_id + 1,
                           0, 0, 0,
                           0, 0, 0);

  gc = xcb_generate_id (c);
  mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
  values_list[0] = screen->black_pixel;
  values_list[1] = screen->white_pixel;
  values_list[2] = font;
  cookie_gc = xcb_create_gc_checked (c, gc, window, mask, values_list);
  error = xcb_request_check (c, cookie_gc);
  if (error) {
    fprintf (stderr, "ERROR: can't create gc : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }

  mask = XCB_CW_CURSOR;
  value_list = cursor;
  xcb_change_window_attributes (c, window, mask, &value_list);

  xcb_free_cursor (c, cursor);

  cookie_font = xcb_close_font_checked (c, font);
  error = xcb_request_check (c, cookie_font);
  if (error) {
    fprintf (stderr, "ERROR: can't close font : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }
}
Пример #3
0
static xcb_gc_t
gc_font_get (xcb_connection_t *c,
             xcb_screen_t     *screen,
             xcb_window_t      window,
             const char       *font_name)
{
  uint32_t             value_list[3];
  xcb_void_cookie_t    cookie_font;
  xcb_void_cookie_t    cookie_gc;
  xcb_generic_error_t *error;
  xcb_font_t           font;
  xcb_gcontext_t       gc;
  uint32_t             mask;

  font = xcb_generate_id (c);
  cookie_font = xcb_open_font_checked (c, font,
                                       strlen (font_name),
                                       font_name);

  error = xcb_request_check (c, cookie_font);
  if (error) {
    fprintf (stderr, "ERROR: can't open font : %d\n", error->error_code);
    xcb_disconnect (c);
    return -1;
  }

  gc = xcb_generate_id (c);
  mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
  value_list[0] = screen->black_pixel;
  value_list[1] = screen->white_pixel;
  value_list[2] = font;
  cookie_gc = xcb_create_gc_checked (c, gc, window, mask, value_list);
  error = xcb_request_check (c, cookie_gc);
  if (error) {
    fprintf (stderr, "ERROR: can't create gc : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }

  cookie_font = xcb_close_font_checked (c, font);
  error = xcb_request_check (c, cookie_font);
  if (error) {
    fprintf (stderr, "ERROR: can't close font : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }

  return gc;
}
static void setCursor(xcb_connection_t *connection,
                      xcb_screen_t *screen,
                      xcb_window_t window,
                      int cursorId) {

  xcb_font_t font = xcb_generate_id(connection);
  xcb_void_cookie_t fontCookie = xcb_open_font_checked(connection,
                                                       font,
                                                       strlen("cursor"),
                                                       "cursor");
  testCookie(fontCookie, connection, "can't open font");

  xcb_cursor_t cursor = xcb_generate_id(connection);
  xcb_create_glyph_cursor(connection,
                          cursor,
                          font,
                          font,
                          cursorId,
                          cursorId + 1,
                          0,0,0,0,0,0);

  xcb_gcontext_t gc = xcb_generate_id(connection);

  uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
  uint32_t values_list[3];
  values_list[0] = screen->black_pixel;
  values_list[1] = screen->white_pixel;
  values_list[2] = font;

  xcb_void_cookie_t gcCookie = xcb_create_gc_checked(connection, gc, window, mask, values_list);
  testCookie(gcCookie, connection, "can't create gc");

  mask = XCB_CW_CURSOR;
  uint32_t value_list = cursor;
  xcb_change_window_attributes(connection, window, mask, &value_list);

  xcb_free_cursor(connection, cursor);

  fontCookie = xcb_close_font_checked(connection, font);
  testCookie(fontCookie, connection, "can't close font");
}
Пример #5
0
void draw(xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t window) {
    if (NULL != testcase) {
        DRAW_FUNC pf = (DRAW_FUNC)dlsym(0, testcase);
        if (NULL != pf) {
            fprintf(stderr, "call %s \n", testcase);
            pf();
            return;
        }
    }

    //get_version();
   
    xcb_font_t font = xcb_generate_id(connection);
    xcb_void_cookie_t cookie_font = xcb_open_font_checked(connection, font, strlen(font_name_pattern), font_name_pattern);
    xcb_generic_error_t *error = xcb_request_check(connection, cookie_font);
    if (error) {
        fprintf(stderr, "ERROR: can't open font :%d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }
    
    xcb_gcontext_t gc = xcb_generate_id(connection);
    uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
    uint32_t value_list[3];
    value_list[0] = screen->black_pixel;
    value_list[1] = screen->white_pixel;
    value_list[2] = font;
    xcb_void_cookie_t cookie_gc = xcb_create_gc_checked(connection, gc, window, mask, value_list);
    error = xcb_request_check(connection, cookie_gc);
    if (error) {
        fprintf(stderr, "ERROR: can't create gc: %d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }

    cookie_font = xcb_close_font_checked(connection, font);
    error = xcb_request_check(connection, cookie_font);
    if (error) {
        fprintf(stderr, "ERROR: can't close font: %d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();

    glColor3f(1.0f, 0.0f, 0.0f);
    glRasterPos2f(0.0f, 0.0f);
    glPushAttrib(GL_LIST_BIT);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    static int isFirstCall = 1;
    static GLuint lists;
    if (isFirstCall) {
        lists = glGenLists(128);
    }
#if 1 
    //for (i = 0; i < sizeof(letters)
    glNewList(lists + 'A', GL_COMPILE);
    glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[0]);
    glEndList();
    GLubyte *str = (GLubyte*)"A";
#else
    glXUseXFont(font, 0, 128, lists);
    GLubyte *str = (GLubyte*)"Hello, world.";
#endif
    glListBase(lists);
    glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
    glPopAttrib();
    glFlush();


/*    static int isFirstCall = 1;
    static GLuint lists;
    //load font
    //gen list
    if (isFirstCall) {
        lists = glGenLists(128);
    }

    glXUseXFont(font, 0, 128, lists);
    glListBase(lists);
    char *str = "Hello, world";
    for (; *str!='\0';++str) {
        glCallList(lists + *str);
    }
    glFlush();
    //glDeleteLists(lists, 256);
    //use font
    //draw text
    //unuse font?
    //delete list
    //unload font*/

    cookie_gc = xcb_free_gc(connection, gc);
    error = xcb_request_check(connection, cookie_gc);
    if (error) {
        fprintf(stderr, "ERROR: can't free gc: %d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }
}