Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet 6.0 ( wasm tool ) glfm on Webassembly #44

Open
DeafMan1983 opened this issue May 26, 2022 · 0 comments
Open

Dotnet 6.0 ( wasm tool ) glfm on Webassembly #44

DeafMan1983 opened this issue May 26, 2022 · 0 comments

Comments

@DeafMan1983
Copy link

DeafMan1983 commented May 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant