Can native C programs be used in LibGDX? - c

I have a program in C which i would like to call and use it in LibGDX so that i can use it both for android and desktop. So can you suggest me methods to call a C file into LibGDX?

To be clear, I believe you have an app written in Java that uses Libgdx currently, and you would like to extend that app by including a C library and making calls out to the C library from the Java application.
Libgdx does not provide any special support for third-party libraries, native or Java. You will have to use the backend platform's APIs to call out to native code (JNI, NDK, etc).
You should be able to add your library to the Android and Desktop backend projects, and access it via a Platform Interface. It is probably not possible to use the GWT-backend (unless you have a C to Javascript compiler). For iOS you would need to build your library for iOS, and then figure out how to link it into the Xamarin (or robovm) build process for your app. While I'm going to assume this is possible, I suspect neither is easy to accomplish.

Related

Can I make an android game using OPEN GL ES with c language?

I saw that most OPEN GL ES resources are written in java. And i don't know java. Can I make an android game using OPEN GL ES with c language? Is this possible? If possible, will I have trouble in compiling and similar situations?
Note:I want to make a 2d game for android.
Yes you can. Use Android NDK - native developer kit for C/C++ developers: https://developer.android.com/ndk
The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages.
Example:
https://developer.android.com/ndk/samples/sample_na
The native-activity sample resides under the NDK samples root, in folder native-activity. It is a very simple example of a purely native application, with no Java source code. In the absence of any Java source, the Java compiler still creates an executable stub for the virtual machine to run. The stub serves as a wrapper for the actual, native program, which is located in the .so file.

How can I incorporate a C project in Xamarin Forms?

I have a project, written in C which I want to use in Xamarin Forms. What is the best way to use this code? Generate libraries for each platform?
What I'd prefer is to have one wrapper that I can use in shared code that doesn't have to be implemented for each platform.
Unfortunately, the way binding works is different for Android and iOS, so you would need to generate libraries for each platform.
You can read more about how that is done here for iOS and here for Android. For iOS, you can consider using Objective Sharpie which will do the most of the work for you.
Afterwards, you can simply use DependecyService to access the native platform features.

Can i create apple or android application using c?

I was wondering if i can create an application using C because android applications nowadays are programed using java and i don't have a lot of knowledge in Java programing
You can use something called the NDK to create statically linked libraries that Android can call. Remember these are linked libraries (.so files) and so they do not have a Main in the traditional sense. To find more information on that follow this link. http://developer.android.com/tools/sdk/ndk/index.html
It's important to note that you will still need to write some Java code but it allows you to do a lot of the non GUI work via C code.
On the flip side IOS programs are written in Objective-C which sounds similar to C but from what I've been told it's very far apart.

Run native C++ code on codename one

I have an android app where I am running native C++ code using JNI (Java Native Interface). I want to port it to codename one so that it can run on iOS as well. What is the alternative to JNI on codename one that will allow me to run my native C++ code?
You can call C++ from Objective-C we did just that in the ZXing demo for the iOS port see: http://github.com/codenameone/codenameone-demos
For Android you will need to wrap the C++ code using the NDK in order to use it. Chen discussed this a while back in a blog post here: http://www.codenameone.com/blog/integrating-android-3rd-party-libraries-jni.html
The relevant section is this:
We recently added a 3rd option :aar files. The aar file is a binary format from Google that represents an Android Library project.
One of the problem with the Android Library projects was the fact that
it required the project sources which made it difficult for 3rd party
vendors to publish libraries, so android introduced the aar file which
is a binary format that represents a Library project.
To learn more about arr you can read this.
You can link an aar file by placing it under the native/android and
the build server will link it to the project.
Notice that for Android you might want to use the new gradle build system which would also make this simpler: http://www.codenameone.com/blog/material-icons-background-music-geofencing-gradle.html
Codenameone has it's native interface that allows adding native codes.
Each platform has it's native code and as far as I know C++ is not in any of them.
I would suggest you translate your code from C++ to Java and Objective-C manually and you can use those code in implementing CN1 native interface.
Read about Native Interface here and also have a look at native demo

How to develop GTK+ programs on windows?

There isn't a windows binary release, so when it says that they are cross-OS, they mean you can write source to compile on windows, but you have to develop in linux/osx? But then what if you want to make calls to win32api within the app, and want to test as you go along?
They mean you can develop under Windows and you do not have to compile the libraries for yourself.
Binaries for GTK+ and its dependencies can be found here.
Cross OS means that the same API is available across all supported platforms.
Direct calls to the win32 API can be made normally in a GTK+ application.

Resources