Beginner needs help w Fog + Juce

169 views
Skip to first unread message

Donald Le Duck

unread,
Mar 6, 2012, 8:05:07 AM3/6/12
to fog-dev
Hi everyone,

I am a beginner at c++ and I am using Juce http://www.rawmaterialsoftware.com/
for my learning projects. I have realized that Juce's rendering and
antialiasing is no where near as good as Fog's, so I would like to
incorporate Fog into my GUI code for faster and better drawing but I
would really need some help to get started. Is there a friendly soul
out there who can guide me? :-) What do I need to include in my Juce
visual studio project to use Fog to draw things in an image?

Thanks in advance!

/ Donald

Petr Kobalíček

unread,
Mar 6, 2012, 2:39:00 PM3/6/12
to fog...@googlegroups.com
Hello,

welcome to Fog-Framework mailing list.

If you want to compile Fog-Framework, you need to install cmake
(www.cmake.org/) and run script included in Fog/Util - For example
configure-windows-vs2010-x64.bat for VS2010 and 64-bit mode
compilation. You can check whether you are successful by trying one of
samples provided.

Including Fog within another projects is trivial if you know C++
tooling. The simplest way is to create new cmake project which include
compiled Fog library, or it's also possible to include Fog into your
project and to link statically. Generally the way of including Fog
depends on your project and the way you are maintaining it. Please
don't try to just add Fog files into your project, the build is not
easy because of cross-platform nature of the project (and the way how
cpu specific optimizations and handled).

After you finish all of this, there is another question. How Juce
works with raster graphics and which compatible pixel formats you can
use to map Juce<->Fog imaging. I have currently not idea of this, but
I can create some wiki pages where the information related to
interoperability with another libraries.

If you have another questions, just ask;)

Best regards
Petr Kobalicek

Donald Le Duck

unread,
Mar 7, 2012, 12:51:57 PM3/7/12
to fog-dev
Hi Peter,

First of all, thank you very much for a nice welcoming to the list! I
am used to being yelled at when asking for help, so this was a really
nice surprise!

I managed to download Fog and run the script, but unfortunately I hit
some errors when I opened the resulting .sln-file and tried to build
(visual c++ 2008 express, win 7 32).
These were the errors:

RasterInit_C.cpp
..\Src\Fog\G2d\Painting\RasterInit_C.cpp(260) : error C2440: '=' :
cannot convert from 'void (__cdecl *)(uint8_t *,const uint8_t
*,int,const Fog::RasterClosure *)' to 'Fog::RasterVBlitLineFunc'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
..\Src\Fog\G2d\Painting\RasterInit_C.cpp(291) : error C2440: '=' :
cannot convert from 'void (__cdecl *)(uint8_t *,const uint8_t
*,int,const Fog::RasterClosure *)' to 'Fog::RasterVBlitLineFunc'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast

Am I doing something wrong here?

"Including Fog within another projects is trivial if you know C++
tooling. The simplest way is to create new cmake project which
include
compiled Fog library, or it's also possible to include Fog into your
project and to link statically"

- I do not know how to use cmake so the static linking option you
mentioned sounds more realistic (even that will be a challenge with my
limited skills!). Then I will need to compile some .obj files,
tell the linker where they are and include one or more .h-files, is
that correct?

"After you finish all of this, there is another question. How Juce
works with raster graphics and which compatible pixel formats you can
use to map Juce<->Fog imaging. I have currently not idea of this, but
I can create some wiki pages where the information related to
interoperability with another libraries. "

- I don't know either, but I do know that people have used AGG to draw
paths and stuff to images in juce, so I am hoping it will be possible
to do the same with Fog.

All the best,
Donald

Petr Kobalíček

unread,
Mar 8, 2012, 2:54:10 PM3/8/12
to fog...@googlegroups.com
Hi Donald,

On Wed, Mar 7, 2012 at 7:51 PM, Donald Le Duck <andersa...@gmail.com> wrote:
> Hi Peter,
>
> First of all, thank you very much for a nice welcoming to the list! I
> am used to being yelled at when asking for help, so this was a really
> nice surprise!

You are welcome! I have no problem with helping others to start with Fog;)

> I managed to download Fog and run the script, but unfortunately I hit
> some errors when I opened the resulting .sln-file and tried to build
> (visual c++ 2008 express, win 7 32).
> These were the errors:
>
> RasterInit_C.cpp
> ..\Src\Fog\G2d\Painting\RasterInit_C.cpp(260) : error C2440: '=' :
> cannot convert from 'void (__cdecl *)(uint8_t *,const uint8_t
> *,int,const Fog::RasterClosure *)' to 'Fog::RasterVBlitLineFunc'
>        This conversion requires a reinterpret_cast, a C-style cast or
> function-style cast
> ..\Src\Fog\G2d\Painting\RasterInit_C.cpp(291) : error C2440: '=' :
> cannot convert from 'void (__cdecl *)(uint8_t *,const uint8_t
> *,int,const Fog::RasterClosure *)' to 'Fog::RasterVBlitLineFunc'
>        This conversion requires a reinterpret_cast, a C-style cast or
> function-style cast
>
> Am I doing something wrong here?

It was a bug and it should be fixed now, thanks!
(I'm using mainly 64-bit compilation where I was unable to catch it)

> "Including Fog within another projects is trivial if you know C++
> tooling. The simplest way is to create new cmake project which
> include
> compiled Fog library, or it's also possible to include Fog into your
> project and to link statically"
>
> - I do not know how to use cmake so the static linking option you
> mentioned sounds more realistic (even that will be a challenge with my
> limited skills!). Then I will need to compile some .obj files,
> tell the linker where they are and include one or more .h-files, is
> that correct?

Basically the way how to do static linking and dynamic linking is very
similar. I prefer dynamic linking, because you can just compile Fog
using cmake, basically you only need to create a project file and
build it, and then you can add the 'dll' library into your own
project. The only thing you need to setup is to add Fog into your
project's include directory (I think that it's -I command line option,
or use project settings in Visual Studio, look for include
directories)

> "After you finish all of this, there is another question. How Juce
> works with raster graphics and which compatible pixel formats you can
> use to map Juce<->Fog imaging. I have currently not idea of this, but
> I can create some wiki pages where the information related to
> interoperability with another libraries. "
>
> - I don't know either, but I do know that people have used AGG to draw
> paths and stuff to images in juce, so I am hoping it will be possible
> to do the same with Fog.

If people successfully used to draw using AGG then Fog shouldn't be a
problem. I'm planning to add some information to the wiki and Juce can
be nice addition;)

> All the best,
> Donald

Best regards
Petr Kobalicek

Donald Le Duck

unread,
Mar 10, 2012, 9:06:39 AM3/10/12
to fog-dev
Hi Peter,

Thanks for fixing the bug. I have managed to compile Fog!

I have a few more qustions on how to set up Fog;

1) Is it the .lib's or .dll's that are generated in the Build/Debug
and Build/Release directories when I "build all" in vcpp that I should
include?

2) What .h files do I need, Fog/Core.h G2d.h and UI.h?

3) I think I remember I saw a tutorial on how to get started with Fog
but I can no longer find it, is it still out there somewhere?

4) In order to get an overview of Fog I installed doxygen and run it
("typing doxygen Doxygen.conf") in the Documentation directory. I got
errors and no html output, it appears that the Doxygen.conf is not up
to date.

Where in Czech Republic do you live? Prague? Has the spring arrived
there yet?

All the best,
Donald

Donald Le Duck

unread,
Mar 10, 2012, 11:49:44 AM3/10/12
to fog-dev
Ok,I have been playing around a little. I think I have the answers to
1) and 2) in my previous post (see below!), and also 3) (here:
http://kobalicek.com/data/articles/Fog-Graphics.html), but 4) remains
and a have a new problem (below). Here is what I did after having
built Fog:

In my vc project;

1. In a file where I want to use Fog I added the following:
#include "..\..\..\fog-read-only\Fog\Src\Fog\Core.h"
#include "..\..\..\fog-read-only\Fog\Src\Fog\G2d.h"
#include "..\..\..\fog-read-only\Fog\Src\Fog\UI.h"

2. Configuration properties/C++/Additional include directories:
D:\fog-read-only\Fog\Build\Debug
D:\fog-read-only\Fog\Src
D:\fog-read-only\Fog\

3. Linker/General/Additional library directories:
D:\fog-read-only\Fog\Build\Debug

4. Linker/Input/Additional dependencies/:
Fog.lib


Now there appears to be a name conflict between Juce and Fog, because
I get this:

1>d:\fog-read-only\fog\src\fog\core\global\api.h(2068) : error C2872:
'ssize_t' : ambiguous symbol
1> could be 'd:\fog-read-only\fog\src\fog\core\c++
\stdint.h(128) : __w64 long ssize_t'
1> or 'd:\c++\fogtest\jucelibrarycode\modules\juce_core
\maths\juce_mathsfunctions.h(95) : juce::ssize_t'

Does this mean that Fog and Juce are incompatible?

Donald Le Duck

unread,
Mar 10, 2012, 12:12:09 PM3/10/12
to fog-dev
Hi Peter,

I noticed that both Fog and Juce have classes called Image. The Juce
class for Image looks like this:

Image(Image::ARGB, imageWidth, imageHeight, true,
Image::SoftwareImage);

the first argument could be one of the following:
Image::ARGB :each pixel is a 4-byte ARGB premultiplied colour value.
{ indexA = 3, indexR = 2, indexG = 1, indexB = 0 }
Image::RGB : in which each pixel is a 3-byte packed RGB colour value.
{ indexR = 0, indexG = 1, indexB = 2 }



To acces the raw pixel data, there is another class which takes an
Image as input:

BitmapData(Image, 0, 0, imageWidth, imageHeight,
Image::BitmapData::readWrite);

It has a few useful member functions:

uint8 * Image::getPixelPointer (int x, int y) const noexcept
uint8 * Image::BitmapData::getLinePointer (int y) const noexcept
(uint8 is a platform-independent 8-bit unsigned integer type)


I hope it will be possible to create a juce image, take a pointer to
the raw data and give it to
a suitable class in Fog to do some drawing...

All the best,
Donald

Donald Le Duck

unread,
Mar 11, 2012, 7:08:48 AM3/11/12
to fog-dev
Hello, it's me again:)

I changed the order in which I included the .h-files so that

#include "..\..\..\fog-read-only\Fog\Src\Fog\Core.h"
#include "..\..\..\fog-read-only\Fog\Src\Fog\G2d.h"
#include "..\..\..\fog-read-only\Fog\Src\Fog\UI.h"

comes before

#include "ContentComponent.h"

which includes the Juce header.

I no longer get the ambiguous symbol error, but I do get 721 warnings!

Here follows a few examples:

fog\core\global\types.h(53) : warning C4201: nonstandard extension
used : nameless struct/union
fog\core\acc\accc.h(329) : warning C4127: conditional expression is
constant
fog\core\tools\char.h(73) : warning C4127: conditional expression is
constant
fog\core\kernel\coreobj.h(45) : warning C4100: 'name' : unreferenced
formal parameter
fog\core\dom\dom.h(134) : warning C4481: nonstandard extension used:
override specifier 'override'
fog\g2d\source\argb.h(103) : warning C4244: '=' : conversion from
'uint32_t' to 'uint8_t', possible loss of data
etc.

I have no idea whether or not the include order trick really solved
the name conflicts, but I guess I'll find out...

All the best,
Donald

Donald Le Duck

unread,
Mar 11, 2012, 7:30:51 AM3/11/12
to fog-dev
Peter,

I need help with two things:

1) How do I create a Fog Image from a ointer to the pixel data in a
Juce Image?

2) How can I generate documentation? Do I need to do something
differently or do you need to update Doxygen.conf ?

All the best,
Donald

Petr Kobalíček

unread,
Mar 11, 2012, 1:38:46 PM3/11/12
to fog...@googlegroups.com
Hi Donald,

It's a lot of stuff so I try to reply as best as possible :)

1) Libraries - Fog on Windows typically compiles to Fog.dll and
Fog.lib (to include it in VS). So you need only to add this single
library into your visual studio project.

2) Include path - Fog require only one include path that points to
Fog/Src directory, all other include paths are useless, because you
always reference include files like #include <Fog/Module.h>, in your
case it would be <Fog/Core.h> and <Fog/G2d.h>.

3) Fog tutorial was on my fog-blog, but it's outdated, I'd like to
move all tutorial like things into Wiki on project page. I'm sorry
about this, I did large refactorization after the tutorial has been
written.

4) ssize_t - it's quite problem, because juce defines it differently.
This type shouldn't be a problem on non-windows platforms where it's
defined in stdint.h. I looked at Juce and the typedef there is a bit
different, I will explore this, but I think that definition in Fog
better matches MSCV compiler. I will probably fill an issue for this.

5) Doxygen - Today I worked on documentation sections so the generated
documentation should be quite okay, but many classes/functions are not
documented so you can only guess what they do (the naming should be,
however, straightforward).

6) Imaging/Painting stuff - Fog::Image is the way to go. If you have
Juce image in some format, you can map this image into Fog image. You
only need to fill ImageBits structure and then to call
Image::adopt(imageBits, flags). This call is used to 'adopt' data into
image container so for some time it will be shared between Juce and
Fog. Adoption is powerful, but when used incorrectly it can be also
dangerous, because if you destroy your Juce image without releasing
Fog-Image then application may crash when Fog will try to access the
data (it's basically a dangling pointer problem). I'm not sure whether
you can do the opposite, map Fog image into Juce image - in such case
it could be better, because you can use Fog to manage images and paint
into them, and Juce to blit the result on the screen (for me better
solution).

There is also solution that you can fill ImageBits and then pass it to
the Fog::Painter, in this case you don't need intermediate Fog::Image
as a container. Ideal to draw to Juce image, I think.

From the Juce documentation I think that only Fog::IMAGE_FORMAT_PRGB32
and Juce::Image::ARGB are compatible, I'm not sure about
Juce::Image::RGB, because I think that Fog uses different byte
ordering here (Fog uses always native endian byte-order).

So to use Fog::Image on top of JuceImage, you can do something like this:

// You need to fill these variables, stride means bytes per one line.
uint32_t width;
uint32_t height;
uint32_t format;
ssize_t stride;
uint8_t* data;

Fog::Image fi;
err_t err = fi.adopt(Fog::ImageBits(Fog::SizeI(width, height), format,
stride, data));

if (FOG_IS_ERROR(err))
{
// Something failed.
}

or create a painter:

Fog::Painter p(fi);
// ... painting.
p.end();

7) I fixed some warnings you posted, but I think that some wrong
warning options are set during a compilation. For example MSVC
shouldn't complain about 'override' keyword and stuff which comes from
C++0x.

8) I'm from Zlin, it's in the opposite side of Czech Republic as Prague:)

I hope that some my hints can help you to solve your problems, I will
look at ssize_t issue. Write here about your progress :)

Best regards
Petr Kobalicek

Donald Le Duck

unread,
Mar 12, 2012, 1:44:28 PM3/12/12
to fog-dev
Hi Peter,

Thanks for all your help!

It looks as if I can't do anything more until we have found a solution
to the ssize_t issue
since both the Image and Painter solution demands that I use ssize_t.

All the best,
Donald

Donald Le Duck

unread,
Mar 14, 2012, 2:01:59 PM3/14/12
to fog-dev
Hi Peter,

I got some help from a nice dude today, he told me I could simply use
the juce::ssize_t whenever a Fog::ssize_t is needed as the types are
identical apart from the name!
Hopefully this means that we are much closer to success!

I tried the following in the a paint(Graphics & g) function in my test
application (juce::Graphics appears to be similar to Fog::Painter):

// Fill the background with red color
g.setColour(Colours::red);
g.fillAll();

// Create a juce image
int width = 100;
int height = 100;
Image im = Image( Image::ARGB, width, height, true,
SoftwareImageType() );
Image::BitmapData bmp( im, 0, 0, width, height,
Image::BitmapData::readWrite );

// Fill the image with green
Graphics g2(im);
g2.setColour(Colours::green);
g2.fillAll();

// Create a fog image, adopt the pixel data from the juce image
uint32_t w = width;
uint32_t h = height;
uint32_t format = Fog::IMAGE_FORMAT_PRGB32;
juce::ssize_t stride = bmp.lineStride;
uint8_t* data = bmp.getLinePointer(0);
Fog::Image fi;
err_t err =
fi.adopt( Fog::ImageBits(Fog::SizeI(width, height), format, stride,
data));

// Fill the image with a new color
Fog::Painter p(fi);
p.setSource(Fog::Argb32(0xAAFF0066));
p.fillAll();
p.end();

// draw the image on the background
g.drawImageAt(im, 0, 0);


I get a red square with a smaller green square inside (drawn by juce),
but the Fog stuff doesn't seem to do anything...

Can you spot anything that looks weird here?

All the best,
Donald

Petr Kobalíček

unread,
Mar 25, 2012, 7:21:59 AM3/25/12
to fog...@googlegroups.com
Hi Donald,

I'm sorry for slow reply, I completely forgot about this thread.

Your code seems to be valid, please check for error code returned by
Image::adopt() and Painter::begin() (you can use Painter::begin()
instead of constructor to be able to get possible error). For me it
seems strange that you have bitmap and juce graphics context at the
same time on the image.

I would try to simplify the code, for example:

// Fill the background with red color
g.setColour(Colours::red);
g.fillAll();

// Create a juce image
int width = 100;
int height = 100;

Image im(Image::ARGB, width, height, true, SoftwareImageType());
Image::BitmapData bmp(im, 0, 0, width, height, Image::BitmapData::readWrite);

// Create a fog image, adopt the pixel data from the juce image
uint32_t w = width;
uint32_t h = height;
uint32_t format = Fog::IMAGE_FORMAT_PRGB32;
juce::ssize_t stride = bmp.lineStride;
uint8_t* data = bmp.getLinePointer(0);

Fog::Image fi;
err_t err = fi.adopt( Fog::ImageBits(Fog::SizeI(width, height),
format, stride, data));

if (FOG_IS_ERROR(err))
{
printf("Error %u in Fog::Image::adopt()\n", err);
}

// Fill the image with a new color

Fog::Painter p;
err = p.begin((fi);

if (FOG_IS_ERROR(err))
{
printf("Error %u in Fog::Paiter::begin()\n", err);
}

p.setSource(Fog::Argb32(0xAAFF0066));
p.fillAll();
p.end();

// Here I'm not sure about juce Image::BitmapData, I think
// that it should be destroyed before im is used.

// draw the image on the background
g.drawImageAt(im, 0, 0);

Hope that helps.

Best regards
Petr Kobalicek

Donald Le Duck

unread,
Mar 25, 2012, 9:03:35 AM3/25/12
to fog-dev
Hi Peter,

Great that you're back:)

Unfortunately Fog::Painter p; causes an access violation in

//! @brief Create a null painter.
FOG_INLINE Painter()
{
_engine = fog_api.painter_getNullEngine(); <---on this line...
_vtable = _engine->vtable;
}


so I am forced to use Fog::Painter p(fi);




Anyway, adopt() returns 0 so it seems to work.


If I try
Fog::Painter p(fi);
err = p.begin(fi);
I get err=65653

I don't know if it is ok to initialize a painter two times like this
though.


setSource returns 65546 but maybe that is expected since the painter
is not properly set up.




All the best,
Donald

Petr Kobalíček

unread,
Mar 26, 2012, 5:39:29 AM3/26/12
to fog...@googlegroups.com
Hi Donald,

I tried to reproduce the issue with empty painter constructor, but I
didn't have a luck. Could you try the latest SVN version so we are
sure that we are using the same?

I'd like also to try to isolate the code which paints using Fog into
one function so we will be sure that all states are correct, for
example try moving painting code to one function:

// --------------------------------------
static void paint(juce::Image& jImage)
{
// Juce stuff.
int width = jImage.getWidth();
int height = jImage.getHeight();

Image::BitmapData jBitmap(jImage, 0, 0, width, height,
Image::BitmapData::readWrite);

// Create Fog::Image which adopts juce image.
uint32_t fFormat = Fog::IMAGE_FORMAT_PRGB32;

Fog::Image fImage;


err_t err = fi.adopt( Fog::ImageBits(Fog::SizeI(width, height),

fFormat, jBitmap.lineStride, jBitmap.getLinePointer(0)));

if (FOG_IS_ERROR(err))
{
printf("Error %u in Fog::Image::adopt()\n", err);

return;
}

// Create Fog::Painter.
Fog::Painter p(fImage);

p.setSource(Fog::Argb32(0xFF000000));
p.fillAll();

// Here everything will be destroyed in correct order, juce image
should contain the painting.
}
// --------------------------------------

It's also possible to skip creating Fog::Image if you plan to use it
only for painting, for example this should work like the previous
sample:

// --------------------------------------
static void paint(juce::Image& jImage)
{
// Juce stuff.
int width = jImage.getWidth();
int height = jImage.getHeight();

Image::BitmapData jBitmap(jImage, 0, 0, width, height,
Image::BitmapData::readWrite);
uint32_t fFormat = Fog::IMAGE_FORMAT_PRGB32;

// Create Fog::Painter.
Fog::Painter p;

p.begin(Fog::ImageBits(Fog::SizeI(width, height), fFormat,
jBitmap.lineStride, jBitmap.getLinePointer(0)));
p.setSource(Fog::Argb32(0xFF000000));
p.fillAll();

// Here everything will be destroyed in correct order, juce image
should contain the painting.
}
// --------------------------------------

Hope that helps, I'd like to solve this so you can continue trying Fog:)

Best regards
Petr Kobalicek

Donald Le Duck

unread,
Mar 26, 2012, 12:27:08 PM3/26/12
to fog-dev
Hi Petr,

I checked out the latest revision, ran the scripts, rebuilt Fog (right-
clicked rebuild on solution) and rebuilt my test project.

I used the second function you suggested above (skipped 'static'
though) but unfortunately I still get

Unhandled exception at 0x00000000 in FOGtest.exe: 0xC0000005: Access
violation.

at

FOG_INLINE Painter()
{
_engine = fog_api.painter_getNullEngine(); // <----- here!



Is there anything I can do to help debugging?

petervy

unread,
Mar 31, 2012, 3:31:29 AM3/31/12
to fog...@googlegroups.com

Hi guys.

I know Donald is having trouble getting Fog to render on JUCE. I may be able to give some insight to getting the drawing surface setup properly. JUCE is bloated and I am not going that route as it takes too much time to dev and debug. I think as a learning project, NET framework will be better for the front end and Fog as the rendering backend. I was fuking around with the demo code that came with Fog and came up a bridge to handle the GUI, events, and access to resources/etc on the managed C# side using a C++/CLI wrapper. This way, you get nearly all the native drawing performance of Fog, but the simplicity of using NET for everything else. I exposed a single bitmap from the managed side so that I can blit the bitmap into the GDI graphic surface during Paint events.
 
GDI+ Forms >>> Managed Gfx class >>> Managed C++ wrapper >>> Native Gfx api >>> Fog engine 
 

See the attached source code and binary demo files for (win32 x86 Net4).

I googled for some code project that allow bindings from Fog to C#, but found none, so I cooked one up -- hope ya don't mind.

Fog_Net.4.demo.zip
CoderStudio.zip

petervy

unread,
Mar 31, 2012, 3:56:30 AM3/31/12
to fog...@googlegroups.com
Oh, btw you will need the Fog dll + lib and for the project to compile. If the animation didn't run, its because the Timer event handler in the form.cs file is wrong. Here is the correct one:


  private void timer_Tick( object sender, System.EventArgs e ) {
     x++;
     gfx.Draw( x, y );
     this.Invalidate(); // trigger
  }

Petr --- your Fog library is awesome. I can't wait for new features and optimization.

Donald Le Duck

unread,
Mar 31, 2012, 9:14:53 AM3/31/12
to fog-dev
Petr & petervy,

Thanks for the code. Unfortunately I know nothing about .NET etc. :
( In what way do you think Juce is bloated?
It has recently been modularized and IMHO it is pretty stremlined, and
I intend to keep using C/C++ and Juce
until I find a better solution for creating stand alone audio
applications and plugins. I'm afraid I don't really have time to
learn yet another language even though I know you can do amazing stuff
with C#.

Still no progress. I have really no idea how to proceed.

I wonder if the problem with the Painter() constructor is related to
Juce or if it is caused by an incompatibility with the old tools that
I am using (vs2008 and 32 bit computer)....

Best,
Donald



Petr Kobalíček

unread,
Mar 31, 2012, 9:32:29 AM3/31/12
to fog...@googlegroups.com
Hi Donald,

I'm very sorry that this issue is still not yet resolved. To be
honest, I have no idea why it happens, I tried to reproduce, but no
luck. There is however one thing we can test. What kind of linking do
you use? Static linking or dynamic linking? If you are using static
linking then there is one C++ issue which can be fixed by calling
_fog_init_static() in your application`s main().

Hi Petervy,

I tried the demo and it looks nice, thanks for this effort. When I get
more free time I'd like to start working more on wiki so it wouldn't
be so hard to make Fog working or to use it from different language.

Best regards
Petr Kobalicek

Jerry Evans

unread,
Mar 31, 2012, 10:37:26 AM3/31/12
to fog...@googlegroups.com, petervy
Nice. .NET is always good. Will the source be available?

Thanks for sharing.

Jerry

Donald Le Duck

unread,
Mar 31, 2012, 10:56:50 AM3/31/12
to fog-dev
Hi Petr,

I am (trying) to use static linking so maybe _fog_init_static is what
is missing? I don't know how to link dynamically. Here are my settings
for static linking :

- Linker-Input-Additional dependencies : Fog.lib
- Linker-Additional library directories: D:\fog-read-only\Fog\Build
\Debug

Juce auto generates the code for main(), but I found a function called
initialize, with the comment "// Do your application's initialisation
code here.." so I put
_fog_init_static(); there and included:

#include "..\..\..\fog-read-only\Fog\Src\Fog\Core.h"
#include "..\..\..\fog-read-only\Fog\Src\Fog\G2d.h"

Unfortunately I got "error C3861: '_fog_init_static': identifier not
found"...

I searched for _fog_init_static in the entire solution but it didn't
exist, so I opened the Fog.sln and searched there instead. Found it:

#if defined(FOG_BUILD_STATIC)
FOG_CAPI_EXTERN void _fog_init_static(void);
#endif // FOG_BUILD_STATIC

apparently FOG_BUILD_STATIC was not defined during the build, so I
tried to set it manually and rebuild. The build failed.... arghh...








Jerry Evans

unread,
Mar 31, 2012, 11:03:58 AM3/31/12
to fog...@googlegroups.com, Donald Le Duck
DLD, what tools on which OS are you using to build the project?

Petr Kobalíček

unread,
Mar 31, 2012, 11:19:16 AM3/31/12
to fog...@googlegroups.com
Hi guys,

we should go deeply here so I will try to explain the issue and the
solution. If you are using static linking then it means that Fog is
compiled statically. Static linking is different to dynamic linking
and C++ compiler tries to remove all code which "it thinks" is not
used. The code removal is based on .cpp files where no function was
called by your application. The problem is that Fog contains one entry
point which is needed to initialize the library so you are able to use
it. Without calling _fog_init_static() the initialization won't
happen, this means that any call to exported Fog function (not inlined
function) will fail due to null pointer exception (access violation).

The solution for static linking is to define one dummy function used
in Init.cpp which you call through your code - this ensures that C++
compiler won't remove the initialization process, because you used
(referenced by _fog_init_static() call) the .cpp module where the
initialization happens.

So the problem here is, I think, that Fog things that it's build
dynamically, but it's not. You can try to add -DFOG_BUILD_STATIC
argument to cmake so Fog will know that it's statically linked.

BTW: The best thing to ensure whether everything is okay is to build
Fog and examples using standard way (scripts in Util directory). If
you can successfully build Fog this way and examples work then you
should concentrate on building your app.

Best regards
Petr Kobalicek

Donald Le Duck

unread,
Mar 31, 2012, 12:23:33 PM3/31/12
to fog-dev
Jerry - Win 7 32 bit Visual C++ 2008 express.

Petr - I added "-DFOG_BUILD_STATIC=1" to the file configure-windows-
vs2008-x86.bat and ran it. Opened the generated Fog solution, it
contained Fog, ALL_BUILD and ZERO_CHECK. Built the solution, got some
warnings. One in particular looked sinister:

Painter.obj : warning LNK4221: no public symbols found; archive member
will be inaccessible

Opened the other solution with my test application, tried to build it
but it now failed:

1>Linking...
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall
type_info::type_info(class type_info const &)" (??
0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info
& __thiscall type_info::operator=(class type_info const &)" (??
4type_info@@AAEAAV0@ABV0@@Z) already defined in
LIBCMTD.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of
other libs; use /NODEFAULTLIB:library
1>.\Debug\FOGtest.exe : fatal error LNK1169: one or more multiply
defined symbols found

Jerry Evans

unread,
Mar 31, 2012, 3:22:32 PM3/31/12
to fog...@googlegroups.com
DLD: You've got runtimes set up incorrectly.

Ensure the following options are set for both FOG and JUCE:

1. Configuration Properties >> General >> Configuration type

Application (.exe) for JUCE if this contains main() or equivalent
Static Library for FOG if you have defined

-DFOG_BUILD_STATIC=1

2. Configuration Properties >> General >> Character set

should be either MBCS or UNICODE for *both*

3. Configuration Properties >> C++ >> Code Generation >> Runtime library

For static linking of Fog and Juce select multi-threaded debug.

4. Make sure the JUCE project is dependent on FOG.

Right-click in Solution Explorer, select Project dependencies and tick
the right box.

Then clean everything out and rebuild.

If this fails post the output from the project as it builds.

Good luck.

On 31/03/2012 17:23, Donald Le Duck wrote:
> Jerry - Win 7 32 bit Visual C++ 2008 express.
>
> Petr - I added "-DFOG_BUILD_STATIC=1" to the file configure-windows-
> vs2008-x86.bat and ran it. Opened the generated Fog solution, it
> contained Fog, ALL_BUILD and ZERO_CHECK. Built the solution, got some
> warnings. One in particular looked sinister:
>
> Painter.obj : warning LNK4221: no public symbols found; archive member
> will be inaccessible
>
> Opened the other solution with my test application, tried to build it
> but it now failed:
>
> 1>Linking...
> 1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall

> type_info::type_info(class type_info const&)" (??


> 0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
> 1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info

> & __thiscall type_info::operator=(class type_info const&)" (??

Donald Le Duck

unread,
Apr 1, 2012, 9:19:29 AM4/1/12
to fog-dev
Hi Jerry,

Thanks for helping me.

1. No changes were necessary

2. Changed Fog project from Unicode to Multibyte since the auto
generated Juce project was using Multibyte
(in Preprocessor definitions there is _UNICODE, is that a problem?)

3. Changed Fog project from "Multi-threaded Debug DLL" to "Multi-
threaded Debug"

4. Didn't find any box to tick. If I right-click on the solution icon
in the solution explorer I can select "Project Dependencies"
a dropdown ("Project") shows only one alternative, "FOGtest" which is
the name of the Juce project trying to link with Fog.
Below the dropdown is large white box ("Depends on") which is
completely empty.

I think it fails already when trying to build the Fog solution; I
still get the warnings:

2>Creating library...
2>UIEngineEvent.obj : warning LNK4221: no public symbols found;
archive member will be inaccessible
2>Texture.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>ColorStopCache.obj : warning LNK4221: no public symbols found;
archive member will be inaccessible
2>ColorStop.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>ColorBase.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>Painter.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>PaintParams.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>PaintEngine.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>PngCodec.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>MacCGCodec.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>JpegCodec.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>Size.obj : warning LNK4221: no public symbols found; archive member
will be inaccessible
2>Point.obj : warning LNK4221: no public symbols found; archive member
will be inaccessible
2>Math2d.obj : warning LNK4221: no public symbols found; archive
member will be inaccessible
2>Stub.obj : warning LNK4221: no public symbols found; archive member
will be inaccessible
2>Char.obj : warning LNK4221: no public symbols found; archive member
will be inaccessible
2>Fuzzy.obj : warning LNK4221: no public symbols found; archive member
will be inaccessible
2>Build log was saved at "file://d:\fog-read-only\Fog\Build\Fog.dir
\Debug\BuildLog.htm"
2>Fog - 0 error(s), 21 warning(s)


This looks to me as if I will not be able to access important parts of
the library!

These warnings appear when I add "-DFOG_BUILD_STATIC=1" in "configure-
windows-vs2008-x86.bat" before I run it.



Petr Kobalíček

unread,
Apr 1, 2012, 10:18:55 AM4/1/12
to fog...@googlegroups.com
Hi Donald,

these warnings are fine - files they point to are empty for now.
Changing Fog to multibyte shouldn't be a problem, but it's year 2012,
so I don't think you want an application without proper unicode
support:) Fog uses WinAPI functions with 'W' suffix everywhere so I
don't think this should be a problem. Btw is there an option to build
juce with unicode support?

I'm included an attachment where is a cmake project which includes Fog
and adds one executable linked statically with Fog. I tested it now
and it works fine for me. Included are also various 'cmake' scripts
for simplicity.

password to the archive is 'fog' without single quotes (google doesn't
allow to post zip files including shell scripts, so I encrypted it).

Best regards
Petr Kobalicek

Fog-Static.7z

Donald Le Duck

unread,
Apr 1, 2012, 12:25:24 PM4/1/12
to fog-dev
Hi Petr,

"Btw is there an option to build
juce with unicode support?"

- Very likely


The scripts work and the solution compiles just fine.

1. Your solution contains two projects, "Fog" and "App". My setup is
different, I have Fog and the test application in two separate
solutions. Does that matter?

2. Comparing the "Configuration properties" for the projects, there
are big differences; for example "Configuration properties>>Linker"
doesn't even exist in the "App" project, but there is a "Configuration
properties>>Librarian" so it is kind of hard to merge them together
when they are that different.

All the best,
Donald















Jerry Evans

unread,
Apr 1, 2012, 12:32:21 PM4/1/12
to fog...@googlegroups.com
D.

You do not (and should not) alter any linker/librarian flags. It is
still impossible to know what is happening unless you attach the build
log for the entire solution.

Donald Le Duck

unread,
Apr 2, 2012, 6:57:38 AM4/2/12
to fog...@googlegroups.com, jerry...@novadsp.com
Hi Jerry,
 
Thanks for your patience Jerry & Petr, you guys are great! It is temting to give up, but I won't!! :-)
 
I don't have one solution, I have two. The first solution is generated with the .bat from the latest version of Fog on svn. I added "-DFOG_BUILD_STATIC=1" to the bat file. The
build log for that solution is attached.
 
The second solution is my Juce test application that should use Fog. The solution is generated by "The Introjucer" tool that comes with Juce. The
build log for that solution is also attached, it is "BuildLog2.htm".
 
All the best,
Donald
 

BuildLog.htm
BuildLog2.htm

Jerry Evans

unread,
Apr 2, 2012, 9:26:30 PM4/2/12
to Donald Le Duck, fog...@googlegroups.com, jerry...@novadsp.com
Once off only offer.

Zip *all* the source code in the most compact form possible. Ensure no
binary files. Attach and send to me:

ipp _encircled_A_ chordia _dot_ co _dot_ uk

Donald Le Duck

unread,
Apr 3, 2012, 12:14:51 PM4/3/12
to fog-dev
Hi Jerry,

I just emailed you the solutions. Thanks for taking the time!!!

Best,
Donald

Jerry Evans

unread,
Apr 4, 2012, 12:36:27 PM4/4/12
to fog...@googlegroups.com, Donald Le Duck
Hello D. Nothing. try sending to this address

Donald Le Duck

unread,
Apr 4, 2012, 1:00:23 PM4/4/12
to fog-dev
Hi Jerry,
Sent it to the nova address...
/ Donald

Sonic Fiftynine

unread,
Apr 17, 2012, 3:39:34 PM4/17/12
to fog-dev
The best way to do this in Juce is to inherit LowLevelGraphicsContext
(http://www.juce.com/juce/api/classLowLevelGraphicsContext.html) and
create your own "LowLevelGraphicsFogRenderer" similar to how Juce has
implemented it's own 2D renderer in LowLevelGraphicsSoftwareRenderer
(http://www.juce.com/juce/api/
classLowLevelGraphicsSoftwareRenderer.html)

petervy

unread,
Apr 27, 2012, 4:24:57 PM4/27/12
to fog-dev
Donald, are you still having trouble getting Fog to render to the juce
component surface?

I just recently downloaded the JUCE v2 code and played with the
jucedemo example. I added the release version of the Fog library and
successfully render directly to the component surface or any JUCE
Image. It is really easy actually! This is a code snippit I inserted
into one of the visual component...you can extend your own and
override or add to the paint event!

Fog::Painter painter; // <-- the Fog Painter
Fog::Image canvas; // <-- surrogate for the locked bitmap
Image bmp; // <-- temp image structure

void paint (Graphics& g) {

juce::Rectangle<int> bounds (owner.getLocalBounds());

bmp = Image ( juce::Image::ARGB, bounds.getWidth(),
bounds.getHeight(), false);

const Image::BitmapData bd (bmp, Image::BitmapData::readOnly);

canvas.adopt( Fog::ImageBits(Fog::SizeI( bd.width, bd.height),
Fog::IMAGE_FORMAT_PRGB32, bd.lineStride,
(uint8_t*) bd.data));

painter.begin(canvas);
painter.resetOpacity();
painter.setSource(Fog::Argb32(0x00FFFFFF));
painter.fillRound(Fog::RoundF(10.0f, 10.0f, 200.0f, 200.0f,
50.0f));

// ... anything else

}

Enjoy, life is too short!
Reply all
Reply to author
Forward
0 new messages