- Home /
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.:
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