Dotnet 6.0 ( wasm tool ) glfm on Webassembly
DeafMan1983 opened this issue · 0 comments
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.
- Copy glfm.h, glfm_platform.h and glfm_platform_emscription.c to current working directory while you type `dotnet new blazor -o wasmtest
- 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....