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

How to use IVRNotifications? #1133

Open
AndersMalmgren opened this issue Feb 4, 2019 · 6 comments
Open

How to use IVRNotifications? #1133

AndersMalmgren opened this issue Feb 4, 2019 · 6 comments

Comments

@AndersMalmgren
Copy link

I cant seem to get Notifications working, can you guys provide docs please?

I talk about the SteamVR notifications, IVRNotifications, CreateNotification etc

@AndersMalmgren
Copy link
Author

AndersMalmgren commented Feb 4, 2019

I invested some time in this, Just a few days ago this was pushed to the Openvr repo

823135d#diff-a7e4e65799ecc1976f2eca8869a9c7a7

It adds support to the IVRNotifications API. I tried it out and it works.

I suggest a wrapper that takes care of creating the overlay. But more important act as a wrapper for a Unity sprite so we can use a Unity sprite object as image for the overlay.

@AndersMalmgren
Copy link
Author

Also I cant get the icon image to work, tried,

            image.m_nBytesPerPixel = ?;
            image.m_pImageData = MyImage.texture.GetNativeTexturePtr();
            image.m_nWidth = MyImage.texture.width;
            image.m_nHeight = MyImage.texture.height;

Unity crashes hard

@AndersMalmgren
Copy link
Author

Also tried

            var bytes = MyImage.texture.GetRawTextureData();
            IntPtr unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
            Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);

            image.m_nBytesPerPixel = 4;
            image.m_pImageData = unmanagedPointer;
            image.m_nWidth = MyImage.texture.width;
            image.m_nHeight = MyImage.texture.height;

Doesnt crash, but no image in notification

@AndersMalmgren
Copy link
Author

I created a minimal example in Unity without the SteamVR plugin just raw OpenVR,

	    var e = EVRInitError.None;
	    OpenVR.Init(ref e, EVRApplicationType.VRApplication_Overlay);


	    ulong handle = 0;
	    var error = OpenVR.Overlay.CreateOverlay(Guid.NewGuid().ToString(), "My app", ref handle);
	   
	    var image = new NotificationBitmap_t();
	    var bitmap = new Bitmap(File.OpenRead(@"myimage.png"));

	    System.Drawing.Imaging.BitmapData TextureData =
	        bitmap.LockBits(
	            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
	            System.Drawing.Imaging.ImageLockMode.ReadOnly,
	            System.Drawing.Imaging.PixelFormat.Format32bppArgb
	        );

	    var foo = BitConverter.IsLittleEndian;

	    image.m_pImageData = TextureData.Scan0;
	    image.m_nWidth = TextureData.Width;
	    image.m_nHeight = TextureData.Height;
	    image.m_nBytesPerPixel = 4;

	    uint id = 0;
	    OpenVR.Notifications.CreateNotification(handle, 0, Valve.VR.EVRNotificationType.Transient, "foobar", Valve.VR.EVRNotificationStyle.Application, ref image, ref id);

	    //Unlocks Image Data
	    bitmap.UnlockBits(TextureData);

This works in vanilla .net but not in Unity, the images does not show, the notification does show but without image. Image work in vanilla. It seems the pointer data types differ in .net and mono/unity.

In mono:
image

.net
image

@bddckr
Copy link

bddckr commented Feb 5, 2019

Related: #1038

@AndersMalmgren
Copy link
Author

@bddckr Yep, its related to x64 dll

@kisak-valve kisak-valve transferred this issue from ValveSoftware/steamvr_unity_plugin Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants