Ejemplo n.º 1
0
 public override void Init()
 {
     t           = new Texture("Content/Untitled.png");
     spriteBatch = new SpriteBatch();
     Gl.Viewport(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
     Gl.ClearColor(1, 0, 0, 1);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Allocate GL resources or GL states.
        /// </summary>
        /// <param name="sender">
        /// The <see cref="object"/> that has rasied the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="GlControlEventArgs"/> that specifies the event arguments.
        /// </param>
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            // GL Debugging
            if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB)
            {
                Gl.DebugMessageCallback(GLDebugProc, IntPtr.Zero);
                Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, null, true);
            }

            _renderer = _rendererFactory.Create(Gl.CurrentVersion);

            _renderer.Create();

            ContextCreated?.Invoke(sender, e);

            Gl.ClearColor(0.0f, 0.4f, 0.6f, 1.0f);

            // Uses multisampling, if available
            if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0)
            {
                Gl.Enable(EnableCap.Multisample);
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override void Setup(Vector2 renderSize)
        {
            Gl.BindAPI(s => Glfw.GetProcAddress(s));
            Gl.QueryContextVersion();
            // Check if context was created.
            if (Gl.CurrentVersion == null)
            {
                ErrorHandler.SubmitError(new Exception("Couldn't connect to OpenGL context."));
                return;
            }

            // Bind current thread as the GLThread.
            GLThread.BindThread();

            // Renderer bootstrap.
            Engine.Log.Info("Creating OpenGL GraphicsManager...", MessageSource.GL);
            Engine.Log.Info($"GL: {Gl.CurrentVersion} on {Gl.CurrentRenderer}", MessageSource.GL);
            Engine.Log.Info($"GLSL: {Gl.CurrentShadingVersion}", MessageSource.GL);

            CreateDefaultShader();
            CreateDefaultIbo();

            // Set default state.
            DefaultGLState();
            ResetState();

            // Clear to transparent black.
            Gl.ClearColor(0, 0, 0, 0);

            Engine.Log.Info("GraphicsManager ready.", MessageSource.GL);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Allocate resources for rendering.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Wrap GL context with GraphicsContext
            _Context = new GraphicsContext(e.DeviceContext, e.RenderContext);

            // Scene
            _CubeScene = new SceneGraph(SceneGraphFlags.None)
            {
                SceneRoot   = new SceneObjectGeometry(),
                CurrentView = new SceneObjectCamera()
            };

            // Root object
            // _CubeScene.SceneRoot.ObjectState.DefineState(new DepthTestState(DepthFunction.Less));

            // Camera object
            _CubeScene.SceneRoot.Link(_CubeScene.CurrentView);

            // Horizontal plane
            _CubeScene.SceneRoot.Link(CreatePlane());

            // Create scene resource
            _CubeScene.Create(_Context);

            Gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);

            Gl.Enable(EnableCap.Multisample);
        }
Ejemplo n.º 5
0
        private SDLWIndow(string title, int width, int height) : base(title, width, height)
        {
            SDL.SDL_Init(SDL.SDL_INIT_VIDEO);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 8);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, 8);

            var flags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;

            if (FullScreen)
            {
                flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
            }


            _window = SDL.SDL_CreateWindow("title",
                                           SDL.SDL_WINDOWPOS_CENTERED,
                                           SDL.SDL_WINDOWPOS_CENTERED,
                                           width,
                                           height,
                                           flags);

            EntryPoint.CoreLogger.Assert(_window == IntPtr.Zero, "Could not create window!");

            _glContext = SDL.SDL_GL_CreateContext(_window);
            EntryPoint.CoreLogger.Assert(_glContext == IntPtr.Zero, "Could not create context!");

            Gl.ClearColor(0f, 0f, 0f, 1f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            SDL.SDL_GL_SwapWindow(_window);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Clear surface buffers.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for clearing buffers.
        /// </param>
        /// <param name="bufferMask">
        /// A <see cref="ClearBufferMask"/> indicating which buffers to clear.
        /// </param>
        public void Clear(GraphicsContext ctx, ClearBufferMask bufferMask)
        {
            // Update clear values (only what is necessary)
            if ((bufferMask & ClearBufferMask.ColorBufferBit) != 0)
            {
                Gl.ClearColor(mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a);
            }
#if !MONODROID
            if ((bufferMask & ClearBufferMask.DepthBufferBit) != 0)
            {
                Gl.ClearDepth(mClearDepth);
            }
#else
            if ((bufferMask & ClearBufferMask.DepthBufferBit) != 0)
            {
                Gl.ClearDepth((float)mClearDepth);
            }
#endif
            if ((bufferMask & ClearBufferMask.StencilBufferBit) != 0)
            {
                Gl.ClearStencil(mClearStencil);
            }

            // Clear
            Gl.Clear(bufferMask);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates an OpenGL context in a valid SDL window.
        /// </summary>
        /// <param name="window">The valid SDL window.</param>
        /// <param name="fullscreen">True if the window is already in fullscreen mode.</param>
        public static ErrorCode CreateContextFromWindow(IntPtr window, bool fullscreen = false)
        {
            if (window == IntPtr.Zero)
            {
                return(ErrorCode.WindowWasNotInitialized);
            }

            int width, height;

            SDL.SDL_GetWindowSize(window, out width, out height);

            Width      = width;
            Height     = height;
            Fullscreen = fullscreen;

            // create a valid OpenGL context within the newly created window
            glContext = SDL.SDL_GL_CreateContext(window);
            if (glContext == IntPtr.Zero)
            {
                return(ErrorCode.CouldNotCreateContext);
            }

            // initialize the screen to black as soon as possible
            Gl.ClearColor(0f, 0f, 0f, 1f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            SwapBuffers();

            Open = true;

            return(ErrorCode.Success);
        }
Ejemplo n.º 8
0
        public void InitializeRenderer(RendererWindow WindowHandle, IPreferredGraphicsDeviceFilter myPreferencesForDevice = null)
        {
            Gl.Enable(EnableCap.Multisample);
            byte[]  ShaderData = null;
            Program myProgram  = new Program(_VertexSourceGL, _FragmentSourceGL);

            int linked;

            Gl.GetProgram(ProgramName, ProgramProperty.LinkStatus, out linked);
            if (linked == 0)
            {
                throw new Exception("Damn");
            }
            if ((LocationMVP = Gl.GetUniformLocation(ProgramName, "uMVP")) < 0)
            {
                throw new InvalidOperationException("no uniform uMVP");
            }

            // Get attributes locations
            if ((LocationPosition = Gl.GetAttribLocation(ProgramName, "aPosition")) < 0)
            {
                throw new InvalidOperationException("no attribute aPosition");
            }
            if ((LocationColor = Gl.GetAttribLocation(ProgramName, "aColor")) < 0)
            {
                throw new InvalidOperationException("no attribute aColor");
            }
            this.WindowHandle = WindowHandle;
            _VertexArray      = new VertexArray(myProgram, _ArrayPosition, _ArrayColor);
            Gl.Viewport(0, 0, WindowHandle.Width, WindowHandle.Height);

            Gl.ClearColor(Color.AliceBlue.R, Color.AliceBlue.G, Color.AliceBlue.B, Color.AliceBlue.A);
        }
Ejemplo n.º 9
0
        public void Update()
        {
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);
            Gl.Viewport(0, 0, screenWidth, screenHeight);
            Color32 clrColor = sceneClear;

            Gl.ClearColor(clrColor.r / 255.0f, clrColor.g / 255.0f, clrColor.b / 255.0f, 255.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            ObjRenderer.RenderQueue();
            Debug.Label("obj render");
            drawScreen.Render();
            Debug.Label("soft render");

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            Gl.Viewport(0, 0, windowWidth, windowHeight);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            Debug.Label("framebuffer swap");
            Gl.UseProgram(shader);

            Gl.BindBufferToShaderAttribute(vertices, shader, "pos");
            Gl.BindBufferToShaderAttribute(uvs, shader, "uv");
            Gl.BindBuffer(triangles);
            Gl.BindTexture(TextureTarget.Texture2D, texture);

            Gl.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Debug.Label("framebuffer render");

            SDL.SDL_GL_SwapWindow(window);
            Debug.Label("swap window");
        }
Ejemplo n.º 10
0
        private void OnRender(object sender, OpenGL.GlControlEventArgs e)
        {
            GlControl gl_control = (GlControl)sender;


            if ((LastMotion == null) || (LastMotion.Finished == true))
            {
                // モーションをランダムに再生する
                // 名前なしのモーショングループから0~9番のモーションを乱数で選ぶ
                var motion_group = Asset.MotionGroups[""];
                int number       = new Random().Next() % motion_group.Length;
                var motion       = (CubismMotion)motion_group[number];
                LastMotion = Asset.StartMotion(CubismAsset.MotionType.Base, motion, false);
            }

            // モデルを更新する
            var elapsed = Timer.Elapsed;

            Timer.Restart();
            Asset.Update(elapsed.TotalSeconds);

            // モデルを描画する
            Gl.ClearColor(0.0f, 0.5f, 0.5f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            Gl.Viewport(0, 0, gl_control.Width, gl_control.Height);
            Matrix mvp_matrix = DenseMatrix.CreateIdentity(4);

            mvp_matrix[0, 0] = 2.0f;
            mvp_matrix[1, 1] = 2.0f * gl_control.Width / gl_control.Height;
            RenderingManager.Draw(mvp_matrix);
        }
Ejemplo n.º 11
0
        protected void Run()
        {
            while (!_mainWindow.Closing)
            {
                if (!_mainWindow.HandleEvents())
                {
                    return;
                }

                Gl.Clear(Gl.ColorBufferBit);
                Gl.ClearColor(0.6901961f, 0.1921569f, 0.2470588f, 1);

                Gl.MatrixMode(Gl.Projection);
                Gl.LoadIdentity();
                Gl.Ortho(0, 1, 0, 1, 0, 1);

                Gl.Begin(Gl.Triangles);
                Gl.Color3(1, 0, 0);
                Gl.Vertex2(0, 0);
                Gl.Color3(0, 1, 0);
                Gl.Vertex2(0.5f, 1);
                Gl.Color3(0, 0, 1);
                Gl.Vertex2(1, 0);
                Gl.End();

                //Gl.Clear(Gl.ColorBufferBit);

                _mainWindow.Swap();
            }
        }
Ejemplo n.º 12
0
        private void RenderControl_Render_GLSL(object sender, GlControlEventArgs e)
        {
            Control control = (Control)sender;

            PerspectiveProjectionMatrix projectionMatrix = new PerspectiveProjectionMatrix(45.0f, (float)control.Width / (float)control.Height, 0.1f, 100.0f);
            ModelMatrix viewMatrix  = new ModelMatrix();
            ModelMatrix modelMatrix = new ModelMatrix();

            modelMatrix.Translate(new Vertex3f(modelPosition.X, modelPosition.Y, modelPosition.Z));
            modelMatrix.Scale(new Vertex3f(0.2f, 0.2f, 0.2f));

            Gl.Viewport(0, 0, control.Width, control.Height);
            Gl.ClearColor(0.05f, 0.05f, 0.05f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            modelShader.Use();
            modelMatrix.RotateX(modelAngle.X);
            modelMatrix.RotateY(modelAngle.Y);
            modelMatrix.RotateZ(modelAngle.Z);
            //viewMatrix.Translate(new Vertex3f(-2.0f * (float)Math.Sin(modelAngle.Y * PI_OVER_180), 0.0f, -2.0f*(float)Math.Cos(modelAngle.Y*PI_OVER_180)));
            Gl.UniformMatrix4(modelShader.uLocation_Projection, 1, false, projectionMatrix.ToArray());
            Gl.UniformMatrix4(modelShader.uLocation_View, 1, false, viewMatrix.ToArray());
            Gl.UniformMatrix4(modelShader.uLocation_Model, 1, false, modelMatrix.ToArray());

            modelNanosuit.Draw(modelShader);
        }
Ejemplo n.º 13
0
        private static void OnRenderFrame()
        {
            // calculate how much time has elapsed since the last frame
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            Matrix4 modelMatrix = CreateModelMatrix(time_);

            time_ += deltaTime;
            effect_.update(deltaTime, Neutrino._math.vec3_(modelMatrix[3].x, modelMatrix[3].y, modelMatrix[3].z), null);

            // set up the OpenGL viewport and clear both the color and depth bits
            Gl.Viewport(0, 0, width, height);
            //Gl.ClearColor(0.5F, 0.5F, 0.5F, 0.0F);
            Gl.ClearColor(0.4F, 0.4F, 0.4F, 0.0F);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 projMatrix = Matrix4.CreatePerspectiveFieldOfView(60F * (float)Math.PI / 180F, (float)width / height, 1F, 10000F);             //.CreateOrthographic(width, height, 1F, 10000F);
            Matrix4 viewMatrix = Matrix4.LookAt(new Vector3(0, 0, 1000), Vector3.Zero, Vector3.Up);

            effect_.render(ref projMatrix, ref viewMatrix, ref modelMatrix);

            Glut.glutSwapBuffers();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.ClearColor(1.0f, 0.0f, 0.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.ProjectionMatrix = Matrix4x4f.Perspective(45.0f, senderAspectRatio, 0.1f, 100.0f);
            // _CubeScene.CurrentView.LocalModelView = Matrix4x4f.Translated(0.0f, 0.0f, 10.0f);
            //_CubeScene.CurrentView.LocalModelView =
            //	Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f) *
            //	Matrix4x4f.RotatedY(_ViewAzimuth) *
            //	Matrix4x4f.RotatedX(_ViewElevation) *
            //	Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever);
            //_CubeScene.CurrentView.LocalModelView =
            //	Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever) *
            //	Matrix4x4f.RotatedX(_ViewElevation) *
            //	Matrix4x4f.RotatedY(_ViewAzimuth) *
            //	Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.UpdateViewMatrix();

            _CubeScene.Draw(_Context);
        }
Ejemplo n.º 15
0
 private void Render()
 {
     _transform     *= Mat4F.Rotation(1, new Vec3 <float>(0.0f, 0.0f, 1.0f));
     _root.Transform = _transform;
     Gl.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
     Gl.Clear(Gl.ColorBufferBit);
     _root.Render();
 }
Ejemplo n.º 16
0
        private void glClear(uint color, float alpha)
        {
            uint r = ((color & 0x00ff0000) >> 16);
            uint g = ((color & 0x0000ff00) >> 8);
            uint b = ((color & 0x000000ff));

            Gl.ClearColor(r / 255f, g / 255f, b / 255f, alpha);
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            Glfw.Init();

            Glfw.WindowHint(Hint.ContextVersionMajor, 4);
            Glfw.WindowHint(Hint.ContextVersionMinor, 6);
            Glfw.WindowHint(Hint.OpenglProfile, Profile.Compatibility);
            Window window = Glfw.CreateWindow(1080, 720, "Yeet", Monitor.None, Window.None);

            // `Gl.Initialize()` has to be don before `Glfw.MakeContextCurrent(window)`
            // [How Do I Initialize OpenGL.NET with GLFW.Net?](https://stackoverflow.com/questions/61318104/how-do-i-initialize-opengl-net-with-glfw-net/61319044?noredirect=1#comment108476826_61319044)
            Gl.Initialize();
            Glfw.MakeContextCurrent(window);

            var v = Gl.GetString(StringName.Version);

            Console.WriteLine(v);

            uint vao = Gl.CreateVertexArray();

            Gl.BindVertexArray(vao);

            uint vbo = Gl.GenBuffer();

            Gl.BindBuffer(BufferTarget.ArrayBuffer, vbo);

            var vertices = new float[] { -0.5f, -0.5f, 0.5f, -0.5f, 0.0f, 0.5f };

            Gl.BufferData(BufferTarget.ArrayBuffer, (uint)(4 * vertices.Length), null, BufferUsage.StaticDraw);

            IntPtr unmanagedPointer = Marshal.AllocHGlobal(4 * vertices.Length);

            Marshal.Copy(vertices, 0, unmanagedPointer, vertices.Length);
            Gl.BufferSubData(BufferTarget.ArrayBuffer, new IntPtr(0), (uint)(4 * vertices.Length), unmanagedPointer);
            Marshal.FreeHGlobal(unmanagedPointer);

            //Gl.BufferSubData(BufferTarget.ArrayBuffer, new IntPtr(0), (uint)(4 * vertices.Length), vertices);

            Gl.VertexAttribPointer(0, 2, VertexAttribType.Float, false, 0, null);

            while (!Glfw.WindowShouldClose(window))
            {
                Glfw.PollEvents();

                Gl.ClearColor(0.0f, 1.0f, 1.0f, 1.0f);
                Gl.Clear(ClearBufferMask.ColorBufferBit);
                Gl.BindVertexArray(vao);
                Gl.EnableVertexAttribArray(0);
                Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                Gl.DisableVertexAttribArray(0);
                Gl.BindVertexArray(0);

                Glfw.SwapBuffers(window);
            }

            Glfw.DestroyWindow(window);
            Glfw.Terminate();
        }
Ejemplo n.º 18
0
 public void ClearBuffer(Pixel p, bool bDepth)
 {
     Gl.ClearColor((float)p.r / 255.0f, (float)p.g / 255.0f, (float)p.b / 255.0f, (float)p.a / 255.0f);
     Gl.Clear(ClearBufferMask.ColorBufferBit);
     if (bDepth)
     {
         Gl.Clear(ClearBufferMask.DepthBufferBit);
     }
 }
Ejemplo n.º 19
0
        private void glClear(uint color)
        {
            uint a = ((color & 0xff000000) >> 24);
            uint r = ((color & 0x00ff0000) >> 16);
            uint g = ((color & 0x0000ff00) >> 8);
            uint b = ((color & 0x000000ff));

            Gl.ClearColor(r / 255f, g / 255f, b / 255f, a);
        }
Ejemplo n.º 20
0
 public override void Draw(int viewPortWidth, int viewPortHeight)
 {
     UserProgram(_program);
     Gl.ClearColor(0.0f, 0.5f, 1.0f, 1.0f);
     Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
     Gl.BindTexture(TextureTarget.Texture2d, _texture1);
     base.Draw(viewPortWidth, viewPortHeight);
     Gl.BindVertexArray(_vertexAttrObject);
     Gl.DrawArrays(PrimitiveType.Triangles, 0, _figureResult.Figure.Length);
 }
Ejemplo n.º 21
0
        private void WindowOnRender(double deltaTime)
        {
            Controller.Update((float)deltaTime);
            Gl.ClearColor(Color.FromArgb(255, 0, 32, 40));
            Gl.Clear((uint)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit));

            ImGuiNET.ImGui.ShowDemoWindow();

            Controller.Render();
        }
Ejemplo n.º 22
0
        public void ClearFrameBuffer(float r, float g, float b, float a)
        {
            FrameBuffer.Bind();

            Gl.ClearColor(r, g, b, a);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            FrameBuffer.Unbind();
        }
Ejemplo n.º 23
0
        public ImageBoxWindow()
        {
            InitializeComponent();

            GlWindow = new GlWindow(Handle);

            GlWindow.Begin();
            Gl.ClearColor(Color.WhiteSmoke);
            GlWindow.End();
        }
Ejemplo n.º 24
0
        private void SurfaceView_Render(object sender, GLSurfaceViewEventArgs e)
        {
            GLSurfaceView glSurfaceView = (GLSurfaceView)sender;

            Gl.Viewport(0, 0, glSurfaceView.Width, glSurfaceView.Height);
            Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Es2_Render();
        }
Ejemplo n.º 25
0
        public override void Draw(int viewPortWidth, int viewPortHeight)
        {
            UserProgram(_program);
            Gl.ClearColor(0.0f, 0.5f, 1.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            int vertexCount = _figureResult.Figure.Length / _figureResult.VertexPerLineCount;

            Gl.BindVertexArray(_vertexAttrObject);
            Gl.DrawArrays(PrimitiveType.Triangles, 0, vertexCount);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Clears the render context with a certain color and alpha value. Since this also
        /// clears the stencil buffer, the stencil reference value is also reset to '0'.
        /// </summary>
        public void Clear(uint rgb = 0, float alpha = 0.0f)
        {
            ApplyRenderTarget();

            float red   = ColorUtil.GetR(rgb) / 255.0f;
            float green = ColorUtil.GetG(rgb) / 255.0f;
            float blue  = ColorUtil.GetB(rgb) / 255.0f;

            Gl.ClearColor(red, green, blue, alpha);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.DepthBufferBit);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Allocate resources for rendering.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Wrap GL context with GraphicsContext
            _Context = new GraphicsContext(e.DeviceContext, e.RenderContext);
            // Create resources
            CreateResources(_Context);

            Gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);

            Gl.Enable(EnableCap.Multisample);
        }
Ejemplo n.º 28
0
        internal ImageBoxMiniMap(ImageBoxWindow imageBoxWindow)
        {
            InitializeComponent();
            m_glWindow = new GlWindow(Handle);

            m_glWindow.Begin();
            Gl.ClearColor(Color.WhiteSmoke);
            m_glWindow.End();

            m_imageBoxWindow = imageBoxWindow;
            Win32.wglShareLists(m_imageBoxWindow.GlWindow.Hglrc, m_glWindow.Hglrc);
        }
Ejemplo n.º 29
0
        private void GlControl_OnContextCreated(object sender, GlControlEventArgs e)
        {
            var control = (GlControl)sender;

            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();

            Gl.ClearColor(_bgColorVec.X, _bgColorVec.Y, _bgColorVec.Z, _bgColorVec.W);

            Shader = new ShaderHelper();
            AdjustOrtho(new Size(control.Height, control.Width));
        }
Ejemplo n.º 30
0
        private static void OnRenderFrame()
        {
            // set up the OpenGL viewport and clear both the color and depth bits
            Gl.Viewport(0, 0, Window.Width, Window.Height);
            Gl.ClearColor(0.2f, 0.2f, 0.2f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // draw the user interface after everything else
            OpenGL.UI.UserInterface.Draw();

            // finally, swap the back buffer to the front so that the screen displays
            Window.SwapBuffers();
        }