brackeen / glfm Goto Github PK
View Code? Open in Web Editor NEWOpenGL ES and input for iOS, tvOS, Android, and WebGL
License: zlib License
OpenGL ES and input for iOS, tvOS, Android, and WebGL
License: zlib License
First of all, thank you for your awesome work on glfm!
Then, a suggestion. As a seasoned game developer, but fairly big noob at Android, I had a lot of trouble getting the example to work based on your instructions in the readme
I was using the latest AndroidStudio downloaded today (version 3.5.2) and followed your instructions to the letter. So I replaced the android manifest and the app/build.gradle with what you supply, but it didn't work at all. I had nothing but weird linking errors (in xml files...) and tried to fix things for about 2 hours.
Frustrated, I started from scratch with a new and fresh "No Activity" project in AndroidStudio, and tried careful copy/pasting from your app/build.gradle file instead. I just copied android/defaultConfig/externalNativeBuild, android/sourceSets.main and android/externalNativeBuild, and it worked instantly!
So my recommendation would be to NOT tell people to bluntly replace their app/build.gradle file, but copy/paste the necessary sections as mentioned above instead. It's a lot better advice as messing with SDK versions and dependencies will get you in a world of hurt!
When I start my glfm based app, the first few short moments there is a bright green flash behind the rendered scene.
See the video below:
This happens every time I minimize the app, and go back in. Also when I start the app for the first time.
It seems to be the green default Android icon that is mixed in with my rendering.
Now I've double checked that:
GL_COLOR_BUFFER_BIT
and GL_DEPTH_BUFFER_BIT
)glClearColor
and glClearDepthf
Is there anything glfm related that could cause this? Is there some sort of blending setting I can change in Android or something? I realize this MIGHT not be glfm related, but as of now I just don't know for certain.
Thanks in advance for any help!
Marc
Also, make the GLFM AppDelegate optional.
ISSUE RESOLVED
A very kind guy already helped me, see: https://github.com/EXLMOTODEV/GLFM-example
Hello!
I'm new to Android and gradle. Can't get your example to compile.
Briefly, I took gradle settings from a successfully-compiled hello-jniCallback (google ndk sample; all compiled and ran fine), and used your build.gradle and AndroidManifest.xml from readme. Got errors with resources (mipmaps).
In more detail:
include ':example'
../../../../CMakeLists.txt
to ../CMakeLists.txt
(and similarly ../example/assets
)Got error:
$ ./gradlew build
...
error: resource mipmap/ic_launcher (aka com.brackeen.glfmexample:mipmap/ic_launcher) not found.
...
I tried then to copy directory res
(with some mipmaps) from hello-jniCallback (also tried from a very basic hello-jni). No matter what I tried to make gradle happy, I only got various error messages. This directory, res
, seems to be too tightly coupled with that particular google sample.
Am I moving in the right direction? Should I proceed with getting hello-jniCallback res
directory "approved" by gradle? Is it a sensible idea — (for you) to add this resource directory (and may be, corrected build.gradle and AndroidManifest.xml) to the repo?
Thanks.
i learn that can support ios android and web, how about maos and windows?
how about vulkan?
This file contains GLFMAppDelegate and GLFMViewController, amongst other things.
Having this all in one files makes it harder to navigate to one of these things (e.g. in AppCode "quick open" then typing GLFMAppDelegate doesn't work).
It also makes tracking source control changes to one of these classes more tricky (e.g. I can't easily just see changes to GLFMViewController).
Hello everyone,
I don't expect everything because GLFM_Display is as pointer for C#
Console.WriteLine("Hello GLFW ( GLFM WASM )");
GLFW.Display* glfw_display = (GLFW.Display*)Marshal.SizeOf<GLFW.Display>();
GLFW.PlatformData* glfw_platformdata = (GLFW.PlatformData*)Marshal.SizeOf<GLFW.PlatformData>();
glfw_display->platformdata = glfw_platformdata;
GLFW.GetDisplaySize(glfw_display, out int glfw_width, out int glfw_height);
glfw_width = glfw_platformdata->width;
glfw_height = glfw_platformdata->height;
Console.WriteLine("GLFW Display WIDTH: " + glfw_width);
Console.WriteLine("GLFW Display HEIGHT: " + glfw_height);
I have tried to add in WASM but why do width and height jhave only "0"?
I thought glfmGetDisplayWidth
and glfmGetDisplayHeight
are implemented on Emscription
And It doesn't throw errors. just shows only 0.
<ItemGroup>
<NativeFileReference Include="libEGL.c" ScanForPInvokes="true" />
<NativeFileReference Include="openal32.c" ScanForPInvokes="true" />
<NativeFileReference Include="glfm_platform_emscripten.c" ScanForPInvokes="true" />
</ItemGroup>
Write class outside of Program's class
// GLFW ( GLFM WASM )
internal unsafe static class GLFW
{
public const int MAX_ACTIVE_TOUCHES = 10;
[StructLayout(LayoutKind.Sequential)]
public unsafe struct PlatformData
{
public bool multitouchEnabled;
public int width, height;
public double scale;
public IntPtr RenderingAPI; // GLFMRenderingAPI
public bool mouseDown;
// ...
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Display
{
public PlatformData* platformdata;
// ...
}
const string glfw_wasm = "glfm_platform_emscripten";
[DllImport(glfw_wasm)]
private static extern void glfmGetDisplaySize(Display *display, int *width, int *height);
public static void GetDisplaySize(Display *display, int *width, int *height)
{
if (glfmGetDisplaySize != null)
glfmGetDisplaySize(display, width, height);
}
public static void GetDisplaySize(Display *display, out int width, out int height)
{
fixed (int* width_ptt = &width)
{
fixed (int* height_ptr = &height)
{
GetDisplaySize(display, width_ptt, height_ptr);
}
}
}
// ...
}
iinside Program's class static int Main(string[] args)
Console.WriteLine("Hello GLFW ( GLFM WASM )");
GLFW.Display* glfw_display = (GLFW.Display*)Marshal.SizeOf<GLFW.Display>();
GLFW.PlatformData* glfw_platformdata = (GLFW.PlatformData*)Marshal.SizeOf<GLFW.PlatformData>();
glfw_display->platformdata = glfw_platformdata;
GLFW.GetDisplaySize(glfw_display, out int glfw_width, out int glfw_height);
glfw_width = glfw_platformdata->width;
glfw_height = glfw_platformdata->height;
Console.WriteLine("GLFW Display WIDTH: " + glfw_width);
Console.WriteLine("GLFW Display HEIGHT: " + glfw_height);
I recommend you example with "Dotnet-webgl-example
You can download DotNet-WebGL-Example and add in void Frame() add gl functions but It is really required with shaders ( Do not write without shader because OpenGLES and OpenGL are different.
OpenGL can write without shader and triangle, quad etc are white
OpenGLES can't see white shapes because they disappear / hide cause they require for shader.
Enjoy your C# programming with glfm
But i don't understand why does it happen with width and height measures in WASM....
and WebGL 1.0 (via Emscripten).
OpenGL ES 2.0, 3.0, 3.1, and 3.2 display setup.
#elif defined(GLFM_PLATFORM_EMSCRIPTEN)
#include <GLES3/gl3.h>
#include <GLES3/gl2ext.h>
#else
Does it mean that ES 3.0 can be used in WebGL 1.0?
WebGL 1.0 based on ES 2.0, so it confused me a bit
The enum name GLFMDepthFormat24 is a little confusing since GLFMDepthFormat24 resolves to MTLPixelFormatDepth32Float.
It lead me to believe that 32-bit depth wasn't supported.
Is it possible to have a less confusing name?
Why only "mobile"? Maybe add also Linux support?
Hey, I was curious if GLFM plans to support features like context menus or edit menus. Obviously these can be hand-made by the developer using custom UI, but wont have the native look or feel especially across devices.
Context menu:
https://developer.apple.com/documentation/uikit/uicontrol/adding_context_menus_in_your_app
These kinds of menus would be great for creating tools/applications using GLFM instead for just creating games!
I'm looking for a multi-platform abstraction layer for Vulkan.
Hello! I would like to request support for UIImpactFeedbackGenerator. This is useful because as a software-user it is often gratifying to have some physical feedback when pressing a button. or completing a task.
This can be done on ios using:
https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator
Would this be possible to integrate with GLFM API?
After seeing the "out of scope" section of the readme, I am unsure if this falls in to that category or not. I believe this should be supported though, as all of those categories (images/text/audio/ui/maps/etc) are generally supported by an entire library themselves. Whereas this would be a relatively small/simple addition to GLFM
I have a couple of questions on building and using GLFM on android thought of making it into one issue since I couldn't find one single tutorial on how to use this.
What is happening in the CMakeLists.txt file in examples folder? Why there isn't the add_executable() function. ?
Can I include GLFM with add_subdirectory(path/to/glfm) and link it with my project with target_link_libraries(project glfm)?
What about in source build support?
How would I compile it with Gradle?
I am sorry if I missed something in the README file.
Anyway, Thanks in advance!
Hi. Thank you very much for such an awesome library! It saved a lot of my time.
Could you please consider adding something like this to the _glfmSetFullScreen
in the android implementation?
if (SDK_INT >= 28) {
static const int WindowManager_LayoutParams_LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES = 0x00000001;
jobject window = _glfmCallJavaMethod(jni, app->activity->clazz, "getWindow", "()Landroid/view/Window;", Object);
jobject attributes = _glfmCallJavaMethod(jni, window, "getAttributes", "()Landroid/view/WindowManager$LayoutParams;", Object);
jclass clazz = (*jni)->GetObjectClass(jni, attributes);
jfieldID mi = (*jni)->GetFieldID(jni, clazz, "layoutInDisplayCutoutMode", "I");
(*jni)->SetIntField(jni, attributes, mi, WindowManager_LayoutParams_LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES);
(*jni)->DeleteLocalRef(jni, clazz);
(*jni)->DeleteLocalRef(jni, attributes);
(*jni)->DeleteLocalRef(jni, window);
}
I use this piece of code in my copy of the library to deal with notched devices, works fine.
Also this helps to deal with insets (glfmGetDisplayChromeInsets
):
if (SDK_INT >= 28) {
JNIEnv *jni = platformData->jniEnv;
jobject decorView = _glfmGetDecorView(platformData->app);
jobject insets = _glfmCallJavaMethod(jni, decorView, "getRootWindowInsets", "()Landroid/view/WindowInsets;", Object);
jobject cutouts = _glfmCallJavaMethod(jni, insets, "getDisplayCutout", "()Landroid/view/DisplayCutout;", Object);
*top = _glfmCallJavaMethod(jni, cutouts, "getSafeInsetTop", "()I", Int);
*right = _glfmCallJavaMethod(jni, cutouts, "getSafeInsetRight", "()I", Int);
*bottom = _glfmCallJavaMethod(jni, cutouts, "getSafeInsetBottom", "()I", Int);
*left = _glfmCallJavaMethod(jni, cutouts, "getSafeInsetLeft", "()I", Int);
}
For more info please see
https://developer.android.com/guide/topics/display-cutout
https://developer.android.com/reference/android/view/WindowManager.LayoutParams#LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
*Edit: added second piece of code for insets
Sensor input is implemented on iOS and Android, but not for Web.
Sensors: accelerometer, magnetometer, gyroscope, rotation matrix
To implement in glfm_platform_emscripten.c
:
glfmIsSensorAvailable
_glfmSensorFuncUpdated
(enable/disable sensors as needed)Sensor output must match the iOS/Android versions.
windows:
glfwCreateWindow(1024, 768, "app", NULL, NULL);
vs
android:
ANativeWindow_setBuffersGeometry(engine->app->window,1024,768, format);//line 468
why my layout(1024x768) is problem in android?
When building for ios simulator using cmake and ios-cmake-toolchain found at https://github.com/leetal/ios-cmake, this line triggers
Line 18 in d04ac86
but when commented, everything goes fine.
Not sure, but is it necessary that iphoneos is specified explicitely as cmake computes it?
Hi, it would be nice to have the public interface to get the default frame buffer id like uint32_t glfmDefaultFrameBuffer() in most cases it will return 0 but for the iOS/tvOS case it must return _defaultFramebuffer from the implementation. The motivation of this is simple, in case of if you are using framebuffers inside mainLoopFunc it would be hard to restore the default framebuffer without any glGet*.
Is there a way to make glfm exit the app and return to the OS?
Searched in the code and the docs, couldn't find anything, I'm hoping I'm overlooking something! :)
Hi, I'm sure it's trivial (I'm new to C/C++) but when I follow the instructions on the README I get fatal error: 'glfm.h' file not found
:
If I manually copy theglfm.h
into the source directory the example builds but I get WARNING:root:emcc: cannot find library "glfm"
and the emscripten example loads in browser but just shows black square for content.
Is it possible to use this directly on an Android with AIDE app to build ?
can you add a xcode project for ios example? i'm new in xcode :)
I was having an issue with getting keyboard input on mobile using emscripten. I have a canvas that covers the entire viewport. While I'm rendering to the canvas using OpenGL ES the canvas no longer responds to JS event listeners, so I had no way of getting the user keyboard up using HTML5 APIs since it requires a user gesture for activation. Does this library fix this issue? When running my code using this library in the browser, can I activate the soft keyboard programmatically?
On iOS, when using the sample code with XCode 9.3 and the iOS 11 SDK, the application crashes when changing the orientation of the device.
1>glfm_platform_android.c(113,16): error : declaration of anonymous class must be a definition
1> jclass class = (*jni)->GetObjectClass(jni, object);
1> ^
1>glfm_platform_android.c(113,9): warning : declaration does not declare anything [-Wmissing-declarations]
1> jclass class = (*jni)->GetObjectClass(jni, object);
1> ^~~~~~
1>glfm_platform_android.c(114,36): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> jmethodID methodID = (*jni)->GetMethodID(jni, class, name, sig);
1> ~~~~~~^~
1> .
1>glfm_platform_android.c(114,55): error : expected expression
1> jmethodID methodID = (*jni)->GetMethodID(jni, class, name, sig);
1> ^
1>glfm_platform_android.c(115,15): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> (*jni)->DeleteLocalRef(jni, class);
1> ~~~~~~^~
1> .
1>glfm_platform_android.c(115,37): error : expected expression
1> (*jni)->DeleteLocalRef(jni, class);
1> ^
1>glfm_platform_android.c(116,16): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> return _glfmWasJavaExceptionThrown() ? NULL : methodID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,12): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~^
1>glfm_platform_android.c(116,16): error : too many arguments to function call, expected 0, have 1
1> return _glfmWasJavaExceptionThrown() ? NULL : methodID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,29): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~~~~~~~~~~~~~~~~~ ^~~
1>C:\Microsoft\AndroidNDK64\android-ndk-r15c\platforms\android-19\arch-x86\usr\include\jni.h(1047,5): note: 'ExceptionCheck' declared here
1> jboolean ExceptionCheck()
1> ^
1>glfm_platform_android.c(116,16): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> return _glfmWasJavaExceptionThrown() ? NULL : methodID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,43): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~^
1>glfm_platform_android.c(116,16): error : too many arguments to function call, expected 0, have 1
1> return _glfmWasJavaExceptionThrown() ? NULL : methodID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,60): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~~~~~~~~~~~~~~~~~ ^~~
1>C:\Microsoft\AndroidNDK64\android-ndk-r15c\platforms\android-19\arch-x86\usr\include\jni.h(551,5): note: 'ExceptionClear' declared here
1> void ExceptionClear()
1> ^
1>glfm_platform_android.c(124,16): error : declaration of anonymous class must be a definition
1> jclass class = (*jni)->GetObjectClass(jni, object);
1> ^
1>glfm_platform_android.c(124,9): warning : declaration does not declare anything [-Wmissing-declarations]
1> jclass class = (*jni)->GetObjectClass(jni, object);
1> ^~~~~~
1>glfm_platform_android.c(125,34): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> jfieldID fieldID = (*jni)->GetFieldID(jni, class, name, sig);
1> ~~~~~~^~
1> .
1>glfm_platform_android.c(125,52): error : expected expression
1> jfieldID fieldID = (*jni)->GetFieldID(jni, class, name, sig);
1> ^
1>glfm_platform_android.c(126,15): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> (*jni)->DeleteLocalRef(jni, class);
1> ~~~~~~^~
1> .
1>glfm_platform_android.c(126,37): error : expected expression
1> (*jni)->DeleteLocalRef(jni, class);
1> ^
1>glfm_platform_android.c(127,16): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> return _glfmWasJavaExceptionThrown() ? NULL : fieldID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,12): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~^
1>glfm_platform_android.c(127,16): error : too many arguments to function call, expected 0, have 1
1> return _glfmWasJavaExceptionThrown() ? NULL : fieldID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,29): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~~~~~~~~~~~~~~~~~ ^~~
1>C:\Microsoft\AndroidNDK64\android-ndk-r15c\platforms\android-19\arch-x86\usr\include\jni.h(1047,5): note: 'ExceptionCheck' declared here
1> jboolean ExceptionCheck()
1> ^
1>glfm_platform_android.c(127,16): error : member reference type 'JNIEnv' (aka '_JNIEnv') is not a pointer; did you mean to use '.'?
1> return _glfmWasJavaExceptionThrown() ? NULL : fieldID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,43): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~^
1>glfm_platform_android.c(127,16): error : too many arguments to function call, expected 0, have 1
1> return _glfmWasJavaExceptionThrown() ? NULL : fieldID;
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>glfm_platform_android.c(103,60): note: expanded from macro '_glfmWasJavaExceptionThrown'
1> ((*jni)->ExceptionCheck(jni) ? ((*jni)->ExceptionClear(jni), true) : false)
1> ~~~~~~~~~~~~~~~~~~~~~~ ^~~
1>C:\Microsoft\AndroidNDK64\android-ndk-r15c\platforms\android-19\arch-x86\usr\include\jni.h(551,5): note: 'ExceptionClear' declared here
1> void ExceptionClear()
1> ^
1>glfm_platform_android.c(133,63): error : declaration of anonymous class must be a definition
1>static jfieldID _glfmGetJavaStaticFieldID(JNIEnv *jni, jclass class, const char *name,
Need more detailed steps
Currently chrome insets (glfmGetDisplayChromeInsets
) work on startup, but fail when the device is rotated.
This should improve key events. Also, look into GCMouse
https://developer.apple.com/documentation/gamecontroller?language=objc
If you get errors such as this:
The C compiler identification is unknown
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
And you have xcode installed, you need to switch to non-command line xcode:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
It would be nice of CMake script would tell you that.
we can do 1024x768 screen resolation ? how?
Why don't you create a desktop platform (say, based on SDL or GLFW) to make it easier for development?
If you're interested in this, I may try adding it too. Just say if you care whether SDL or GLFW (or something else) should be used as the underlying platform independent layer.
I'm interested primarily in supporting OpengL ES 2.0 unit tests (GTest, etc) from CMake without the need for Java wrappers. This would entail building NDK native apps and running in /data/local/tmp/
https://github.com/brackeen/glfm/blob/master/src/glfm_platform_android.c
i'm trying to make it work with visual studio 2019 native activity
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.