LoadAll() public method

Loads all OpenGL entry points.
/// Occurs when this instance is not current on the calling thread. ///
public LoadAll ( ) : void
return void
Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Closing += Form1_Closing;

            WindowInfo = Utilities.CreateWindowsWindowInfo(panel1.Handle);
            var WindowMode = new GraphicsMode(32, 24, 0, 0, 0, 2);
            WindowContext = new GraphicsContext(WindowMode, WindowInfo, 2, 0, GraphicsContextFlags.Debug);

            WindowContext.MakeCurrent(WindowInfo);
            WindowContext.LoadAll(); // as IGraphicsContextInternal)

            WindowContext.SwapInterval = 1;
            GL.Viewport(0, 0, panel1.Width, panel1.Height);

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.ClearColor(Color.DarkBlue);

            try
            {
                state.LoadCLRPackage();
                state.DoString(@" import ('LUA', 'LUA') ");
            }
            catch (LuaException ex)
            {
                MessageBox.Show(ex.Message, "LUA Package Exception", MessageBoxButtons.OK);
            }

            state["x"] = 0.0;
            state["y"] = 1.0;
            state["fn"] = 0;
            script = textBox1.Text;

            timer1.Enabled = true;
        }
Ejemplo n.º 2
0
 public static IGraphicsContext CreateGraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags)
 {
     GraphicsContext graphicsContext = new GraphicsContext(mode, window, major, minor, flags);
       graphicsContext.MakeCurrent(window);
       graphicsContext.LoadAll();
       return (IGraphicsContext) graphicsContext;
 }
Ejemplo n.º 3
0
 private void InitGL()
 {
     windowInfo = Utilities.CreateWindowsWindowInfo(window.Handle);
     context = new GraphicsContext(GraphicsMode.Default, windowInfo);
     context.MakeCurrent(windowInfo);
     context.LoadAll();
 }
Ejemplo n.º 4
0
        public void Run()
        {
            GraphicsMode gmode = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, GraphicsMode.Default.Stencil, 0);

            DisplayDevice dd = DisplayDevice.Default;

            NativeWindow nw = new NativeWindow(Width, Height, "Test", GameWindowFlags.Default, gmode, dd);

            GraphicsContext glContext = new GraphicsContext(gmode, nw.WindowInfo, 3, 0, GraphicsContextFlags.Default);
            glContext.LoadAll();

            glContext.MakeCurrent(nw.WindowInfo);

            if (Load())
            {
                nw.Visible = true;
                while (nw.Visible)
                {
                    Frame();

                    glContext.SwapBuffers();

                    Thread.Sleep(1000 / 60); //"60" fps (not really...)

                    nw.ProcessEvents();
                }

                nw.Visible = false;
            }

            Unload();
        }
        public OpenGLGraphics(Form form)
        {
            this.form = form;
            var windowInfo = Utilities.CreateWindowsWindowInfo(form.Handle);
            context = new GraphicsContext(GraphicsMode.Default, windowInfo);
            context.MakeCurrent(windowInfo);
            context.LoadAll();

            GL.Enable(EnableCap.DepthTest);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.Lighting);
            GL.Light(LightName.Light0, LightParameter.Ambient, new[] {.2f, .2f, .2f, 1.0f});
            GL.Light(LightName.Light0, LightParameter.Diffuse, new[] {1, 1, 1, 1.0f});
            GL.Light(LightName.Light0, LightParameter.Position, new[] {Common.LightX, Common.LightY, Common.LightZ});
            GL.Enable(EnableCap.Light0);

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 prespective = Matrix4.CreatePerspectiveFieldOfView(Common.FieldOfView,
                (float)form.ClientSize.Width / (float)form.ClientSize.Height,
                Common.NearPlane, Common.FarPlane);
            GL.LoadMatrix(ref prespective);

            GL.MatrixMode(MatrixMode.Modelview);
            Matrix4 view = Matrix4.CreateTranslation(Common.CameraX, Common.CameraY, Common.CameraZ) *
                Matrix4.CreateRotationY(Common.CameraRotationY);
            GL.LoadMatrix(ref view);
        }
 private void CreateContext(Form form)
 {
     var windowInfo = Utilities.CreateWindowsWindowInfo(form.Handle);
     context = new GraphicsContext(GraphicsMode.Default, windowInfo);
     context.MakeCurrent(windowInfo);
     context.LoadAll();
     GL.Enable(EnableCap.DepthTest);
 }
 public OpenGLGraphics(Form form, Common common)
 {
     this.form = form;
     this.common = common;
     var windowInfo = Utilities.CreateWindowsWindowInfo(form.Handle);
     context = new GraphicsContext(GraphicsMode.Default, windowInfo);
     context.MakeCurrent(windowInfo);
     context.LoadAll();
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            ContextSettings contextSettings = new ContextSettings(24, 0, 0);
            var             window          = new RenderWindow(new SFML.Window.VideoMode(640, 480), "ImGui + SFML + .Net = <3", Styles.Default, contextSettings);

            OpenTK.Graphics.GraphicsMode graphicsMode = new OpenTK.Graphics.GraphicsMode(32, (int)contextSettings.DepthBits, (int)contextSettings.StencilBits, (int)contextSettings.AntialiasingLevel);
            OpenTK.Platform.IWindowInfo  windowInfo   = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(window.SystemHandle);

            OpenTK.Graphics.GraphicsContext context = new OpenTK.Graphics.GraphicsContext(graphicsMode, windowInfo);
            context.MakeCurrent(windowInfo);
            context.LoadAll();


            window.SetFramerateLimit(60);
            ImGuiSfml.Init(window);

            window.Closed += (s, e) => window.Close();

            CircleShape shape = new CircleShape(100);

            shape.FillColor = Color.Green;

            Clock deltaClock = new Clock();

            while (window.IsOpen)
            {
                window.DispatchEvents();

                ImGuiSfml.Update(window, deltaClock.Restart());

                ImGui.ShowDemoWindow();
                //ImGui.ShowTestWindow();

                /*
                 * ImGui.Begin("Hello, world!");
                 * ImGui.Button("Look at this pretty button");
                 * ImGui.End();
                 */

                window.Clear();
                window.Draw(shape);
                ImGuiSfml.Render(window);
                window.Display();
            }
        }
Ejemplo n.º 9
0
        // TODO: make a not terrible constructor
        public Renderer(IntPtr handle, int width, int height)
        {
            renderWidth = width;
            renderHeight = height;

            GraphicsContext = new GraphicsContext(GraphicsMode.Default, Utilities.CreateWindowsWindowInfo(handle));
            GraphicsContext.LoadAll();

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            Camera = new Camera(new Vector3(0.0f, 0.0f, 0.0f), 0, 0, 0, 90, new Vector2(width, height));

            DefaultRenderTextureShader defaultRenderTextureShader = new DefaultRenderTextureShader();
            _renderTextureMesh = new RenderTextureMesh(defaultRenderTextureShader);
            RenderTexture = new RenderTexture(width, height, defaultRenderTextureShader);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Request a 24-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 24;

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings);
            window.SetVerticalSyncEnabled(true);

            // Initialize OpenTK
            Toolkit.Init();

            GraphicsMode graphicsMode = new GraphicsMode(32, (int)contextSettings.DepthBits, (int)contextSettings.StencilBits, (int)contextSettings.AntialiasingLevel);
            IWindowInfo windowInfo = Utilities.CreateWindowsWindowInfo(window.SystemHandle);
            GraphicsContext context = new GraphicsContext(graphicsMode, windowInfo);
            context.LoadAll();

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Create a sprite for the background
            Sprite background = new Sprite(new Texture("resources/background.jpg"));

            // Create a text to display on top of the OpenGL object
            Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"));
            text.Position = new Vector2f(250, 450);
            text.Color = new Color(255, 255, 255, 170);

            // Make the window the active target for OpenGL calls
            window.SetActive();

            // Load an OpenGL texture.
            // We could directly use a SFML.Graphics.Texture as an OpenGL texture (with its Bind() member function),
            // but here we want more control on it (generate mipmaps, ...) so we create a new one
            int texture = 0;
            using (Image image = new Image("resources/texture.jpg"))
            {
                GL.GenTextures(1, out texture);
                GL.BindTexture(TextureTarget.Texture2D, texture);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)image.Size.X, (int)image.Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, image.Pixels);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            }

            // Enable Z-buffer read and write
            GL.Enable(EnableCap.DepthTest);
            GL.DepthMask(true);
            GL.ClearDepth(1);

            // Disable lighting
            GL.Disable(EnableCap.Lighting);

            // Configure the viewport (the same size as the window)
            GL.Viewport(0, 0, (int)window.Size.X, (int)window.Size.Y);

            // Setup a perspective projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            float ratio = (float)(window.Size.X) / window.Size.Y;
            GL.Frustum(-ratio, ratio, -1, 1, 1, 500);

            // Bind the texture
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, texture);

            // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
            float[] cube = new float[]
            {
                // positions    // texture coordinates
                -20, -20, -20,  0, 0,
                -20,  20, -20,  1, 0,
                -20, -20,  20,  0, 1,
                -20, -20,  20,  0, 1,
                -20,  20, -20,  1, 0,
                -20,  20,  20,  1, 1,

                 20, -20, -20,  0, 0,
                 20,  20, -20,  1, 0,
                 20, -20,  20,  0, 1,
                 20, -20,  20,  0, 1,
                 20,  20, -20,  1, 0,
                 20,  20,  20,  1, 1,

                -20, -20, -20,  0, 0,
                 20, -20, -20,  1, 0,
                -20, -20,  20,  0, 1,
                -20, -20,  20,  0, 1,
                 20, -20, -20,  1, 0,
                 20, -20,  20,  1, 1,

                -20,  20, -20,  0, 0,
                 20,  20, -20,  1, 0,
                -20,  20,  20,  0, 1,
                -20,  20,  20,  0, 1,
                 20,  20, -20,  1, 0,
                 20,  20,  20,  1, 1,

                -20, -20, -20,  0, 0,
                 20, -20, -20,  1, 0,
                -20,  20, -20,  0, 1,
                -20,  20, -20,  0, 1,
                 20, -20, -20,  1, 0,
                 20,  20, -20,  1, 1,

                -20, -20,  20,  0, 0,
                 20, -20,  20,  1, 0,
                -20,  20,  20,  0, 1,
                -20,  20,  20,  0, 1,
                 20, -20,  20,  1, 0,
                 20,  20,  20,  1, 1
            };

            // Enable position and texture coordinates vertex components
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.VertexPointer(3, VertexPointerType.Float, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3));

            // Disable normal and color vertex components
            GL.DisableClientState(ArrayCap.NormalArray);
            GL.DisableClientState(ArrayCap.ColorArray);

            Clock clock = new Clock();

            // Start game loop
            while (window.IsOpen)
            {
                // Process events
                window.DispatchEvents();

                // Clear the window
                GL.Clear(ClearBufferMask.DepthBufferBit);

                // Draw background
                window.PushGLStates();
                window.Draw(background);
                window.PopGLStates();

                // Clear the depth buffer
                GL.Clear(ClearBufferMask.DepthBufferBit);

                // We get the position of the mouse cursor, so that we can move the box accordingly
                float x =  Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F;
                float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F;

                // Apply some transformations
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.Translate(x, y, -100.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 50, 1.0F, 0.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 30, 0.0F, 1.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 90, 0.0F, 0.0F, 1.0F);

                // Draw the cube
                GL.DrawArrays(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, 0, 36);

                // Draw some text on top of our OpenGL object
                window.PushGLStates();
                window.Draw(text);
                window.PopGLStates();

                // Finally, display the rendered frame on screen
                window.Display();
            }

            // Don't forget to destroy our texture
            GL.DeleteTextures(1, ref texture);
        }
Ejemplo n.º 11
0
		private void CreateContext ()
		{
			AssertNotDisposed ();

			Layer.DrawableProperties = NSDictionary.FromObjectsAndKeys (
				new NSObject [] {
					NSNumber.FromBoolean (true),
					EAGLColorFormat.RGBA8
				},
				new NSObject [] {
					EAGLDrawableProperty.RetainedBacking,
					EAGLDrawableProperty.ColorFormat
				});

			Layer.ContentsScale = Window.Screen.Scale;

			//var strVersion = OpenTK.Graphics.ES11.GL.GetString (OpenTK.Graphics.ES11.All.Version);
			//strVersion = OpenTK.Graphics.ES20.GL.GetString (OpenTK.Graphics.ES20.All.Version);
			//var version = Version.Parse (strVersion);

			EAGLRenderingAPI eaglRenderingAPI;
			try {
				_graphicsContext = new GraphicsContext (null, null, 2, 0, GraphicsContextFlags.Embedded);
				eaglRenderingAPI = EAGLRenderingAPI.OpenGLES2;
				_glapi = new Gles20Api ();
			} catch {
				_graphicsContext = new GraphicsContext (null, null, 1, 1, GraphicsContextFlags.Embedded);
				eaglRenderingAPI = EAGLRenderingAPI.OpenGLES1;
				_glapi = new Gles11Api ();
			}

			_graphicsContext.MakeCurrent (null);
			_graphicsContext.LoadAll ();

			// FIXME: These static methods on GraphicsDevice need
			// to go away someday.
			GraphicsDevice.OpenGLESVersion = eaglRenderingAPI;
		}
Ejemplo n.º 12
0
            void IXwtRender.CreateForWidgetContext(IRenderer renderer, IRenderOwner rendererimpl, Canvas widget)
            {
                var wBackend  = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget) as Xwt.Backends.ICanvasBackend;
                var gtkwidget = wBackend.GetType().GetPropertyValue(wBackend, "Widget");

                gtkwidget.GetType().SetPropertyValue(gtkwidget, "DoubleBuffered", false);
                // var widget = wBackend.GetType().GetPropertyValue(wBackend, "Widget");
                // widget.GetType().SetPropertyValue(widget, "DoubleBuffered", false);
                // var gdkwin = widget.GetType().GetPropertyValue(widget, "GdkWindow");
                var h = GetHandle(wBackend);                       // (IntPtr)gdkwin.GetType().GetPropertyValue(gdkwin, "Handle");

                IntPtr windowHandle = gdk_x11_drawable_get_xid(h); // wBackend.Widget.Handle
                IntPtr display2     = gdk_drawable_get_display(h);
                IntPtr display      = gdk_x11_drawable_get_xdisplay(h);
                IntPtr screen       = gdk_display_get_default_screen(display2);
                int    screenn      = gdk_screen_get_number(screen);
                IntPtr rootWindow   = gdk_screen_get_root_window(screen);
                IntPtr visualInfo   = IntPtr.Zero;

                XVisualInfo info = new XVisualInfo();

                info.VisualID = IntPtr.Zero;
                int dummy;

                visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
                //     }

                /*    else
                 *  {
                 *      visualInfo = GetVisualInfo(display);
                 *  }*/

                var          wBackendMain = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget.ParentWindow) as Xwt.Backends.IWindowFrameBackend;
                var          winmain      = wBackendMain.GetType().GetPropertyValue(wBackendMain, "Window");
                var          gdkwinmain   = winmain.GetType().GetPropertyValue(winmain, "GdkWindow");
                var          hmain        = (IntPtr)gdkwinmain.GetType().GetPropertyValue(gdkwinmain, "Handle");
                Canvas       view         = null;
                EventHandler sizefunc     = null;

                if (h == hmain)
                {
                    view = new global::Xwt.Canvas()
                    {
                        ExpandHorizontal = true, ExpandVertical = true, HorizontalPlacement = WidgetPlacement.Fill, VerticalPlacement = WidgetPlacement.Fill, MinWidth = 1, MinHeight = 1, BackgroundColor = Xwt.Drawing.Colors.Black
                    };
                    widget.AddChild(view);
                    var viewbackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(view) as Xwt.Backends.ICanvasBackend;
                    var gtkview     = viewbackend.GetType().GetPropertyValue(viewbackend, "Widget");
                    gtkview.GetType().SetPropertyValue(gtkview, "DoubleBuffered", false);
                    var hwnd = GetHandle(viewbackend);
                    Debug.Assert(hwnd != hmain);
                    sizefunc              = new EventHandler((s, a) => widget.SetChildBounds(view, new Rectangle(Point.Zero, widget.Size)));
                    widget.BoundsChanged += sizefunc;
                    sizefunc(null, EventArgs.Empty);

                    windowHandle = gdk_x11_drawable_get_xid(hwnd);
                }



                var WindowInfo = Utilities.CreateX11WindowInfo(display, screenn, windowHandle, rootWindow, visualInfo);

                XFree(visualInfo);

                var gfxcontext = new OpenTK.Graphics.GraphicsContext(new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8), WindowInfo, 3, 3, GraphicsContextFlags.Default);

                views[widget] = new viewinfo(WindowInfo, gfxcontext, (gfxcontext as IGraphicsContextInternal).Context)
                {
                    view = view, sizefunc = sizefunc
                };

                gfxcontext.MakeCurrent(WindowInfo);
                gfxcontext.LoadAll();

                int major, minor;

                GL.GetInteger(GetPName.MajorVersion, out major);
                GL.GetInteger(GetPName.MinorVersion, out minor);

                Console.WriteLine("OpenGL {0}.{1}", major, minor);

                gfxcontext.MakeCurrent(null);
            }
Ejemplo n.º 13
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Request a 24-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 24;

            // Create the main window
            Window window = new Window(new VideoMode(640, 480), "SFML window with OpenGL", Styles.Default, contextSettings);

            // Make it the active window for OpenGL calls
            window.SetActive();

            // Initialize OpenTK
            Toolkit.Init();

            GraphicsMode graphicsMode = new GraphicsMode(32, (int)contextSettings.DepthBits, (int)contextSettings.StencilBits, (int)contextSettings.AntialiasingLevel);
            IWindowInfo windowInfo = Utilities.CreateWindowsWindowInfo(window.SystemHandle);
            GraphicsContext context = new GraphicsContext(graphicsMode, windowInfo);
            context.LoadAll();

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Set the color and depth clear values
            GL.ClearDepth(1);
            GL.ClearColor(0, 0, 0, 1);

            // Enable Z-buffer read and write
            GL.Enable(EnableCap.DepthTest);
            GL.DepthMask(true);

            // Disable lighting and texturing
            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.Texture2D);

            // Configure the viewport (the same size as the window)
            GL.Viewport(0, 0, (int)window.Size.X, (int)window.Size.Y);

            // Setup a perspective projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            float ratio = (float)(window.Size.X) / window.Size.Y;
            GL.Frustum(-ratio, ratio, -1, 1, 1, 500);

            // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
            float[] cube = new float[]
            {
                // positions    // colors (r, g, b, a)
                -50, -50, -50,  0, 0, 1, 1,
                -50,  50, -50,  0, 0, 1, 1,
                -50, -50,  50,  0, 0, 1, 1,
                -50, -50,  50,  0, 0, 1, 1,
                -50,  50, -50,  0, 0, 1, 1,
                -50,  50,  50,  0, 0, 1, 1,

                 50, -50, -50,  0, 1, 0, 1,
                 50,  50, -50,  0, 1, 0, 1,
                 50, -50,  50,  0, 1, 0, 1,
                 50, -50,  50,  0, 1, 0, 1,
                 50,  50, -50,  0, 1, 0, 1,
                 50,  50,  50,  0, 1, 0, 1,

                -50, -50, -50,  1, 0, 0, 1,
                 50, -50, -50,  1, 0, 0, 1,
                -50, -50,  50,  1, 0, 0, 1,
                -50, -50,  50,  1, 0, 0, 1,
                 50, -50, -50,  1, 0, 0, 1,
                 50, -50,  50,  1, 0, 0, 1,

                -50,  50, -50,  0, 1, 1, 1,
                 50,  50, -50,  0, 1, 1, 1,
                -50,  50,  50,  0, 1, 1, 1,
                -50,  50,  50,  0, 1, 1, 1,
                 50,  50, -50,  0, 1, 1, 1,
                 50,  50,  50,  0, 1, 1, 1,

                -50, -50, -50,  1, 0, 1, 1,
                 50, -50, -50,  1, 0, 1, 1,
                -50,  50, -50,  1, 0, 1, 1,
                -50,  50, -50,  1, 0, 1, 1,
                 50, -50, -50,  1, 0, 1, 1,
                 50,  50, -50,  1, 0, 1, 1,

                -50, -50,  50,  1, 1, 0, 1,
                 50, -50,  50,  1, 1, 0, 1,
                -50,  50,  50,  1, 1, 0, 1,
                -50,  50,  50,  1, 1, 0, 1,
                 50, -50,  50,  1, 1, 0, 1,
                 50,  50,  50,  1, 1, 0, 1,
            };

            // Enable position and color vertex components
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(3, VertexPointerType.Float, 7 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0));
            GL.ColorPointer(4, ColorPointerType.Float, 7 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3));

            // Disable normal and texture coordinates vertex components
            GL.DisableClientState(ArrayCap.NormalArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);

            Clock clock = new Clock();

            // Start the game loop
            while (window.IsOpen)
            {
                // Process events
                window.DispatchEvents();

                // Clear color and depth buffer
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                // Apply some transformations
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.Translate(0.0F, 0.0F, -200.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 50, 1.0F, 0.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 30, 0.0F, 1.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 90, 0.0F, 0.0F, 1.0F);

                // Draw the cube
                GL.DrawArrays(PrimitiveType.Triangles, 0, 36);

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Enter the gameloop.
        /// </summary>
        void EnterGameloop()
        {
            // Create graphics context
            this.Log ("Creating graphics context");
            context = new GraphicsContext (
                mode: graphicsMode,
                window: window.WindowInfo,
                major: 4,
                minor: 0,
                flags: GraphicsContextFlags.ForwardCompatible
            );

            // Make the created context the current context
            context.MakeCurrent (window.WindowInfo);

            // Throw if context is not available
            GraphicsContext.Assert ();

            // Set vsync mode
            SetupVsync ();

            // Load OpenGL entry points
            this.Log ("Loading OpenGL entry points");
            context.LoadAll ();

            // Initialize the sprite batch
            SpriteBatch = new SpriteBatch (this);

            // Bind the UI
            UI.Bind (this);

            // Initialize the game
            this.Log ("Initializing game");
            PreInitialize ();
            Initialize ();

            // Set target framerate
            // Use 60hz if framerate is not set
            var framerate = Configuration.TargetFramerate > 0 ? Configuration.TargetFramerate : 60;

            // Prepare timing variables
            PrepareTiming (framerate);

            // Present the window to the user
            window.Visible = true;

            // Wait till the window is visible
            while (!windowVisible && !window.Focused && !window.Visible) { }

            // Enter the actual game loop
            while (!exit) {

                // Set updating to true
                updating = true;

                // Invoke waiting actions
                for (var i = 0; i < ContextActions.Count; i++) {
                    Action action;
                    if (ContextActions.TryDequeue (out action)) {
                        try {
                            action ();
                        } catch (Exception e) {
                            this.Throw (e.Message);
                        }
                    }
                }

                // Set the paused variable to true
                // if the game should be paused and continue
                if (pause) {
                    paused = true;
                    continue;
                }

                // Set the paused variable to false
                paused = false;

                // Break out of the loop if the context is not available.
                if (context.IsDisposed) {
                    this.Log ("Context not available");
                    this.Log ("Leaving gameloop");
                    break;
                }

                // Update current time
                currentTime = DateTime.UtcNow;

                // Update
                InternalUpdate (currentTime);

                // Draw
                Draw (gameTime);

                // Set updating to false
                updating = false;
            }
        }