[cairo] trouble with Cairo text in OpenGL

Andrea Canciani ranma42 at gmail.com
Thu Jan 5 03:47:01 PST 2012


On Thu, Jan 5, 2012 at 12:15 PM, Victor henri <nadaeck at hotmail.com> wrote:
> Hello people and thank you for your suport
>
>
> To Bill :
>> Does he need to do cairo_flush(cr) before using the pixels?

Kind of, he needs to flush the drawing operations with cairo_surface_flush().

http://cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-flush

Unfortunately the documentation of cairo_image_surface_get_data()
hasn't been updated yet, otherwise it would provide some useful
information about what needs to be done to actually get the correct
data:
http://cgit.freedesktop.org/cairo/tree/src/cairo-image-surface.c#n529

>>
>  I cannot find this function
>
>
>
>> You did not set the current point before drawing the text, so I think it
>> drew it at 0,0 and you are just seeing the descenders of some letters.
>
> Well I tried to change that also, without succes; I must say that I can see
> the surface at the place I want it to be, but it is just a white rectangle
> with nothing written on it...

You're trying to draw a very big text string on a very small image.
I would suggest you to start using a big destination and a default font.

Saving to png can help you check if the image content is what you need it to be.
For this kind of debugging purposes, cairo provides cairo_surface_write_to_png()
http://cairographics.org/manual/cairo-PNG-Support.html#cairo-surface-write-to-png

Example:

#include <cairo.h>

#define FIXED 1

int main()
{
    cairo_surface_t *surface;
    cairo_t *cr;

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 64, 64);
    cr = cairo_create (surface);
    cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
#if FIXED
    cairo_move_to(cr, 0, 48);
#endif
    cairo_set_font_size (cr, 32.0);
    cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
    cairo_show_text (cr, "HELLO");

    cairo_surface_write_to_png(surface, "gl.png");
    return 0;
}

This is basically the same as (the cairo part of) your code, except
that it starts the text from (0,48), making it visible.
(If you define FIXED to 0, you get a completely transparent image).

If you manage to get the png right, making cairo and GL interact as
desired should only be a matter of choosing the correct pixel format.

Andrea

>
>
>>
>> You may also need to do cairo_surface_flush(surface) before grabbing the
>> image?
>
> I did; no change untill now.
>
> To Henry :
>
>
>>You use RGBA as format in glTexImage2D(), make sure your image data is RGBA
>> format.
>
> I don't know how to check that in Cairo;
>
> To everyone : Thank you again
>
> Victor
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list