• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iiJDSii · Feb 28, 2020 at 07:50 AM · vrwindowsvirtualrealitydesktop

How can I convert my desktop viewer to a virtual reality side-by-side display?

have a custom VR headset whose display just takes HDMI. So I'd like to provide the output of my Windows laptop. However I need the proper screen settings to make 'VR mode' work.

Below I have the code for a see-through desktop that is fully clickable, exactly what I want to send to the device - which is essentially just a 6" HDMI screen. However, I need to get the rectilinear buldge transform thing to really make it look proper on the headset (plus adjust the offset of the sides/'eyes'), e.g.:

alt text

How can I go about converting the below code to let me have a proper display for VR goggles like so?

//Note: Inspired by and uses some code found here: http://forum.unity3d.com/threads/windows-api-calls.127719/

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Runtime.InteropServices; // Pro and Free!!!

 public class TransparentWindow : MonoBehaviour
 {
     [DllImport("user32.dll", EntryPoint = "MoveWindow")]
     static extern int MoveWindow(int hwnd, int x, int y, int nWidth, int nHeight, int bRepaint);
     [DllImport("user32.dll", EntryPoint = "SetWindowLongA")]
     static extern int SetWindowLong(int hwnd, int nIndex, long dwNewLong);
     [DllImport("user32.dll")]
     static extern bool ShowWindowAsync(int hWnd, int nCmdShow);
     [DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
     static extern int SetLayeredWindowAttributes(int hwnd, int crKey, byte bAlpha, int dwFlags);
     [DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
     private static extern int GetActiveWindow();
     [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
     private static extern long GetWindowLong(int hwnd, int nIndex);
     [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
     private static extern int GetSystemMetrics(int nIndex);
     [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
     private static extern int SetWindowPos(int hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int uFlags);

 void Start()
 {
     int handle = GetActiveWindow();
     int fWidth = Screen.width ;
     int fHeight = Screen.height;
     MoveWindow(handle, 0, 0, fWidth, fHeight, 1); // move the Unity Project windows >>> 0,0 
     ShowWindowAsync(handle, 3); // full screen !!!    // SW_SHOWMAXIMIZED
     //Remove title bar
     long lCurStyle = GetWindowLong(handle, -16);     // GWL_STYLE=-16
     int a = 12582912;   //WS_CAPTION = 0x00C00000L
     int b = 1048576;    //WS_HSCROLL = 0x00100000L
     int c = 16777216;   //WS_MAXIMIZE = 0x01000000L
     int d = 524288;     //WS_SYSMENU = 0x00080000L
     int e = 2097152;    //WS_VSCROLL = 0x00200000L
     lCurStyle -= a | b | c | d | e;
     SetWindowLong(handle, -16, lCurStyle);//524288); // GWL_EXSTYLE=-20 , WS_EX_LAYERED=524288=&h80000

     lCurStyle = GetWindowLong(handle, -20);
     int j = 1;          //WS_EX_DLGMODALFRAME = 0x00000001L
     int k = 512;        //WS_EX_CLIENTEDGE = 0x00000200L
     int l = 131072;     //WS_EX_STATICEDGE = 0x00020000L

     lCurStyle -= j | k | l;
     // Transparency windows
     SetWindowLong(handle, -20, lCurStyle);//524288); // GWL_EXSTYLE=-20 , WS_EX_LAYERED=524288=&h80000

     //SetLayeredWindowAttributes(handle,0,127, 2); // Transparency=127 >> 50%  ,  LWA_ALPHA=2 
     // Transparency color key !!!
     SetLayeredWindowAttributes(handle, 0, 0, 1); // handle,color key = 0 >> black, % of transparency, LWA_COLORKEY=1

     //SetWindowPos(Handle, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_SHOWWINDOW);
     //SWP_FRAMECHANGED = 0x0020
     //SWP_SHOWWINDOW = 0x0040
     SetWindowPos(handle, 0, 0, 0, GetSystemMetrics(0), GetSystemMetrics(1), 32 | 64); //handle,0,0
 }

}

Thanks in advance for any help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

156 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change HTC Vive compositor progress panel image 1 Answer

Unity crash when using Oculus Rift and SteamVR 0 Answers

Video lags in Unity VR 0 Answers

Unity Native VR doesn't work!! 0 Answers

Unity XR get controller thumb stick axis 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges