static void Main() { Window.CreateWindow("OpenGL UI: Example 4", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create a container that will store all of our color picker content OpenGL.UI.UIContainer colorPickerContainer = new OpenGL.UI.UIContainer(); colorPickerContainer.Size = new Point(240, 190); colorPickerContainer.Position = new Point(20, 20); colorPickerContainer.RelativeTo = OpenGL.UI.Corner.TopLeft; // create a menu bar that will have two different textures menuTexture = new Texture("data/menu.png"); menuSelectedTexture = new Texture("data/menuSelected.png"); OpenGL.UI.Button menu = new OpenGL.UI.Button(menuTexture); colorPickerContainer.AddElement(menu); // place some text within the menu bar OpenGL.UI.Text menuText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._12pt, "Color Picker"); menuText.RelativeTo = OpenGL.UI.Corner.TopLeft; menuText.Position = new Point(4, 17); colorPickerContainer.AddElement(menuText); // add some events that will move the entire color picker container with the menu bar bool moving = false; menu.OnMouseDown = (sender, e) => { moving = true; menu.BackgroundTexture = menuSelectedTexture; // make it look nice by swapping the menubar texture }; menu.OnMouseUp = (sender, e) => { moving = false; menu.BackgroundTexture = menuTexture; // make sure to restore the menubar texture }; menu.OnMouseMove = (sender, e) => { if (moving) { int x = colorPickerContainer.Position.X + OpenGL.UI.UserInterface.MousePosition.X - OpenGL.UI.UserInterface.LastMousePosition.X; int y = colorPickerContainer.Position.Y + OpenGL.UI.UserInterface.MousePosition.Y - OpenGL.UI.UserInterface.LastMousePosition.Y; colorPickerContainer.Position = new Point(x, y); colorPickerContainer.OnResize(); } }; // create the color picker itself OpenGL.UI.ColorGradient gradient = new OpenGL.UI.ColorGradient(); gradient.Position = new Point(30, 30); // and create a hue slider that can control the types of colors shown in the color picker OpenGL.UI.HueGradient hue = new OpenGL.UI.HueGradient(); hue.Position = new Point(190, 30); // add the color picker and its hue slider to the UI colorPickerContainer.AddElement(gradient); colorPickerContainer.AddElement(hue); // add the entire container to the user interface OpenGL.UI.UserInterface.AddElement(colorPickerContainer); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (true) { Window.HandleEvents(); OnRenderFrame(); } }
static void Main() { // create an OpenGL window Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL UI: Example 2"); // provide the Glut callbacks that are necessary for running this tutorial Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(() => { }); // only here for mac os x Glut.glutCloseFunc(OnClose); Glut.glutMouseFunc(OnMouseClick); Glut.glutMotionFunc(OnMouseMove); Glut.glutPassiveMotionFunc(OnMouseMove); Glut.glutReshapeFunc(OnResize); Glut.glutKeyboardFunc(OnKeyboard); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(width, height); // create some centered text OpenGL.UI.Text selectText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Select A Character", OpenGL.UI.BMFont.Justification.Center); selectText.Position = new Point(0, 50); selectText.RelativeTo = OpenGL.UI.Corner.Center; OpenGL.UI.Text characterName = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "", OpenGL.UI.BMFont.Justification.Center); characterName.RelativeTo = OpenGL.UI.Corner.Center; characterName.Position = new Point(0, -70); // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(selectText); OpenGL.UI.UserInterface.AddElement(characterName); // the license for these icons is located in the data folder string[] characters = new string[] { "boy.png", "man.png", "girl1.png", "girl2.png", "girl3.png" }; textures = new Texture[characters.Length]; int xoffset = -characters.Length * 80 / 2 + 40; for (int i = 0; i < characters.Length; i++) { string character = characters[i]; // load a texture that will be used by a button textures[i] = new Texture(string.Format("data/{0}", character)); // create buttons in a row, each of which uses a Texture (the Texture gives the initial size of the Button in pixels) OpenGL.UI.Button button = new OpenGL.UI.Button(textures[i]); button.Position = new Point(xoffset, 5); button.RelativeTo = OpenGL.UI.Corner.Center; // change the color of the button when entering/leaving/clicking with the mouse button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0, 1f, 0.2f, 1.0f); button.OnMouseLeave = (sender, e) => button.BackgroundColor = Vector4.Zero; button.OnMouseDown = (sender, e) => button.BackgroundColor = new Vector4(0, 0.6f, 1f, 1f); button.OnMouseUp = (sender, e) => button.BackgroundColor = (OpenGL.UI.UserInterface.Selection == button ? new Vector4(0, 1f, 0.2f, 1.0f) : Vector4.Zero); // update the text with the character name when the button is clicked button.OnMouseClick = (sender, e) => characterName.String = string.Format("You selected {0}!", character); OpenGL.UI.UserInterface.AddElement(button); xoffset += 80; } // enter the glut main loop (this is where the drawing happens) Glut.glutMainLoop(); }
static void Main() { Window.CreateWindow("OpenGL UI: Example 10", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create the left and right containers leftContainer = new OpenGL.UI.UIContainer(new Point(Window.Width / 2, Window.Height), "LeftContainer"); rightContainer = new OpenGL.UI.UIContainer(new Point(Window.Width / 2, Window.Height), "RightContainer"); leftContainer.RelativeTo = OpenGL.UI.Corner.BottomLeft; rightContainer.RelativeTo = OpenGL.UI.Corner.BottomRight; // add the containers to the user interface OpenGL.UI.UserInterface.AddElement(leftContainer); OpenGL.UI.UserInterface.AddElement(rightContainer); // add some cool stuff to the containers scrollTexture = new Texture("data/scrollTexture.png"); // create a textbox with word wrapping for the left container OpenGL.UI.TextBox textBox = new OpenGL.UI.TextBox(OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt"), scrollTexture); textBox.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget vehicula orci. Nulla nibh nulla, suscipit non neque sed, placerat efficitur velit. Sed convallis gravida tincidunt. Praesent vehicula nibh leo, at consequat nisi condimentum ullamcorper. Vivamus pulvinar accumsan maximus. Integer luctus elit porttitor nisi sollicitudin, eget porttitor odio tincidunt. Sed elit justo, suscipit non dui ut, eleifend euismod nibh. Nullam ac fermentum nisl. In convallis id leo sit amet eleifend. Suspendisse eu ligula pulvinar ex facilisis cursus ac ac velit. In ut turpis nec neque vehicula eleifend. Morbi in tempus est. Vivamus nisi nunc, pharetra quis scelerisque ut, tempor id dui."); textBox.RelativeTo = OpenGL.UI.Corner.Fill; textBox.Padding = new Point(6, 0); leftContainer.AddElement(textBox); textBox.OnResize(); // build 10 buttons for the right container for (int i = 0; i < 10; i++) { OpenGL.UI.Button button = new OpenGL.UI.Button(200, 30); button.Font = OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt"); button.Text = string.Format("Button {0}", i); button.RelativeTo = OpenGL.UI.Corner.Center; button.Position = new Point(0, 200 - i * 40); rightContainer.AddElement(button); button.OnResize(); button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0.5f, 0.5f, 1.0f, 1.0f); button.OnMouseLeave = (sender, e) => button.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); } // add a control to resize the left/right containers divider = new OpenGL.UI.Button(8, Window.Height); divider.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 0.5f); divider.RelativeTo = OpenGL.UI.Corner.BottomLeft; divider.Position = new Point(Window.Width / 2 - divider.Size.X / 2, 0); bool onMouseDown = false; // handle mouse events on the divider divider.OnMouseDown = (sender, e) => onMouseDown = true; divider.OnMouseUp = (sender, e) => onMouseDown = false; divider.OnMouseMove = (sender, e) => { if (onMouseDown) { ResizeControls(e.Location.X - e.LastLocaton.X); } }; // make sure to layout the controls if the window is resized Window.OnReshapeCallbacks.Add(() => ResizeControls(0)); // add the divider to the user interface OpenGL.UI.UserInterface.AddElement(divider); // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (true) { Window.HandleEvents(); OnRenderFrame(); } }
static void Main() { Window.CreateWindow("OpenGL UI: Example 2", 1280, 720); // add a reshape callback to update the UI Window.OnReshapeCallbacks.Add(() => OpenGL.UI.UserInterface.OnResize(Window.Width, Window.Height)); // add a close callback to make sure we dispose of everything properly Window.OnCloseCallbacks.Add(OnClose); // enable depth testing to ensure correct z-ordering of our fragments Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // initialize the user interface OpenGL.UI.UserInterface.InitUI(Window.Width, Window.Height); // create some centered text OpenGL.UI.Text selectText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Select A Character", OpenGL.UI.BMFont.Justification.Center); selectText.Position = new Point(0, 50); selectText.RelativeTo = OpenGL.UI.Corner.Center; OpenGL.UI.Text characterName = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "", OpenGL.UI.BMFont.Justification.Center); characterName.RelativeTo = OpenGL.UI.Corner.Center; characterName.Position = new Point(0, -70); // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(selectText); OpenGL.UI.UserInterface.AddElement(characterName); // the license for these icons is located in the data folder string[] characters = new string[] { "boy.png", "man.png", "girl1.png", "girl2.png", "girl3.png" }; textures = new Texture[characters.Length]; int xoffset = -characters.Length * 80 / 2 + 40; for (int i = 0; i < characters.Length; i++) { string character = characters[i]; // load a texture that will be used by a button textures[i] = new Texture(string.Format("data/{0}", character)); // create buttons in a row, each of which uses a Texture (the Texture gives the initial size of the Button in pixels) OpenGL.UI.Button button = new OpenGL.UI.Button(textures[i]); button.Position = new Point(xoffset, 5); button.RelativeTo = OpenGL.UI.Corner.Center; // change the color of the button when entering/leaving/clicking with the mouse button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0, 1f, 0.2f, 1.0f); button.OnMouseLeave = (sender, e) => button.BackgroundColor = Vector4.Zero; button.OnMouseDown = (sender, e) => button.BackgroundColor = new Vector4(0, 0.6f, 1f, 1f); button.OnMouseUp = (sender, e) => button.BackgroundColor = (OpenGL.UI.UserInterface.Selection == button ? new Vector4(0, 1f, 0.2f, 1.0f) : Vector4.Zero); // update the text with the character name when the button is clicked button.OnMouseClick = (sender, e) => characterName.String = string.Format("You selected {0}!", character); OpenGL.UI.UserInterface.AddElement(button); xoffset += 80; } // subscribe the escape event using the OpenGL.UI class library Input.Subscribe((char)27, Window.OnClose); // make sure to set up mouse event handlers for the window Window.OnMouseCallbacks.Add(OpenGL.UI.UserInterface.OnMouseClick); Window.OnMouseMoveCallbacks.Add(OpenGL.UI.UserInterface.OnMouseMove); while (Window.Open) { Window.HandleEvents(); OnRenderFrame(); } }