Re: Aliased corner with rounded rectangle
Lorenzo <[email protected]> Thu, 9 Aug 2018 15:07:43 +0200
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Sorry, by i already have the BlendFunc method. I initialize my opengl system with this code: glViewport(0, 0, drm->rect()->w, drm->rect()->h); glDisable(GL_CULL_FACE); glEnable(GL_LESS); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Lorenzo. On 08/08/2018 08:00 PM, Bill Spitzak wrote: > glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); > > Sorry, I managed to cut & paste the one example I had that did not say > "ALPHA" > > On Wed, Aug 8, 2018 at 10:59 AM, Bill Spitzak <[email protected] > <mailto:[email protected]>> wrote: > > You have to change the OpenGL compositing to over the > premultiplied image. I think glBlendFunc(GL_ONE, > GL_ONE_MINUS_SRC_COLOR) is what you need. > > On Wed, Aug 8, 2018 at 8:16 AM, Lorenzo <[email protected] > <mailto:[email protected]>> wrote: > > Hi, > > i have a problem with the creation of a rounded rectangle with > cairo. > > Environment info: > > cairo version: 1.14.8-1 > > OS: linux > > > A linux client creates a rounded rectangle with the following > code: > > let x = 0.0 > let y = 0.0 > let w = Double(size.w) > let h = Double(size.h) > let r = 20.0 > > logger.verbose("rounded rectangle > x=\(x),y=\(y),w=\(w),h=\(h),r=\(r)") > > cairo_move_to(context, x, y + r) > cairo_arc(context, x + r, y + r, r, Double.pi, > -Double.pi / 2.0) > cairo_line_to(context, x + w - r, y) > cairo_arc(context, x + w - r, y + r, r, -Double.pi / > 2.0, 0.0) > cairo_line_to(context, x + w, y + h - r) > cairo_arc(context, x + w - r, y + h - r, r, 0.0, > Double.pi / 2.0) > cairo_line_to(context, x + r, y + h) > cairo_arc(context, x + r, y + h - r, r, Double.pi / > 2.0, Double.pi) > cairo_close_path(context) > > > cairo_set_source_rgba(context, cl.red, cl.green, > cl.blue, cl.alpha); > cairo_fill(context) > > > After the surface fill i have 2 different operations to be > performed: > > - write the png on the disk using > "cairo_surface_write_to_png(surface, "testcairo.png")" > > - display the png with opengl es 3.0 as a texture (done by > copy the surface raw bytes with > cairo_image_surface_get_data(surface) > > in a shared memory used by the opengl server program) > > > Save the image on disk is ok, the image is good. > > Display the image as a texture with opengl results in an ugly > image: corners have some black pixels around them. > > Why this difference? > > > I have done some checks: > > - data obtained with cairo_image_surface_get_data are the same > that the graphics server loads from the shared memory (checked > PixelxPixel) so the data transfer don't is the problem > (checked also any signed/unsigned byte conversion) > > - loading the disk png as a texture instead of loading data > from the shared memory results in a good image with no problems. > > > My opinion is that the cairo_surface_write_to_png performs an > antialiasing algorithm and accessing raw data bypass it taking > the original image. > > > Is my opinion correct? If yes, any advice to solve the problem? > > > Regards, > > Lorenzo. > > > > > > -- > cairo mailing list > [email protected] <mailto:[email protected]> > https://lists.cairographics.org/mailman/listinfo/cairo > <https://lists.cairographics.org/mailman/listinfo/cairo> > > > -- cairo mailing list [email protected] https://lists.cairographics.org/mailman/listinfo/cairo