static void Main() { Window.CreateWindow("OpenGL UI: Example 3", 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._16pt, "Pick A Color:", OpenGL.UI.BMFont.Justification.Center); selectText.Position = new Point(0, 80); selectText.RelativeTo = OpenGL.UI.Corner.Center; // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(selectText); // create the color picker itself OpenGL.UI.ColorGradient gradient = new OpenGL.UI.ColorGradient(); gradient.RelativeTo = OpenGL.UI.Corner.Center; gradient.Position = new Point(-20, 0); gradient.OnColorChange = (sender, e) => selectText.Color = gradient.Color; // 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.RelativeTo = OpenGL.UI.Corner.Center; hue.Position = new Point(80, 0); // add the color picker and its hue slider to the UI OpenGL.UI.UserInterface.AddElement(gradient); OpenGL.UI.UserInterface.AddElement(hue); // 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 5", 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 slider with a specified texture sliderTexture = new Texture("data/slider.png"); OpenGL.UI.Slider slider = new OpenGL.UI.Slider(sliderTexture); slider.RelativeTo = OpenGL.UI.Corner.Center; slider.BackgroundColor = new Vector4(0.1f, 0.1f, 0.1f, 1f); slider.LockToSteps = true; // create some text that will change with the slider position OpenGL.UI.Text text = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "Value: 0"); text.RelativeTo = OpenGL.UI.Corner.Center; text.Position = new Point(120, -text.TextSize.Y / 2); slider.OnValueChanged = (sender, e) => text.String = string.Format("Value: {0}", slider.Value); // add both the slider and text controls to the UI OpenGL.UI.UserInterface.AddElement(slider); OpenGL.UI.UserInterface.AddElement(text); // 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(); } }
static void Main() { Window.CreateWindow("OpenGL UI: Example 9", 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); OpenGL.UI.Text text = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "Type Something:"); text.RelativeTo = OpenGL.UI.Corner.Center; text.Position = new Point(-260, -10); // create a text input control OpenGL.UI.TextInput textInput = new OpenGL.UI.TextInput(OpenGL.UI.BMFont.LoadFont("fonts/font16.fnt")); textInput.Size = new Point(300, 20); textInput.Position = new Point(50, 0); textInput.RelativeTo = OpenGL.UI.Corner.Center; textInput.BackgroundColor = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); // add the text input control to the user interface OpenGL.UI.UserInterface.AddElement(textInput); OpenGL.UI.UserInterface.AddElement(text); // 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(); } }
static void Main() { Window.CreateWindow("OpenGL UI: Example 1", 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 welcome = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Welcome to OpenGL", OpenGL.UI.BMFont.Justification.Center); welcome.RelativeTo = OpenGL.UI.Corner.Center; // create some colored text OpenGL.UI.Text coloredText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "using C#", OpenGL.UI.BMFont.Justification.Center); coloredText.Position = new Point(0, -30); coloredText.Color = new Vector3(0.2f, 0.3f, 1f); coloredText.RelativeTo = OpenGL.UI.Corner.Center; // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(welcome); OpenGL.UI.UserInterface.AddElement(coloredText); // 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(); } }
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 1"); // 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 welcome = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Welcome to OpenGL", OpenGL.UI.BMFont.Justification.Center); welcome.RelativeTo = OpenGL.UI.Corner.Center; // create some colored text OpenGL.UI.Text coloredText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "using C#", OpenGL.UI.BMFont.Justification.Center); coloredText.Position = new Point(0, -30); coloredText.Color = new Vector3(0.2f, 0.3f, 1f); coloredText.RelativeTo = OpenGL.UI.Corner.Center; // add the two text object to the UI OpenGL.UI.UserInterface.AddElement(welcome); OpenGL.UI.UserInterface.AddElement(coloredText); // enter the glut main loop (this is where the drawing happens) Glut.glutMainLoop(); }
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 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(); } }