Cairo-1.10.2 (32/64 bit)
Cairo-1.10.2 (32/64 bit)
Cairo is a library used to provide a vector graphics-based, device-independent API for software developers. It is designed to provide primitives for 2-dimensional drawing across a number of different backends. Cairo is designed to use hardware acceleration when available.
Cairo is free and open-source software subject to the terms of dual licensing, under the GNU Lesser General Public License (LGPL) and the Mozilla Public License (MPL).
This header set is ready for 32/64 bit compiling and can replace the original headers shipped with the fbc packages.
Re: Cairo-1.10.2 (32/64 bit)
So when I try to compile and run the cairo examples from the 32-bit FreeBASIC distribution with your headers on my 64-bit system and compiler, I get a seg fault in cairo_paint(). Perhaps something still isn't quite right with the new headers on 64-bit systems?
For example:
For example:
Code: Select all
'' Cairo clock. Translated from the C example written by Writser Cleveringa
'' Details: http://cairographics.org/documentation/
#include once "cairo/cairo.bi"
#include once "datetime.bi"
Const SCREEN_W = 400
Const SCREEN_H = 300
Const PI = 3.14159265358979323846#
ScreenRes SCREEN_W, SCREEN_H, 32
''
'' Create a cairo drawing context, using the FB screen as surface.
''
Dim As cairo_surface_t Ptr surface = _
cairo_image_surface_create_for_data(ScreenPtr(), _
CAIRO_FORMAT_ARGB32, SCREEN_W, SCREEN_H, _
SCREEN_W * SizeOf(Integer))
Dim As cairo_t Ptr c = cairo_create(surface)
cairo_scale(c, SCREEN_W, SCREEN_H)
Do
ScreenLock()
''
'' Draw a clock
''
'' compute the angles for the indicators of our clock
Dim As Double minutes = Minute(Now()) * PI / 30
Dim As Double hours = Hour(Now()) * PI / 6
Dim As Double seconds = Second(Now()) * PI / 30
'' Draw the entire context white.
cairo_set_source_rgba(c, 1, 1, 1, 1)
cairo_paint(c)
'' Who doesn't want all those nice line settings :)
cairo_set_line_cap(c, CAIRO_LINE_CAP_ROUND)
cairo_set_line_width(c, 0.1)
'' Translate to the center of the rendering context,
'' and draw a black clock outline.
cairo_set_source_rgba(c, 0, 0, 0, 1)
cairo_translate(c, 0.5, 0.5)
cairo_arc(c, 0, 0, 0.4, 0, PI * 2)
cairo_stroke(c)
'' Draw a white dot on the current second.
cairo_set_source_rgba(c, 1, 1, 1, 0.6)
cairo_arc(c, Sin(seconds) * 0.4, -Cos(seconds) * 0.4, 0.05, 0, PI * 2)
cairo_fill(c)
'' Draw the minutes indicator
cairo_set_source_rgba(c, 0.2, 0.2, 1, 0.6)
cairo_move_to(c, 0, 0)
cairo_line_to(c, Sin(minutes) * 0.4, -Cos(minutes) * 0.4)
cairo_stroke(c)
'' Draw the hours indicator
cairo_move_to(c, 0, 0)
cairo_line_to(c, Sin(hours) * 0.2, -Cos(hours) * 0.2)
cairo_stroke(c)
ScreenUnlock()
Sleep 1000
Loop While (Len(Inkey()) = 0)
'' Clean up the cairo context
cairo_destroy(c)
Re: Cairo-1.10.2 (32/64 bit)
Found the problem. The example file needs to be modified for 64-bit. When the surface is created, the width is defined in terms of sizeof(Integer), which on 64-bit systems is 8. Because the buffer is RGBA (32-bit), it needs to be in terms of size 4, which on linux is LONG.
Re: Cairo-1.10.2 (32/64 bit)
Could you provide the modified example code here?
Or I can add your code to the header package, if you like.
Or I can add your code to the header package, if you like.
Re: Cairo-1.10.2 (32/64 bit)
Sure. Basically this is the faulty line in clock.bas:
The buffer is being created with SCREEN_W specifying the width in pixels multiplied by Sizeof(Integer), which works on 32-bit systems, since Integer is 32-bits. On 64-bit Linux (but not necessarily Windows), Integer is 8, hence the surface thinks it's bigger than the actual screen, and so we get a buffer overflow when the surface is rendered to the screen. The solution is to replace SizeOf(Integer) with 4. I hate magic numbers, but in this case, that's appropriate. 4 Bytes per pixel (since it's CAIRO_FORMAT_ARGB32).
There's one other bug in clock.bas too, but I haven't found or fixed it yet. Basically every time the clock is redrawn it moves off the screen a ways.
Hope this makes sense. All the Cairo example files need to have the Sizeof(Integer) stuff replaced with 4.
Code: Select all
Dim As cairo_surface_t Ptr surface = _
cairo_image_surface_create_for_data(ScreenPtr(), _
CAIRO_FORMAT_ARGB32, SCREEN_W, SCREEN_H, _
SCREEN_W * SizeOf(Integer))
There's one other bug in clock.bas too, but I haven't found or fixed it yet. Basically every time the clock is redrawn it moves off the screen a ways.
Hope this makes sense. All the Cairo example files need to have the Sizeof(Integer) stuff replaced with 4.
Re: Cairo-1.10.2 (32/64 bit)
That's an old bug. The function call to cairo_translate() has to get moved before the DO ... LOOP.caseih wrote:There's one other bug in clock.bas too, but I haven't found or fixed it yet. Basically every time the clock is redrawn it moves off the screen a ways.
I reviewed the examples and included them in the package.
Re: Cairo-1.10.2 (32/64 bit)
Gentlemen,
I'd like to propose a different way to fix the above issue, without any "magic number":
just use SIZEOF(LONG) -- instead of SIZEOF(INTEGER)
since: LONG is the FB-builtin 4-byte INT TYPE (fixed, NOT polymorphic) and therefore
OS independant.
I'd like to propose a different way to fix the above issue, without any "magic number":
just use SIZEOF(LONG) -- instead of SIZEOF(INTEGER)
since: LONG is the FB-builtin 4-byte INT TYPE (fixed, NOT polymorphic) and therefore
OS independant.
Re: Cairo-1.10.2 (32/64 bit)
This 'magic number' isn't related to the size of any FB type. Instead it's the number of bytes for a pixel. Four bytes are used for RGBA (red, green, blue, alpha).
Re: Cairo-1.10.2 (32/64 bit)
Well you've used SizeOf(Interger) --- used to be 4 Bytes (before polymorphing issues)TJF wrote:This 'magic number' isn't related to the size of any FB type. Instead it's the number of bytes for a pixel. Four bytes are used for RGBA (red, green, blue, alpha).
Result of SizeOf(Long) returns the needed 4 (Bytes) ... Brauchst nicht zu "schulmeistern".
Re: Cairo-1.10.2 (32/64 bit)
I haven't used anything. This example is from Writser Cleveringa, as you can see in the file header ;-) (Later I just fixed the cairo_translate() issue in the code in my package.)MrSwiss wrote:Well you've used SizeOf(Interger) --- used to be 4 Bytes (before polymorphing issues)
Result of SizeOf(Long) returns the needed 4 (Bytes) ... Brauchst nicht zu "schulmeistern".
Re: Cairo-1.10.2 (32/64 bit)
OK, after having settled the issue above ;-) , there is something that I personally find
difficult to understand:
- header's (can be got)
- binary's (dito)
what about the import lib's ... e.g. libcairo.dll.a , the only "other way" is compile your-
self, which is difficult without a C-Compiler (to many downloads etc. to just test a library
as far as I'm concerned)
difficult to understand:
- header's (can be got)
- binary's (dito)
what about the import lib's ... e.g. libcairo.dll.a , the only "other way" is compile your-
self, which is difficult without a C-Compiler (to many downloads etc. to just test a library
as far as I'm concerned)
Re: Cairo-1.10.2 (32/64 bit)
That's no issue on LINUX systems. A library gets installed or purged as any other package.
You want it the hard way, so take it ;-)
In case of cairo it's convenient to install the binaries by the GTK+ installers (you'll get Pango and PangoCairo as well):
You want it the hard way, so take it ;-)
In case of cairo it's convenient to install the binaries by the GTK+ installers (you'll get Pango and PangoCairo as well):
Re: Cairo-1.10.2 (32/64 bit)
Like I've pointed out before:
I just wanted to test the library, NOT spend my time, resolving dependencies ...
It may be simple on LUNIX, it is NOT on any "other" system.
(reason: the .sh installers are useless)
I'll go looking at something that is a lot less painfull to use like FLTK!
(advantage: statically linked in dependent lib's)
This exercise was for absolutely nothing, just a big waste of time ...
I just wanted to test the library, NOT spend my time, resolving dependencies ...
It may be simple on LUNIX, it is NOT on any "other" system.
(reason: the .sh installers are useless)
I'll go looking at something that is a lot less painfull to use like FLTK!
(advantage: statically linked in dependent lib's)
This exercise was for absolutely nothing, just a big waste of time ...
Re: Cairo-1.10.2 (32/64 bit)
Installing libraies isn't a trivial issue, beginners may be overhelmed. That's why I pointed to the bundle installers that do all the work for you. Just
Note:
cairo is a grafics library (not a GUI toolkit like FLTK).
- Download the matching version (32 / 64 bit).
- Unpack the archive (you'll get an .exe file installer).
- Doubleklick the .exe file and answer the questions (or just klick OK in the GUI for default configuration).
- When compiling, tell the fbc linker where to find the binaries (ie. when you install in C:\opt\ then either add this to your path, or use -l"C:/opt/bin" in the command line, or use #LIBPATH "C:/opt/bin" in your code).
Note:
cairo is a grafics library (not a GUI toolkit like FLTK).
Re: Cairo-1.10.2 (32/64 bit)
Here are the necessary Cairo dll's and a couple of test files.bas.
32 bit (I don't have 64 bit here, but I will update it when I advance to 64 bit).
Just run the code from inside the folder, no need to blitz your system folders with dll's.
You can make your own code snippets, or projects in that same folder.
I use Win XP here, not sure if Linux or Win 8 will work, maybe you will have to disperse the dll's, but it is worth a try.
I have gone off Cairo personally, the 2d graphics are a very slow compared to FreeBASIC raw graphics, or OpenGL graphics.
Here's the link:
http://www.mediafire.com/download/ui41t ... /Cairo.zip
32 bit (I don't have 64 bit here, but I will update it when I advance to 64 bit).
Just run the code from inside the folder, no need to blitz your system folders with dll's.
You can make your own code snippets, or projects in that same folder.
I use Win XP here, not sure if Linux or Win 8 will work, maybe you will have to disperse the dll's, but it is worth a try.
I have gone off Cairo personally, the 2d graphics are a very slow compared to FreeBASIC raw graphics, or OpenGL graphics.
Here's the link:
http://www.mediafire.com/download/ui41t ... /Cairo.zip