SFML community forums

Bindings - other languages => Java => Topic started by: pdinklag on January 29, 2012, 06:46:23 am

Title: How to build JSFML
Post by: pdinklag on January 29, 2012, 06:46:23 am
The guide to build JSFML has been moved to the Github Wiki: https://github.com/pdinklag/JSFML/wiki/Building-JSFML

Discussion should still happen here. :)
Title: How to build JSFML
Post by: pdinklag on January 29, 2012, 04:59:07 pm
I finished the build targets for Linux, concluding my mission to setup a complete building toolchain. Mac OS X is not on the list of targeted systems yet.
Title: How to build JSFML
Post by: Hiura on January 30, 2012, 09:31:05 pm
I'm currently trying to make it work on Mac but I have some trouble.

I edited the root ant script to add a Mac OS X target, added SFML's binaries to JSFML/sfml/bin/macosx_universal and finally modified SFMLNative.java to add these binaries to nativeLibs (in loadNativeLibraries).

Then I run "ant jar" in both root directory and example directory. However, running "java -jar jsfml-examples.jar" always gives me the following error :
Code: [Select]
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not find native library in the classpath: macosx_universal/libsfml-system.dylib
at org.jsfml.window.ContextSettings.<clinit>(Unknown Source)
at org.jsfml.examples.scene.Standalone.main(Unknown Source)


From the code and this error I understood that there is something wrong with nativeLibPath and PROPERTY_JSFML_BIN.

So I've got a few questions for you, pdinklag :

Code: [Select]
$ java -jar jsfml-examples.jar
objc[49496]: Class SFApplication is implemented in both /Users/marcoantognini/.jsfml/macosx_universal/libsfml-window.dylib and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[49496]: Class SFOpenGLView is implemented in both /Users/marcoantognini/.jsfml/macosx_universal/libsfml-window.dylib and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[49496]: Class SFWindow is implemented in both /Users/marcoantognini/.jsfml/macosx_universal/libsfml-window.dylib and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[49496]: Class SFWindowController is implemented in both /Users/marcoantognini/.jsfml/macosx_universal/libsfml-window.dylib and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
objc[49496]: Class SFViewController is implemented in both /Users/marcoantognini/.jsfml/macosx_universal/libsfml-window.dylib and /usr/local/lib/libsfml-window.2.dylib. One of the two will be used. Which one is undefined.
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jsfml.SFMLNative.nativeInit()V
at org.jsfml.SFMLNative.nativeInit(Native Method)
at org.jsfml.SFMLNative.loadNativeLibraries(Unknown Source)
at org.jsfml.SFMLNativeObject.<clinit>(Unknown Source)
at ShortExample.main(Unknown Source)

Just to be sure, nativeInit is defined as Java_org_jsfml_SFMLNative_nativeInit in C++, right ?

- "One of the two will be used. Which one is undefined." warning happens because libsfml-window.dylib was loaded twice. In fact, if I do not add any lib to nativeLibs and remove the following condition, then I "only" get the exception without the warnings.
Code: [Select]
           if (nativeLibs.size() == 0) {
                throw new JSFMLException("Unsupported operating system: " + osName + " " + osArch);
            }

[/list]
Title: How to build JSFML
Post by: pdinklag on January 30, 2012, 10:54:09 pm
Nice you're going for it! :)

Quote from: "Hiura"
Am I supposed to do something specific with PROPERTY_JSFML_BIN ?

That property I believe can safely be ignored. I realized that I will not want people to tamper with it. :) I should probably remove it to avoid this type of confusion.

SFMLNative checks the classpath for the "bin" folder, from which it will load the libraries specified after OS and architecture detection. Note that load order is very important here, but this doesn't seem to be your problem. From there, it will extract the binaries to the user .jsfml directory. This way I can contain all binaries for all systems in a single file and people don't have to bother.

Quote from: "Hiura"
for windows and linux you add "linux_x64/libjsfml.so" to nativeLibs. What is this library ? I can't find it.

JSFML also has C++ sources which do the actual delegation to SFML, and those are compiled and linked into jsfml.dll / libjsfml.so using the "win32", "win64", "linux32" and "linux64" targets in the ant buildfile. You will need to compile those sources into a dylib as well.

Code: [Select]
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jsfml.SFMLNative.nativeInit()V
   at org.jsfml.SFMLNative.nativeInit(Native Method)
   at org.jsfml.SFMLNative.loadNativeLibraries(Unknown Source)
   at org.jsfml.SFMLNativeObject.<clinit>(Unknown Source)
   at ShortExample.main(Unknown Source)

This is the missing libjsfml.dylib you need to create from the C++ sources.

Quote from: "Hiura"
Just to be sure, nativeInit is defined as Java_org_jsfml_SFMLNative_nativeInit in C++, right ?

Yes.

Quote from: "Hiura"
"One of the two will be used. Which one is undefined." warning happens because libsfml-window.dylib was loaded twice.

Why does that happen? I'm not sure how Mac OS X's Java ticks concerning libraries, but my guess is that if you load libsfml-graphics.dylib, it automatically loads the dependencies before that (it doesn't do that on Windows and Linux). Try removing the "libsfml-window.dylib" from the nativeLibs list and see what happens.

I guess you used some kind of "make install" when building SFML? It's not good if it suddenly uses a dylib from elsewhere, this might cause bad incompatibilities. Not sure what we can do about this.
Title: How to build JSFML
Post by: Hiura on January 31, 2012, 03:27:53 pm
Quote from: "pdinklag"
That property I believe can safely be ignored.
Ok.

Quote from: "pdinklag"
Note that load order is very important here, but this doesn't seem to be your problem.
No, it's not an issue on Mac from my experience.

Quote from: "pdinklag"
You will need to compile those sources into a dylib as well.
I did but then I 'ant clean'd it -.- . (Apple recommends to call them jnilib but this is the same as dylib.)

Quote from: "pdinklag"
Why does that happen? I'm not sure how Mac OS X's Java ticks concerning libraries
In fact this has nothing to do with Java. It's how Objective-C works when two classes with the same name are loaded from two libraries.

Quote from: "pdinklag"
Try removing the "libsfml-window.dylib" from the nativeLibs list and see what happens.
It indeed does remove the warnings.



So, I made some progress ( I essentially added the jnilib to nativeLibs ) but have a bad news for you : here is the output of the example.

Code: [Select]
$ java -jar jsfml-examples.jar
Cannot create a window from a worker thread. (OS X limitation)


No window appears (because none is created) but the music is played.
This is a restriction on SFML. I'll see what I can do to make things work.

I'll let you know when I find something.
Title: How to build JSFML
Post by: pdinklag on January 31, 2012, 03:40:09 pm
Good to see it working! (well, kindof)

Be careful with audio. SFML does not allow a manual shutdown of the AudioDevice and the JVM termination does not seem to invoke static destructors, so the AudioDevice never gets destroyed and the OpenAL thread keeps running until you kill the Java process. I'm just mentioning this in case you start wondering why the process won't end. ;)

Good luck with that window issue. Mac support would be sweet!
Title: How to build JSFML
Post by: Hiura on February 01, 2012, 12:38:52 am
Well, I've some bad news : I modified SFML source code to let the user create a window from a worker thread but I crashed as I expected. Apple documentation says a window must be created from the main thread - that's why I disabled doing so in a worker thread in the first place.

Code: [Select]
$ java -jar jsfml-examples.jar
Cannot create a window from a worker thread. (OS X limitation)
Segmentation fault: 11

with a call stack directly link to the window in cocoa api.

Now, I don't know enough Java's API but you might be able to help me : how can I force the execution of some function on the main thread ?

Beside this issue,
Quote
I guess you used some kind of "make install" when building SFML? It's not good if it suddenly uses a dylib from elsewhere, this might cause bad incompatibilities. Not sure what we can do about this.
I tried to use JSFML after removing all SFML binaries from my system except from .jsfml. Unfortunately this doesn't work :

 
Code: [Select]
$ java -jar jsfml-examples.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/marcoantognini/.jsfml/macosx_universal/libjsfml.jnilib:  Library not loaded: @executable_path/../Frameworks/libsfml-system.2.dylib   Referenced from: /Users/marcoantognini/.jsfml/macosx_universal/libjsfml.jnilib   Reason: image not found
at org.jsfml.window.ContextSettings.<clinit>(Unknown Source)
at org.jsfml.examples.scene.Standalone.main(Unknown Source)

It appears that the jnilib will try to load libsfml-system.dylib even if it was loaded by Java manually. This means that the users must install SFML in the default location.
I consider this is not an issue, at least not when SFML 2.0 will be officially released : everybody will then have the same version of SFML thus avoiding incompatibility issues.

I fork your repository here (https://github.com/mantognini/JSFML) so you can see my work if necessary.
Title: How to build JSFML
Post by: pdinklag on February 01, 2012, 07:49:49 am
I have never run into these kinds of problems, but I will read about it.
Normal Java Swing GUIs do work, right? They (the Java developers) must have found a way to create windows, so I believe it must be possible somehow.

If not, there is a plan B. That plan would be to not feature dedicated RenderWindows under JSFML on Mac OS X. Instead, one could create a simple Swing frame and put a RenderCanvas on it (planned for JSFML 1.x). I suppose that on Mac OS X, the RenderWindow(HANDLE) constructor works even in a worker thread?

Quote from: "Hiura"
It appears that the jnilib will try to load libsfml-system.dylib even if it was loaded by Java manually. This means that the users must install SFML in the default location.

Can you try running Java with the following command line argument?
Code: [Select]
-Djava.library.path=/Users/marcoantognini/.jsfml/

The java.library.path System property is used for locating dynamic libraries if they are not loaded manually using an absolute path. I tried to avoid that, because I kept running into issues with it, but it would still be a very nice solution.
Title: How to build JSFML
Post by: Hiura on February 01, 2012, 10:14:29 am
Quote from: "pdinklag"
Normal Java Swing GUIs do work, right? They (the Java developers) must have found a way to create windows, so I believe it must be possible somehow.
I'll try to look how things work. Maybe I missed something in Apple doc about JNI.

Quote from: "pdinklag"
I suppose that on Mac OS X, the RenderWindow(HANDLE) constructor works even in a worker thread?

Yes, it does.


Quote from: "pdinklag"
Can you try running Java with the following command line argument?
Code: [Select]
-Djava.library.path=/Users/marcoantognini/.jsfml/

Unfortunately, it didn't work. Same with
Code: [Select]
-Djava.library.path=/Users/marcoantognini/.jsfml/macosx_universal/
 :?
Title: How to build JSFML
Post by: pdinklag on February 01, 2012, 01:53:22 pm
It appears to me that the depdendency's full path is written into the jnilib when it is linked. Do you have any influence on that?
Title: How to build JSFML
Post by: Hiura on February 01, 2012, 03:19:30 pm
Yes, you're right!

I can use install_name_tool (http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html) to play with that but this is only a minor issue compared to the window creation.
Title: How to build JSFML
Post by: pdinklag on February 01, 2012, 04:01:00 pm
Still it's much more convenient if that's out of the way! :)
I will try and do some research on the window thing myself in a bunch, see what I can find out.
Title: How to build JSFML
Post by: pdinklag on February 01, 2012, 04:57:27 pm
Found this:
http://stackoverflow.com/questions/3976342/running-swt-based-cross-platform-jar-properly-on-a-mac

In short, try adding this command line argument:
Code: [Select]
-XstartOnFirstThread

Apparently, this can cause trouble on other systems, so we'll have to think of something here. But let's see if this does the trick first. I'm not too sure about that, since I could not get any information on this flag outside a SWT context. JSFML is not a SWT application.
Title: How to build JSFML
Post by: Hiura on February 02, 2012, 07:00:04 pm
I tired some stuff directly in SFML yesterday but only succeed to break the C++ examples.  :roll:


Quote
In short, try adding this command line argument:

Code: [Select]
-XstartOnFirstThread
IT WORKS !  :D

By the way, the example is really cool! I added 1'600 entities without getting any slowdown (run with ~ 60 FPS as expected).

I'll work on the dylib and update my fork. I'll keep you informed when I get something publishable.
Title: How to build JSFML
Post by: pdinklag on February 02, 2012, 07:23:09 pm
Hah, awesome! :D

Well yeah, sort it out and file a pull request or something. I haven't worked with those yet but I think I can handle them.

One little request: I noticed you called it "macosx_universal", I believe because Mac OS X always runs on one and the same architecture and not on 32bit or 64bit. I'd say just leave the "_universal" part.

Apart from that, great to know Mac OS X is on the list. :) When it's time to pack up a release of JSFML 1.0 I'll let you know, then you can send me the libjsfml.dylib and I can put it into the final jar. Going to add you to the credits later.

BTW, did you try auto-extraction again? It would be cool if that worked. I can explain how to test it properly if you haven't worked it out yet.
There is one problem left to solve really. On Mac OS X, any JSFML will have to be started using
Code: [Select]
-Djava.library.path=~/.jsfml/macosx -XstartOnFirstThread
However, this cannot be done from within Java because they are JVM flags.

EDIT:
Things are probably way easier if I just give you access to the repo. There's no reason not to trust you, I guess. ;) Let's see if I can get that done...
Title: How to build JSFML
Post by: Hiura on February 02, 2012, 07:43:10 pm
Quote from: "pdinklag"
Well yeah, sort it out and file a pull request or something.

Things are probably way easier if I just give you access to the repo.
I'll go for a pull request so you have one nice commit and not a bunch of try and mistake commits. :wink:

Quote from: "pdinklag"
One little request: I noticed you called it "macosx_universal", I believe because Mac OS X always runs on one and the same architecture and not on 32bit or 64bit. I'd say just leave the "_universal" part.
The OS is running either in 32bits or 64bits (with Snow Leopard you can choose which one you want at boot time) but these binaries have both architectures (they are two files in one) in order to work on both architectures. So keeping the _universal postfix would prevent any confusion. However, if you think is too ugly I can remove it, of course.

Quote from: "pdinklag"
BTW, did you try auto-extraction again? It would be cool if that worked. I can explain how to test it properly if you haven't worked it out yet.
There is one problem left to solve really. On Mac OS X, any JSFML will have to be started using
Code: [Select]
-Djava.library.path=~/.jsfml/macosx -XstartOnFirstThread
However, this cannot be done from within Java because they are JVM flags.
Not yet, will test it tomorrow. I let you know if I need help with this. thanks.
Title: How to build JSFML
Post by: pdinklag on February 02, 2012, 07:53:10 pm
Just leave the _universal in there then. :)
I don't know about Mac OS X details.

I added you as a collaborator btw, so once we got that pull request sorted you can work on it directly.
Title: How to build JSFML
Post by: Hiura on February 03, 2012, 03:04:29 pm
Ok, I've made some progress! It works without -Djava.library.path (in fact, I didn't succeed to make it work with it but that's another story).  :)

I had to edit SFML binaries so they can be loaded from anywhere. That was no fun!

Anyway, there's only two thing I have to do before everything is clean.
Do you know how to add a post action in the ant script so I can run a shell command on the produced object (in this case, libjsfml.jnilib) ?

The second thing is about <signjar /> stuff. I couldn't make it work (if I give no password the compilation fails with "[signjar] jarsigner: you must enter key password"; and if I give a password it complains with "[signjar] jarsigner error: java.lang.RuntimeException: keystore load: /Users/marcoantognini/.keystore (No such file or directory)") so I commented it out.
How can I disable it only if no password was given by the user ?

I'm not familiar with this ant thing.
Title: How to build JSFML
Post by: pdinklag on February 03, 2012, 03:25:56 pm
Ant is just an awesome build tool in the Java world. :) I prefer it over Maven, which might be better for larger projects, I don't know.

Anyway, the build file is basically nothing but a makefile in a readable XML format. It consists of several targets which hold actions (called "tasks") that are processed sequentially (unless otherwise specified, but that doesn't matter now).

Quote from: "Hiura"
Do you know how to add a post action in the ant script so I can run a shell command on the produced object (in this case, libjsfml.jnilib) ?

You would do that using the "exec" task: http://ant.apache.org/manual/Tasks/exec.html
Code: [Select]

<exec executable="command">
  <arg value="argument1"/>
  <arg value="argument2"/>
  <arg value="argument3"/>
</exec>


Inside those arguments, you can best get the path to libjsfml.jnilib using:
Code: [Select]

${cpp.out}/${arch}/lib${jsfml.bin}.jnilib

That can simply be entered into an arg="" attribute.

Quote from: "Hiura"
The second thing is about <signjar /> stuff. I couldn't make it work (if I give no password the compilation fails with "[signjar] jarsigner: you must enter key password"; and if I give a password it complains with "[signjar] jarsigner error: java.lang.RuntimeException: keystore load: /Users/marcoantognini/.keystore (No such file or directory)") so I commented it out.
How can I disable it only if no password was given by the user ?

Ignore that stuff.

Signing a jar has nothing to do with Ant, but is a Java thing. For now, it's not relevant, but it will be once the features to run RenderWindows in browser applets are in it. If you run an applet, it will not work unless the jar is "signed". The signing happens against a certificate that the user needs to accept when loading the applet. To do that, you need a key store and a password.

You could create your own key store now and create such a certificate, but it doesn't really matter if it fails to sign. This only means that you cannot put it in a browser applet. :)

I will probably make the signing a separate target because it will be needed for actual releases and applet tests only.
Title: How to build JSFML
Post by: Hiura on February 04, 2012, 10:43:16 am
Wow, thanks for all the details! I'll finish the job during next week; probably offline so the shiny pull request will be ready one week later! ;-)
Title: How to build JSFML
Post by: Jove on February 24, 2012, 04:32:49 pm
Hi.

I managed to build JSFML and when running the "Short Example" I receive this error. I'm a bit stuck now.

Code: [Select]
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not find native library in the classpath: windows_x64/libsndfile-1.dll
at org.jsfml.SFMLNativeObject.<clinit>(Unknown Source)
at ShortExample.main(ShortExample.java:15)


Any hints on what I might have done wrong?
Title: How to build JSFML
Post by: pdinklag on February 26, 2012, 08:42:55 am
That error message means that the dll is not available for JSFML to load.
You built SFML yourself, right? You need to make sure that the SFML dll files (and its dependencies, like libsndfile-1.dll, which is included in SFML) are in the classpath of your Java application.

In your case, since you are running on Windows 64-bit, your classpath must somewhere contain the directory windows_x64 with all the DLLs in it.

Anyway, to build JSFML, all this should not be necessary, neither is it recommended, because if you build a newer version of SFML and try to use it with JSFML, there might be incompatibilities. That's why the latest supported SFML dlls are pre-built by me and uploaded to the git repository.

All you should be needing to do to build JSFML is this (command-line using ant):
Code: [Select]

ant win64
ant jar
cd examples
ant jar


The first will build the C++ sources into a jsfml.dll file. The "JAR" targets will ask you for a password, simply enter anything you want. I will change the build targets soon so that is not necessary.

In the "out" directory of your JSFML clone, there should be a jsfml.jar (containing all the DLLs) which you can use for your project, and the examples jar file.
Title: How to build JSFML
Post by: Jove on February 26, 2012, 09:30:50 am
Looks like I did everything correctly, except....

My out\bin\windows_x64 directory is completely empty, so I did the ant win64 step again and the build fails with :

Code: [Select]
D:\Program Files\Java\JSFML\build.xml:220: The directory D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 does not exist

Sure enough it doesn't exist and most likely because I'm using VS2010 Express :(

I did however install the compilers when installing the Microsoft SDK, so they are present in a different location (C:\Program Files (x86) Microsoft Visual Studio 9.0\VC\bin\amd64). Is there any way to use them to build the 64 version?
Title: How to build JSFML
Post by: pdinklag on February 26, 2012, 10:23:16 am
Sounds more like MS Visual Studio 2008 Express?
Anyway, this is good to know. There is this file called "windows-find-vs.bat". I use this to find the MS Visual Studio installation from the registry, however, I only know the registry keys for MSVC++ 2010 Express. :)

If you change the batch to:
Code: [Select]

@echo off
echo "C:\Program Files (x86) Microsoft Visual Studio 9.0\"

Then it should work.

You can help me by checking your registry and see what there is under the key
Code: [Select]
HKEY_CURRENT_USER\Software\Microsoft\VCExpress\
Is there a node called "9.0_Config" with a value called "ShellFolder"? If so, I can extend that batch file to detect it automatically next time. :)
Title: How to build JSFML
Post by: Jove on February 26, 2012, 02:43:01 pm
Things have improved!  Changes to the .bat worked and now I get no compile errors in Eclipse, so that's fixed (thanks!).

However, when I run the ShortExample the 800x600 window appears with only solid white visible, not responding at all.

There is a warning that "Build path specifies execution environment JavaSE-1.6. There are no JREs installed in the workspace that are strictly compatible with this environment."


To answer your registry question; I have only a '10.0_Config' node with no ShellFolder value.
Title: How to build JSFML
Post by: pdinklag on February 27, 2012, 04:30:54 am
That's probably because "cute_image.jpg" etc does not exist. ;)
It's only example code for the website at some point, it's not really supposed to work.

Try to run org.jsfml.examples.tutorials.BasicTutorial instead, that should give you a basic red screen.
Title: How to build JSFML
Post by: Jove on February 27, 2012, 10:40:28 pm
"cute_image.jpg" did exist, along with all the other files required.  :wink:

However, the BasicTutorial did indeed run correctly with a juicy red screen and no other issues.

Looks ok so far.
Title: Re: How to build JSFML
Post by: pdinklag on March 26, 2012, 05:48:25 pm
Added Mac OS X build information from the readme file.
Thanks go to Hiura. :)
Title: Re: How to build JSFML
Post by: pengcheng on August 24, 2012, 07:55:46 am

Windows
To build on Windows (targets win32 and win64), you will require the Windows SDK (latest possible) as well as the Microsoft Visual C++ compiler. Note that the compiler can be installed along with the Windows SDK, so you don't necessarily need the Microsoft Visual Studio.

The path of the Windows SDK and the MS Visual C++ compiler is retrieved automatically using the provided batch scripts. Do not hesitate to report any problems with these scripts, but if you do let me know which Windows and WinSDK / MSVC++ you have installed.


Hello. I am running:
    Vista Home Basic;
    Windows SDK with VC++ compiler installed;
    No VC++ installed;
    Visual C# 2008 Expression installed;

Dir list:
C:\Program Files\Microsoft SDKs\Windows\v6.0
    Bin
    Include
    Lib
    VC
        Bin
        INCLUDE
        LIB
C:\Program Files\Microsoft Visual Studio 9.0
    Common7
    VC
    VC#

To build win32 successfully, I have to use:
   <target name="my_win32" description="Build the C++ sources for Windows 32 bit.">
      
      <property name="path.vs" value="C:/Program Files/Microsoft SDKs/Windows/v6.0" />
      <property name="path.winsdk" value="C:/Program Files/Microsoft SDKs/Windows/v6.0" />
      
      <property name="cl" value="C:/Program Files/Microsoft SDKs/Windows/v6.0/VC/Bin/cl.exe" />
      <property name="link" value="C:/Program Files/Microsoft SDKs/Windows/v6.0/VC/Bin/link.exe" />
      <property name="cwd" value="C:/Program Files/Microsoft Visual Studio 9.0/Common7/IDE" />
      
      <property name="vs.lib" value="C:/Program Files/Microsoft SDKs/Windows/v6.0/VC/lib" />
      <property name="winsdk.lib" value="C:/Program Files/Microsoft SDKs/Windows/v6.0/Lib" />
      
      <property name="arch" value="windows_x86" />
      
      <ant target="windows.build" />
   </target>


However, when running ShortExample:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\pengcheng\.jsfml\windows_x86\sfml-system-2.dll: Can't find dependent libraries
   at java.lang.ClassLoader$NativeLibrary.load(Native Method)
   at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
   at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1674)
   at java.lang.Runtime.load0(Runtime.java:770)
   at java.lang.System.load(System.java:1003)
   at org.jsfml.SFMLNative.loadNativeLibraries(Unknown Source)
   at org.jsfml.SFMLNativeObject.<clinit>(Unknown Source)
   at ShortExample.main(ShortExample.java:22)

Using MingW "objdump -x sfml-system-2.dll", this dll imports 3 dlls:
    KERNEL32.dll
    MSVCR100.dll
    MSVCP100.dll
The last 2 of which don't exist under "C:\Windows\System32", where there does exist "msvcp60.dll, msvcp71.dll, msvcr71.dll".
Title: Re: How to build JSFML
Post by: pdinklag on August 24, 2012, 01:20:26 pm
Quote from: pengcheng
Using MingW "objdump -x sfml-system-2.dll", this dll imports 3 dlls:
    KERNEL32.dll
    MSVCR100.dll
    MSVCP100.dll
This happens because I compiled and linked the SFML binaries using the MS Visual C++ compiler included in WinSDK 7 (Express 2010), you say that you have WinSDK 6 installed (which includes Express 2008).

I would recommend upgrading to WinSDK 7 (it supports Windows XP SP3, Vista and Windows 7) and build JSFML using the VC++ Express 2010 compiler.

Installing the Microsoft Visual C++ 2010 Redistributable Package (http://www.microsoft.com/en-us/download/details.aspx?id=5555) might do the trick for you as well, but I'm not sure if it's a good idea to mix VC++ 2008 components (your jsfml.dll) with VC++ 2010 components (the SFML binaries).
Title: Re: How to build JSFML
Post by: pengcheng on August 27, 2012, 10:51:21 am
After installing WinSDK7.1 with VC++ 2010 compiler selected, and rebuilding "win32" ant target, the "Standalone" sample works!

One issue:
In my registry there's no "HKLM\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VS" "ProductDir".
Instead, there's "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VC" "ProductDir"=C:\Program Files\Microsoft Visual Studio 10.0\VC\.

So I use:
<target name="my_win32" description="Build the C++ sources for Windows 32 bit.">
      
      <property name="path.vs" value="C:/Program Files/Microsoft Visual Studio 10.0" />
      <property name="path.winsdk" value="C:/Program Files/Microsoft SDKs/Windows/v7.1" />
      
      <property name="cl" value="${path.vs}/VC/bin/cl.exe" />
      ...


One question:
Does the end user need to install VC++ 2010 runtime (to get msvcr100.dll & msvcp100.dll under C:\Windows\System32)? What'll be the supporting Windows environments of JSFML?
Title: Re: How to build JSFML
Post by: pdinklag on August 27, 2012, 11:05:33 am
Good to know it works! :)

Quote from: pengcheng
In my registry there's no "HKLM\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VS" "ProductDir".
Instead, there's "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\VC" "ProductDir"=C:\Program Files\Microsoft Visual Studio 10.0\VC\.
Thanks, I will update the batch later so that gets detected.

Quote from: pengcheng
Does the end user need to install VC++ 2010 runtime?
Yep, they will have to install it. A lot of Windows games need it these days, so it should not be much of a problem.

I should probably add an info line about the dependencies in the readme.
On Windows, you will need the VC++ 2010 runtime, on Linux, you need some packages (I know of libglew1.6 and libjpeg8 right now). No idea about Mac OS X. But this should be in the readme.
Title: Re: How to build JSFML
Post by: Hiura on August 27, 2012, 06:48:00 pm
Quote
No idea about Mac OS X
To use JSFML on Mac you only need jsfml.jar. That should be all.  :)
Title: Re: How to build JSFML
Post by: pdinklag on August 27, 2012, 07:01:52 pm
Like Ubuntu (and its spawns Linux Mint etc) then, great! :)
Title: Re: How to build JSFML
Post by: Groogy on September 10, 2012, 12:45:41 am
Thought should try this binding out and give Java another chance though I can't create a basic application because you are trying to use libGLEW-1.6 while I only have libGLEW-1.8

Sitting on Arch Linux and I don't feel comfortable with this system yet to start pasting around stuff like glew libraries ^^
Title: Re: How to build JSFML
Post by: pdinklag on September 10, 2012, 07:11:15 am
I hate Linux environments for these kinds of things...
Thanks for informing! I have yet to try and set up an Arch Linux VM. I suppose installing libGLEW-1.6 parallely isn't allowed by pacman?
Title: Re: How to build JSFML
Post by: Groogy on September 10, 2012, 07:18:16 am
Well I think it would be allowed but there only seems to be version 1.8 in the repo =/
Thing with Arch is that everything is bleeding edge so i guess they remove packages as they become "obsolete"
Title: Re: How to build JSFML
Post by: pdinklag on September 10, 2012, 08:13:58 am
OK, so is this similar to the problem with libjpeg / libjpeg-turbo I had on Fedora (the repo only has libjpeg-turbo).

Can you use / compile SFML, ie will it automatically link against libglew-1.8?
Title: Re: How to build JSFML
Post by: Groogy on September 10, 2012, 09:03:17 am
Yepp it will
Title: Re: How to build JSFML
Post by: pdinklag on September 15, 2012, 10:07:22 am
Hm, is there any way in Linux to link a library against two different versions of another library?

Unless the API changed or functionality of the later version is used, I understand that won't be possible, but in a case like this I wouldn't see a lot of trouble with it technically. Does SFML linked against libglew-1.8 work with libglew-1.6 ?
Title: Re: How to build JSFML
Post by: Groogy on September 16, 2012, 10:49:02 pm
Don't think so, but why do you have to link specifically to a version? You should be able to just link against libglew and have the already in place system for this handle it for you.

Don't know how experienced you are with Linux but we have something called a symbolic link. And you always keep a symbolic link to the latest version of the library without the version numbers.

Well it's simplified but it is something like:
libsomelibrary.so.1.9.1
libsomelibrary.so.1.9
libsomelibrary.so.1
libsomelibrary.so

So you can have several versions installed at the same time. The symbolic link is only used at compile time and the resulting binary remembers exactly what version it was compiled with.
Title: Re: How to build JSFML
Post by: Laurent on September 17, 2012, 07:54:48 am
Quote
The symbolic link is only used at compile time and the resulting binary remembers exactly what version it was compiled with.
To be more precise, the resulting binary remembers the SO version it was compiled with, which is supposed to be the same for binary compatible versions of the library. The SO version can be the major version number, or major and minor version numbers, depending on the versioning conventions of the library.

The problem with some libraries is that they break binary compatibility with each new version, so other users must have the exact same version your project was compiled with.
Title: Re: How to build JSFML
Post by: pdinklag on September 17, 2012, 01:17:10 pm
Maybe I should go for a different approach after all and make the Linux version depend on the SFML 2 package and treat it as an external dependency. That's probably how it should be done anyway.

In that case, can I consider the current SFML2 library file names final so it will work once SFML2 appears in public repositories? What can be done for the "transition phase" - I don't really think SFML2 will be in any repos until a few months after the release...

For Windows, I would still prefer to contain the supported SFML binaries in the release, however, maybe I should place them at a relative location in the file system instead of packing them up. For Mac, since the linking process seems to require a bunch of tricks, I believe the same can be said, Hiura will know for sure though. ;)
Title: Re: How to build JSFML
Post by: Laurent on September 17, 2012, 01:24:30 pm
Quote
Maybe I should go for a different approach after all and make the Linux version depend on the SFML 2 package and treat it as an external dependency. That's probably how it should be done anyway.
Absolutely!

Quote
In that case, can I consider the current SFML2 library file names final so it will work once SFML2 appears in public repositories?
Yep.

Quote
What can be done for the "transition phase" - I don't really think SFML2 will be in any repos until a few months after the release...
Add a link to the SFML download page? :P
Title: Re: How to build JSFML
Post by: Hiura on September 17, 2012, 03:09:34 pm
Quote
For Mac, since the linking process seems to require a bunch of tricks, I believe the same can be said, Hiura will know for sure though.
Yeah, I also think it's the easiest way to go.
Title: Re: How to build JSFML
Post by: pdinklag on September 19, 2012, 03:51:04 pm
Linux now requires the LD_LIBRARY_PATH variable to contain a path to the SFML libs, because the JVM will use that one to find libraries. I guess it's not any worse than the -XstartOnFirstThread that's required on Mac.

I will update the wiki about this soon.
Title: Re: How to build JSFML
Post by: pdinklag on October 17, 2012, 07:50:11 pm
Quote
Add a link to the SFML download page? :P
If you download a game from somewhere, you expect to hit its executable and it runs. You don't expect that you have to download sources and compile another package first and set several environment variables. Maybe everyday Linux users do expect that, I don't know, but IMO it just plain sucks.

So, with all the dependency and version crap, I can't do anything to provide out-of-the-box functionality on "Linux" whatsoever. The only chance that I see is to make it work for the most common distributions. The best candidate I see is Ubuntu. I tested this out-of-the-box feature on Ubuntu and Linux Mint and it worked perfectly. For other distributions, people will have to resort to the LD_LIBRARY_PAH variable. It sucks, but apparently, there's no other way.
Title: Re: How to build JSFML
Post by: pdinklag on October 19, 2012, 08:39:11 am
libGLEW seems to maintain binary compatibility, stressing "binary".
Creating a soft link from libGLEW.so.1.6 to libGLEW.so.1.5 yields no problems whatsoever. I'm not sure how good an approach like this is, but it seems to work out fine.
Title: Re: How to build JSFML
Post by: kryx on October 08, 2014, 08:08:31 am
Hi,

I'm trying recompiling the news source of sfml at master into jsfml. But this seems don't work.

When I compiling, I receive the error:

JSFML-master\src\cpp/JNI/org_jsfml_graphics_SFMLNativeDrawer.cpp(25) : error C2440: 'cast de type' : impossible de convertir de 'jint' en 'sf::BlendMode'
     [exec]         Aucun constructeur n'a pu prendre le type de source, ou la résolution de la surcharge du constructeur était ambiguë
     [exec] JSFML-master\src\cpp/JNI/org_jsfml_graphics_SFMLNativeDrawer.cpp(42) : error C2440: 'cast de type' : impossible de convertir de 'jint' en 'sf::BlendMode'
     [exec]        Aucun constructeur n'a pu prendre le type de source, ou la résolution de la surcharge du constructeur était ambiguë

In fact, BlendMode.h seems to be different in sfml 2.1 and sfml-master. But I need this rebuild in my project because this is a bug in jsfml actually that don't clear properly the renderTexture on some plateforms.

Someone can maybe help me to write the good BlendMode class in java to do a nice compiling for the new sfml sources?

Thanks a lot
Title: Re: How to build JSFML
Post by: Hiura on October 08, 2014, 09:35:51 am
As far as I know, JSFML's master branch is not in sync with SFML's master branch. You have to use SFML 2.1 with JSFML. I think Patrick said he'll update JSFML when SFML 2.2 is released.

BTW, this is reaaally some necromancy you did there.
Title: Re: How to build JSFML
Post by: kryx on October 08, 2014, 09:47:17 am
I know and I understand why you don't follow the sfml-master.

But I really need this changes (it's a primary major bug) and I need to rebuild all the sources. It's done in c++, but I need only the BlendMode.java (if I have understood) to compile in jsfml

in c++, the class BlendMode evolve from:

enum BlendMode
{
    BlendAlpha,    ///< Pixel = Source * Source.a + Dest * (1 - Source.a)
    BlendAdd,      ///< Pixel = Source + Dest
    BlendMultiply, ///< Pixel = Source * Dest
    BlendNone      ///< Pixel = Source
};

to

struct SFML_GRAPHICS_API BlendMode
{

    enum Factor
    {
        Zero,             ///< (0, 0, 0, 0)
        One,              ///< (1, 1, 1, 1)
        SrcColor,         ///< (src.r, src.g, src.b, src.a)
        OneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
        DstColor,         ///< (dst.r, dst.g, dst.b, dst.a)
        OneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
        SrcAlpha,         ///< (src.a, src.a, src.a, src.a)
        OneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
        DstAlpha,         ///< (dst.a, dst.a, dst.a, dst.a)
        OneMinusDstAlpha  ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
    };

    enum Equation
    {
        Add,     ///< Pixel = Src * SrcFactor + Dst * DstFactor
        Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor
    };

    BlendMode();


    BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add);


    BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor,
              Equation colorBlendEquation, Factor alphaSourceFactor,
              Factor alphaDestinationFactor, Equation alphaBlendEquation);

    ////////////////////////////////////////////////////////////
    // Member Data
    ////////////////////////////////////////////////////////////
    Factor   colorSrcFactor; ///< Source blending factor for the color channels
    Factor   colorDstFactor; ///< Destination blending factor for the color channels
    Equation colorEquation;  ///< Blending equation for the color channels
    Factor   alphaSrcFactor; ///< Source blending factor for the alpha channel
    Factor   alphaDstFactor; ///< Destination blending factor for the alpha channel
    Equation alphaEquation;  ///< Blending equation for the alpha channel
};


SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right);


SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right);

SFML_GRAPHICS_API extern const BlendMode BlendAlpha;    ///< Blend source and dest according to dest alpha
SFML_GRAPHICS_API extern const BlendMode BlendAdd;      ///< Add source to dest
SFML_GRAPHICS_API extern const BlendMode BlendMultiply; ///< Multiply source and dest
SFML_GRAPHICS_API extern const BlendMode BlendNone;     ///< Overwrite dest with source

} // namespace sf
 
Title: Re: How to build JSFML
Post by: Hiura on October 08, 2014, 09:49:06 am
You can fork JSFML and update it if you know how jni and cie work (I don't).
Title: Re: How to build JSFML
Post by: zsbzsb on October 08, 2014, 07:13:02 pm
@kryx, if JSFML uses the official CSFML (I don't know if it does) then the hard part is already done, all you would need to do is update JSFML.
Title: Re: How to build JSFML
Post by: kryx on October 08, 2014, 11:15:58 pm
mmmh yes, I suppose it to...

I have compile withour error the 2.1 version, so I know that I don't do errors.
But as I don't know what I must change in JSFLM (BlendMode.java?) to work fine, I have applied some majors corrections to my 2.1 version SFML and compile it...

But if you know how to do, I am very interesting by learn it!
Title: Re: How to build JSFML
Post by: pdinklag on October 14, 2014, 10:30:26 am
SFML is used directly, not CSFML.
And correct, the master branch is still based on the SFML 2.1 API, but you found this out already. :)

From what it looks (I haven't really looked at any 2.2 API changes yet), the BlendMode enumeration will cease to exist and be replaced by a simple class that represents that struct you posted.

This will have an effect on the central drawing dispatcher: SFMLNativeDrawer. The method signatures will need an update from an integer blend mode ordinal to, probably, two integers: factor and equation ordinals. The respective native code will have to be updated accordingly.

It should not be too much work, really, but I'd like to wait until the 2.2 API is "done", so I can take a week or two and do a quick update of JSFML.
Title: Re: How to build JSFML
Post by: kryx on October 14, 2014, 05:55:04 pm
Thanks a lot!

Now it isn't urgent as I have applied changes in previous version, but I'll take the 2.2 when it arrive :D

I hope that Anti-aliasing on RenderTexture will be implemented... :D (but no link here :D)

Have a nice day!