<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hello Henry<br><br>Thank you for your quick answer. <br>It seems that cairo-gl is not currently available on Ubuntu and I would like to stick with tools that are available from the repositories since some users prefer that way to work.<br>I will keep the suggestion for later anyway.<br><br>Do you have an idea how I could solve my "problem"? Do you think it could be related to the last argument passed to the the glTexImage2D function?<br><br>Thank you again<br><br>Victor<br><br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: hsong@sisa.samsung.com<br>To: nadaeck@hotmail.com; cairo@cairographics.org<br>Subject: RE: [cairo] trouble with Cairo text in OpenGL<br>Date: Wed, 4 Jan 2012 17:10:34 +0000<br><br>

<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">


<style>
.ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass div.ecxMsoNormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:"Times New Roman","serif";}
.ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink
{color:blue;text-decoration:underline;}
.ExternalClass a:visited, .ExternalClass span.ecxMsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
.ExternalClass p
{margin-right:0in;margin-left:0in;font-size:12.0pt;font-family:"Times New Roman","serif";}
.ExternalClass span.ecxEmailStyle18
{font-family:"Calibri","sans-serif";color:#1F497D;}
.ExternalClass .ecxMsoChpDefault
{font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;}
.ExternalClass div.ecxWordSection1
{page:WordSection1;}

</style>


<div class="ecxWordSection1">
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Hi, Vector,</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">If you use cairo/gl backend, there is no need to make GL calls directly.&nbsp;
</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">For example</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">/* create a gl surface */</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">cairo_surface_t *surface = cairo_gl_surface_create_for_window (.);</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">cairo_t *cr = cairo_create (surface);</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span></p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">/* draw text on gl surface */</span></p>
<p class="ecxMsoNormal">cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL,&nbsp; CAIRO_FONT_WEIGHT_BOLD);<br>
&nbsp;cairo_set_font_size (cr, 32.0);<br>
&nbsp;cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);<br>
&nbsp;cairo_show_text (cr, "HELLO");</p>
<p class="ecxMsoNormal">&nbsp;</p>
<p class="ecxMsoNormal">/* stroke a rectangle on gl surface */</p>
<p class="ecxMsoNormal">cairo_rectangle (cr, 10, 10, 100, 100);</p>
<p class="ecxMsoNormal">cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 1.0);</p>
<p class="ecxMsoNormal">cairo_stroke (cr);</p>
<p class="ecxMsoNormal">&nbsp;</p>
<p class="ecxMsoNormal">/* display gl surface on screen */</p>
<p class="ecxMsoNormal">cairo_gl_surface_swapbuffers (surface);</p>
<p class="ecxMsoNormal">&nbsp;</p>
<p class="ecxMsoNormal">/* clean up */</p>
<p class="ecxMsoNormal">cairo_surface_destroy (surface);</p>
<p class="ecxMsoNormal">cairo_destroy (cr);</p>
<p class="ecxMsoNormal">&nbsp;</p>
<p class="ecxMsoNormal">&nbsp;</p>
<p class="ecxMsoNormal">Hope this helps</p>
<p class="ecxMsoNormal">&nbsp;</p>
<p class="ecxMsoNormal">Henry</p>
<p class="ecxMsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="ecxMsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> cairo-bounces+hsong=sisa.samsung.com@cairographics.org [mailto:cairo-bounces+hsong=sisa.samsung.com@cairographics.org]
<b>On Behalf Of </b>Victor henri<br>
<b>Sent:</b> Wednesday, January 04, 2012 6:38 AM<br>
<b>To:</b> cairo@cairographics.org<br>
<b>Subject:</b> [cairo] trouble with Cairo text in OpenGL</span></p>
</div>
</div>
<p class="ecxMsoNormal">&nbsp;</p>
<div>
<div>
<p class="ecxMsoNormal">Hello<br>
<br>
I have trouble drawing text in an OpenGL texture with Cairo<br>
<br>
It works with SDL and SDL_ttf with :<br>
<br>
&nbsp;&nbsp;&nbsp; GLuint textureId;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; SDL_Color Color = {150, 0, 240};<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; SDL_Surface *Message = TTF_RenderText_Blended(font, "Hello!", Color);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned Texture = 0;<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glGenTextures(1, &amp;Texture);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glBindTexture(GL_TEXTURE_2D, Texture);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Message-&gt;w, Message-&gt;h, 0, GL_BGRA, GL_UNSIGNED_BYTE, Message-&gt;pixels);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glBegin(GL_QUADS);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glColor4f(1, 0, 0, 1);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(0, 0); glVertex3d(0, 0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(1, 0); glVertex3d(0.2, 0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(1, 1); glVertex3d(0.2, -0.2, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(0, 1); glVertex3d(0,&nbsp; -0.2, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glEnd();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glDeleteTextures(1, &amp;Texture);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SDL_FreeSurface(Message);<br>
<br>
Clearly, the Message-&gt;pixels argument in "glTexImage2D" seems important; if I replace it with NULL, I get random lines and points.<br>
<br>
If I do this with Cairo :<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_surface_t *surface;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_t *cr;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GLuint textureId;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char* surfaceData;<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 64, 64);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cr = cairo_create (surface);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL,&nbsp; CAIRO_FONT_WEIGHT_BOLD);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cairo_set_font_size (cr, 32.0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cairo_show_text (cr, "HELLO");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; surfaceData = cairo_image_surface_get_data (surface);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned Texture = 0;<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glGenTextures(1, &amp;Texture);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glBindTexture(GL_TEXTURE_2D, Texture);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface), 0, GL_BGRA, GL_UNSIGNED_BYTE, surfaceData);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glBegin(GL_QUADS);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glColor4f(1, 0, 0, 1);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; glTexCoord2d(0, 0); glVertex3d(0, 0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(1, 0); glVertex3d(0.2, 0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(1, 1); glVertex3d(0.2, -0.2, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexCoord2d(0, 1); glVertex3d(0,&nbsp; -0.2, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glEnd();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glDeleteTextures(1, &amp;Texture);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cairo_destroy (cr);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_surface_destroy (surface);<br>
<br>
<br>
<br>
If I do that I get a few red points but not the text I want. I use the " cairo_image_surface_get_data (surface)" function to get the appropriate data and to give it to glTextImage2D but I suppose this is where it won't work.
<br>
<br>
In some examples I have come across the "create_cairo_context" through which surfaceData can be taken. But this function seems completely unknown on my system...<br>
I am using Ubuntu Linux 11.10 (lateste version)<br>
<br>
Please could give me some help about this?<br>
<br>
Victor</p>
</div>
</div>
</div></div>                                               </div></body>
</html>