GithubHelp home page GithubHelp logo

brackeen / glfm Goto Github PK

View Code? Open in Web Editor NEW
541.0 43.0 70.0 1 MB

OpenGL ES and input for iOS, tvOS, Android, and WebGL

License: zlib License

C 58.09% Objective-C 37.09% CMake 2.77% Shell 2.05%
opengles emscripten android ios tvos c

glfm's Introduction

GLFM

Build Build Examples

GLFM is a C API for mobile app development with OpenGL ES. It is largely inspired by GLFW.

GLFM runs on iOS 9, tvOS 9, Android 4.1 (API 16), and WebGL 1.0 (via Emscripten).

Additionally, GLFM provides Metal support on iOS and tvOS.

Features

  • OpenGL ES 2, OpenGL ES 3, and Metal display setup.
  • Retina / high-DPI support.
  • Touch and keyboard events.
  • Accelerometer, magnetometer, gyroscope, and device rotation (iOS/Android only)
  • Events for application state and context loss.

Feature Matrix

iOS tvOS Android Web
OpenGL ES 2, OpenGL ES 3 ✔️ ✔️ ✔️ ✔️
Metal ✔️ ✔️ N/A N/A
Retina / high-DPI ✔️ ✔️ ✔️ ✔️
Device orientation ✔️ N/A ✔️
Touch events ✔️ ✔️ ✔️ ✔️
Mouse hover events ✔️1 ✔️
Mouse wheel events ✔️
Mouse cursor style ✔️1 ✔️
Key code events ✔️2 ✔️ ✔️ ✔️
Key repeat events ✔️ ✔️
Character input events ✔️ ✔️3 ✔️ ✔️
Virtual keyboard ✔️ ✔️
Virtual keyboard visibility events ✔️ ✔️
Accelerometer, magnetometer, gyroscope, device rotation ✔️ N/A ✔️
Haptic feedback ✔️4 N/A ✔️
Clipboard ✔️ N/A ✔️ ✔️
Chrome insets ("safe area") ✔️5 ✔️ ✔️
Chrome insets changed events ✔️5 ✔️ ✔️
Focus events ✔️ ✔️ ✔️ ✔️
Resize events ✔️ ✔️ ✔️ ✔️
Memory warning events ✔️ ✔️ ✔️
OpenGL context loss events (surface destroyed) ✔️ ✔️ ✔️ ✔️

1. iPad only. Requires iOS 13.4 or newer
2. Requires iOS/tvOS 13.4 or newer
3. Requires tvOS 13.4 or newer
4. Requires iOS 13 or newer
5. Requires iOS/tvOS 11 or newer

Additionally, there is prelimnary support for macOS with OpenGL 3.2. The macOS version is useful for development purposes, but is not release quality. There is no function to set the window size, for example.

Non-goals

GLFM is limited in scope, and isn't designed to provide everything needed for an app. For example, GLFM doesn't provide (and will never provide) the following:

  • No image loading.
  • No text rendering.
  • No audio.
  • No menus, UI toolkit, or scene graph.
  • No integration with other mobile features like web views, maps, or game scores.

Instead, GLFM can be used with other cross-platform libraries that provide what an app needs.

Use GLFM

A CMakeLists.txt file is provided for convenience, although CMake is not required.

Without CMake:

  1. Add the GLFM source files (in include and src) to your project.
  2. Include a void glfmMain(GLFMDisplay *display) function in a C/C++ file.

For release builds, define NDEBUG to remove superfluous logging statements. NDEBUG is automatically defined for release builds in Android Studio, but not in Xcode.

Example

This example initializes the display in glfmMain() and draws a triangle in onDraw(). A more detailed example is available here.

#include "glfm.h"

static GLint program = 0;
static GLuint vertexBuffer = 0;
static GLuint vertexArray = 0;

static void onDraw(GLFMDisplay *display);
static void onSurfaceDestroyed(GLFMDisplay *display);

void glfmMain(GLFMDisplay *display) {
    glfmSetDisplayConfig(display,
                         GLFMRenderingAPIOpenGLES2,
                         GLFMColorFormatRGBA8888,
                         GLFMDepthFormatNone,
                         GLFMStencilFormatNone,
                         GLFMMultisampleNone);
    glfmSetRenderFunc(display, onDraw);
    glfmSetSurfaceDestroyedFunc(display, onSurfaceDestroyed);
}

static void onSurfaceDestroyed(GLFMDisplay *display) {
    // When the surface is destroyed, all existing GL resources are no longer valid.
    program = 0;
    vertexBuffer = 0;
    vertexArray = 0;
}

static GLuint compileShader(const GLenum type, const GLchar *shaderString, GLint shaderLength) {
    GLuint shader = glCreateShader(type);
    glShaderSource(shader, 1, &shaderString, &shaderLength);
    glCompileShader(shader);
    return shader;
}

static void onDraw(GLFMDisplay *display) {
    if (program == 0) {
        const GLchar vertexShader[] =
            "#version 100\n"
            "attribute highp vec4 position;\n"
            "void main() {\n"
            "   gl_Position = position;\n"
            "}";

        const GLchar fragmentShader[] =
            "#version 100\n"
            "void main() {\n"
            "  gl_FragColor = vec4(0.85, 0.80, 0.75, 1.0);\n"
            "}";

        program = glCreateProgram();
        GLuint vertShader = compileShader(GL_VERTEX_SHADER, vertexShader, sizeof(vertexShader) - 1);
        GLuint fragShader = compileShader(GL_FRAGMENT_SHADER, fragmentShader, sizeof(fragmentShader) - 1);

        glAttachShader(program, vertShader);
        glAttachShader(program, fragShader);

        glLinkProgram(program);

        glDeleteShader(vertShader);
        glDeleteShader(fragShader);
    }
    if (vertexBuffer == 0) {
        const GLfloat vertices[] = {
             0.0,  0.5, 0.0,
            -0.5, -0.5, 0.0,
             0.5, -0.5, 0.0,
        };
        glGenBuffers(1, &vertexBuffer);
        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
    }

    int width, height;
    glfmGetDisplaySize(display, &width, &height);
    glViewport(0, 0, width, height);
    glClearColor(0.08f, 0.07f, 0.07f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

#if defined(GL_VERSION_3_0) && GL_VERSION_3_0
    if (vertexArray == 0) {
        glGenVertexArrays(1, &vertexArray);
    }
    glBindVertexArray(vertexArray);
#endif

    glUseProgram(program);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, 3);

    glfmSwapBuffers(display);
}

API

See glfm.h

Build the GLFM examples with Xcode

Use cmake to generate an Xcode project:

cmake -D GLFM_BUILD_EXAMPLES=ON -B build/apple -G Xcode
open build/apple/GLFM.xcodeproj

In Xcode, switch to the glfm_touch target and run on a simulator or a device.

Build the GLFM examples with Emscripten

Use emcmake to set environmental variables for cmake, then build:

emcmake cmake -D GLFM_BUILD_EXAMPLES=ON -B build/emscripten && cmake --build build/emscripten

Then run locally:

emrun build/emscripten/examples

Or run a specific example:

emrun build/emscripten/examples/glfm_touch.html

Build the GLFM examples with Android Studio

There is no CMake generator for Android Studio projects, but you can include CMakeLists.txt in a new or existing project.

  1. Select "Start a new Android Studio project".
  2. Select "No Activity".
  3. In "Save location", enter [path/to/glfm]/build/android and press "Finish".
  4. In AndroidManifest.xml, add the main <activity> like so:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true">

        <!-- Add this activity to your AndroidManifest.xml -->
        <activity android:name="android.app.NativeActivity"
                  android:exported="true"
                  android:configChanges="orientation|screenLayout|screenSize|keyboardHidden|keyboard">
            <meta-data
                android:name="android.app.lib_name"
                android:value="glfm_touch" />  <!-- glfm_triangle, glfm_touch, glfm_heightmap, glfm_typing, glfm_compass, or glfm_test_pattern -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>
  1. In app/build.gradle, add the externalNativeBuild and sourceSets.main sections like so:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 32
    buildToolsVersion "32.0.0"
    defaultConfig {
        applicationId "com.brackeen.glfmexample"
        minSdkVersion 15
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        // Add externalNativeBuild in defaultConfig (1/2)
        externalNativeBuild {
            cmake {
                arguments "-DGLFM_BUILD_EXAMPLES=ON"
            }
        }
    }
    
    // Add sourceSets.main and externalNativeBuild (2/2)
    sourceSets.main {
        assets.srcDirs = ["../../../examples/assets"]
    }
    externalNativeBuild {
        cmake {
            path "../../../CMakeLists.txt"
        }
    }
    namespace 'com.brackeen.glfmexample'
}
  1. Press "Sync Now" and "Run 'app'"

Caveats

  • OpenGL ES 3.1 and 3.2 support is only available in Android.
  • GLFM is not thread-safe. All GLFM functions must be called on the main thread (that is, from glfmMain or from the callback functions).

Questions

What IDE should I use? Why is there no desktop implementation? Use Xcode or Android Studio. For desktop, use GLFW with the IDE of your choice.

If you prefer not using the mobile simulators for everyday development, a good solution is to use GLFW instead, and then later port your app to GLFM. Not all OpenGL calls will port to OpenGL ES perfectly, but for maximum OpenGL portability, use OpenGL 3.2 Core Profile on desktop and OpenGL ES 2.0 on mobile.

Why is the entry point glfmMain() and not main()?

Otherwise, it wouldn't work on iOS. To initialize the Objective-C environment, the main() function must create an autorelease pool and call the UIApplicationMain() function, which never returns. On iOS, GLFM doesn't call glfmMain() until after the UIApplicationDelegate and UIViewController are initialized.

Why is GLFM event-driven? Why does GLFM take over the main loop?

Otherwise, it wouldn't work on iOS (see above) or on HTML5, which is event-driven.

glfm's People

Contributors

brackeen avatar charlesgriffiths avatar cwiiis avatar ivovandongen avatar marcakafoddex avatar timgates42 avatar tmpsantos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glfm's Issues

How to use GLFM in a real android project?

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!

Could you please help in getting your glfm example compile for Android?

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:

  • copied directory gradle from hello-jniCallback (specified my local zip in distributionUrl=... in gradle/wrapper/gradle-wrapper.properties; but it shouldn't matter)
  • copied files: build.gradle, gradle.properties, gradlew (I'm on Linux)
  • copied settings.gradle, edited it to include ':example'
  • copied local.properties, with my local settings ndk.dir=... and sdk.dir=...
  • created example/build.gradle as instructed in readme. Edited ../../../../CMakeLists.txt to ../CMakeLists.txt (and similarly ../example/assets)
  • created example/src/main/ directory and in it - AndroidManifest.xml as instructed in readme.

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.

Default frame buffer object

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*.

Feature request: split up glfm_platform_ios.c

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).

window size

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?

Leave app?

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! :)

Context/Edit Menu 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

Edit Menu:
https://developer.apple.com/library/archive/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/AddingCustomEditMenuItems/AddingCustomEditMenuItems.html

image
image

These kinds of menus would be great for creating tools/applications using GLFM instead for just creating games!

Will OpenGL ES 3.0 work on WebGL?

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

iPhone X support

  • Access to "safe area"
  • Option to enable "edge protection"
  • Option to autohide home indicator

xcode project

can you add a xcode project for ios example? i'm new in xcode :)

Support something like UIImpactFeedbackGenerator (Device Vibrations)

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

Dotnet 6.0 ( wasm tool ) glfm on Webassembly

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.
image

  1. Copy glfm.h, glfm_platform.h and glfm_platform_emscription.c to current working directory while you type `dotnet new blazor -o wasmtest
  2. Write in csproj
<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....

Can't build emscripten example

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:

screen shot 2018-03-05 at 07 25 55

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.

how about MacOS

i learn that can support ios android and web, how about maos and windows?
how about vulkan?

Building for ios simulator

When building for ios simulator using cmake and ios-cmake-toolchain found at https://github.com/leetal/ios-cmake, this line triggers

set(CMAKE_OSX_SYSROOT "iphoneos")

clang: warning: no such sysroot directory: 'iphoneos' [-Wmissing-sysroot]
glfm-src/include/glfm.h:39:12: fatal error: 'TargetConditionals.h' file not found

but when commented, everything goes fine.
Not sure, but is it necessary that iphoneos is specified explicitely as cmake computes it?

Web: Add support for sensors (via Emscripten)

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 callbacks

Sensor output must match the iOS/Android versions.

Readme improvement suggestions

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!

Correct layout for notched android devices

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

Vulkan support?

I'm looking for a multi-platform abstraction layer for Vulkan.

visual studio 2017 errors

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,

Keyboard Input

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?

Background flickers first few moments of the app

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:

video5942563557299194754.mp4

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:

  • i'm on the latest version of glfm
  • i'm clearing my buffers every time I render (both GL_COLOR_BUFFER_BIT and GL_DEPTH_BUFFER_BIT)
  • i set the clear color & depth using glClearColor and glClearDepthf
  • my viewport, blending etc. settings are correct

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

Add a desktop platform

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.

Error `The C compiler identification is unknown`.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.