Forum Discussion
brendenfrank
12 years agoHonored Guest
Has anyone had success with OVRGUI.StereoDrawTexture()?
I'm calling this within a OnGUI loop, however it seems to only draw my left side instead of drawing in stereo as the name would imply. I modified the class with a singleton reference, but that shouldn't matter from what I can see.
My Implementation:
Looking at the StereoDrawTexture I only see a single drawtexture call:
This leads me to think I have to call this method twice and position each eye, which could be done without using this method all together.
My Implementation:
private void OnGUI()
{
OVRGUI.instance.StereoDrawTexture(0, 0, Screen.width/2, Screen.height, ref reading, Color.white);
}
Looking at the StereoDrawTexture I only see a single drawtexture call:
public void StereoDrawTexture(int X, int Y, int wX, int hY, ref Texture image, Color color)
{
GUI.color = color;
// Make sure to change font if it needs replacement
if(GUI.skin.font != FontReplace) GUI.skin.font = FontReplace;
float s = PixelWidth / DisplayWidth;
CalcPositionAndSize(X * s, Y * s, wX * s, hY * s, ref DrawRect);
GUI.DrawTexture(DrawRect, image);
}
This leads me to think I have to call this method twice and position each eye, which could be done without using this method all together.
8 Replies
Replies have been turned off for this discussion
- petergiokarisProtegeYou will need to set a render texture to draw into before calling OVRGUI functions, and then map this onto geometry that will be rendered in stereo within the scene. If you don't, then the text or image will render into the currently active render target.
Please reference OVRMainMenu.cs to see how it is being used to render the HUD. - brendenfrankHonored GuestThanks Peter, I'll do as you suggested.
- CaliberMengskExplorerActually, you don't need to set a render texture. I found a way that works great without the render texture. You just need to draw everything twice and offset it by the left and right eye configuration using OVRDevice.LeftEyeOffset and OVRDevice.RightEyeOffset
This (I believe anyway) uses the oculus rift profile information, so it should update per user.
I actually made this overly complex window script a while ago. Allows for exact positioning, or centering on screen. Most of the calculations could be set to just the start loop and stored in variables, but I was testing with stuff, so it's not so pretty and optimized, but it does get a gui that works with stereo, without using render texture.
using UnityEngine;
using System.Collections;
[ExecuteInEditMode] //Comment this out when you are done finding all the settings you want.
public class OVRGUIWindow : MonoBehaviour {
public bool centerWindow = true;
public Rect windowSize = new Rect(0,0,100,100);
public string title = "";
public string content = "";
public GUIStyle titleStyle = new GUIStyle();
public GUIStyle contentStyle = new GUIStyle();
void OnGUI()
{
GUI.color = Color.white;
Rect tmpRect = windowSize;
if(centerWindow)
{
tmpRect.x = (Screen.width/4)-(windowSize.width/2) + windowSize.x;
tmpRect.y = (Screen.height/2)-(windowSize.height/2) + windowSize.y;
tmpRect.x += (OVRDevice.LeftEyeOffset*Screen.width);
}
GUI.Box (tmpRect,"");
Vector2 titleSize = titleStyle.CalcSize(new GUIContent(title));
tmpRect.x += (tmpRect.width/2)-(titleSize.x/2);
GUI.Label(tmpRect, title,titleStyle);
GUI.color = new Color(.75f,.75f,.75f,1f);
tmpRect = windowSize;
if(centerWindow)
{
tmpRect.x = (Screen.width/4)-(windowSize.width/2) + windowSize.x;
tmpRect.y = (Screen.height/2)-(windowSize.height/2) + windowSize.y;
tmpRect.x += (OVRDevice.LeftEyeOffset*Screen.width);
}
tmpRect.y += titleSize.y*1.2f;
tmpRect.x += 10;
tmpRect.width -= 20;
tmpRect.height -= titleSize.y *2f;
GUI.Label(tmpRect,content, contentStyle);
GUI.color = Color.white;
tmpRect = windowSize;
if(centerWindow)
{
tmpRect.x = (Screen.width/4)-(windowSize.width/2) + windowSize.x;
tmpRect.y = (Screen.height/2)-(windowSize.height/2) + windowSize.y;
tmpRect.x += Screen.width/2;
tmpRect.x -= (OVRDevice.RightEyeOffset*Screen.width);
}
GUI.Box (tmpRect,"");
tmpRect.x += (tmpRect.width/2)-(titleSize.x/2);
GUI.Label(tmpRect, title,titleStyle);
GUI.color = new Color(.75f,.75f,.75f,1f);
tmpRect = windowSize;
if(centerWindow)
{
tmpRect.x = (Screen.width/4)-(windowSize.width/2) + windowSize.x;
tmpRect.y = (Screen.height/2)-(windowSize.height/2) + windowSize.y;
tmpRect.x += Screen.width/2;
tmpRect.x -= (OVRDevice.RightEyeOffset*Screen.width);
}
tmpRect.y += titleSize.y*1.2f;
tmpRect.x += 10;
tmpRect.width -= 20;
tmpRect.height -= titleSize.y *2f;
GUI.Label(tmpRect,content, contentStyle);
}
}
Now, as to which is better?..... I would say that the Render texture may be better since it only does 1 draw call per gui element. This is a different way to do it though, and if there is ever a way for the rift to work with unity free, then this kind of method would be needed as render texture is not in unity free. - brendenfrankHonored GuestThanks!
This would especially help for something like loading screens. It's the only time I think I need to glue a static object to the player's face. - turnpikemikeHonored Guest
"petergiokaris" wrote:
You will need to set a render texture to draw into before calling OVRGUI functions, and then map this onto geometry that will be rendered in stereo within the scene. If you don't, then the text or image will render into the currently active render target.
Please reference OVRMainMenu.cs to see how it is being used to render the HUD.
This is the method i would like to use, but i cannot find a tutorial or a guide that can accurately tell me step by step how to do this, i've looked at the OVRMainMenu.cs and i can understand some of it, but since i am not that great at programming, i am having trouble working through this. if anyone could make a step by step guide for making a render texture and applying it to a quad and having it stay infront of the camera as well as getting a simple text to appear on it, that would be the single best thing in the world.
-thank you - boone188Honored Guest
"turnpikemike" wrote:
"petergiokaris" wrote:
You will need to set a render texture to draw into before calling OVRGUI functions, and then map this onto geometry that will be rendered in stereo within the scene. If you don't, then the text or image will render into the currently active render target.
Please reference OVRMainMenu.cs to see how it is being used to render the HUD.
This is the method i would like to use, but i cannot find a tutorial or a guide that can accurately tell me step by step how to do this, i've looked at the OVRMainMenu.cs and i can understand some of it, but since i am not that great at programming, i am having trouble working through this. if anyone could make a step by step guide for making a render texture and applying it to a quad and having it stay infront of the camera as well as getting a simple text to appear on it, that would be the single best thing in the world.
-thank you
You can check out the GUI package I created. It will handle the rendering to texture for you, and you just need to do the OnGUI (actually, the OnVRGUI). https://developer.oculusvr.com/forums/viewtopic.php?f=37&t=4944 - turnpikemikeHonored GuestTHANK YOU!!! been looking all over for something like that. you are a life saver!
- boone188Honored Guest
"turnpikemike" wrote:
THANK YOU!!! been looking all over for something like that. you are a life saver!
Very welcome :)
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 6 months ago