Пример #1
0
        //primitives
        public virtual void begin(IRenderTarget target, GLSortMode mode)
        {
            if (_begin)
            {
                throw new InvalidOperationException("You must call end before you can call begin again.");
            }

            if (_stateStack.Count > 0)
            {
                throw new InvalidOperationException("State stack was not empty.");
            }

            if (_clipStack.Count > 0)
            {
                throw new InvalidOperationException("Clipping stack was not empty.");
            }

            if (_effectStack.Count > 0)
            {
                throw new InvalidOperationException("Effect stack was not empty.");
            }

            _target          = target;
            _begin           = true;
            _sortMode        = mode;
            _renderableIndex = 0;
            _clipping        = AxisAlignedBox2.Null;
            _effect          = null;
            //_currentMatrix = Matrix3.Identity;
            _state = GLState.empty;

            _target.enable();
            //check other settings
        }
Пример #2
0
 //[MethodImpl(MethodImplOptions.AggressiveInlining)]
 private void StatesOn(GLState[] stateList)
 {
     int count = stateList.Length;
     for (int i = 0; i < count; i++)
     {
         stateList[i].On();
     }
 }
Пример #3
0
 //[MethodImpl(MethodImplOptions.AggressiveInlining)]
 private void StatesOff(GLState[] stateList)
 {
     int count = stateList.Length;
     for (int i = count - 1; i >= 0; i--)
     {
         stateList[i].Off();
     }
 }
Пример #4
0
 public GLDrawCall(GLShaderProgram program, GLTextureBind[] textureBinds, GLVertexArrayObject vertexArrayObject,
                   UniformBind[] uniformBinds, Action drawAction, GLState state = null)
 {
     Program           = program;
     TextureBinds      = textureBinds;
     VertexArrayObject = vertexArrayObject;
     UniformBinds      = uniformBinds;
     DrawAction        = drawAction;
     State             = state ?? GLState.Default;
 }
Пример #5
0
        //public void push(Matrix4 matrix) { }
        public virtual void pop()
        {
            verifyBegin();

            if (_stateStack.Count == 0)
            {
                throw new InvalidOperationException("State stack was empty.");
            }

            _state = _stateStack.Pop();
        }
        /// <summary>
        /// Window resize event to adjusts perspective.
        /// </summary>
        private void GlControl1_SizeChanged(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            view.Resize(glControl1.Bounds, glControl1.Bounds.Width, glControl1.Bounds.Height);
            view.UpdateProjection();

            textRenderer.Resize(glControl1.Bounds.Size);

            GLState.Viewport = view.Viewport;
            GLState.Apply(glControl1.Size);
        }
Пример #7
0
 public GLAspectPoints(GraphicsInterface gi)
     :base(gi)
 {
     fState = new GLState(gi);
     fSmoothing = new GLFeaturePointSmooth(gi);
 }
Пример #8
0
 protected override void Set(CullMode value) => GLState.SetCullMode(value);
        /// <summary>
        /// Redraw cuboid polygons.
        /// </summary>
        private void GlControl1_Paint(object sender, PaintEventArgs e)
        {
            if (isInErrorState == true)
            {
                return;
            }

            try
            {
                if (WindowState == FormWindowState.Minimized)
                {
                    return;
                }

                EulerAngles euler = NgimuApi.Maths.Quaternion.ToEulerAngles(quaternion);

                NgimuApi.Maths.Quaternion quat = quaternion;

                // Apply transformation matrix to cuboid
                RotationMatrix rotationMatrix = NgimuApi.Maths.Quaternion.ToRotationMatrix(quat);

                try
                {
                    glControl1.MakeCurrent();
                }
                catch (OpenTK.Graphics.GraphicsContextException ex)
                {
                    DisposeOpenGLControl();

                    LoadOpenGLControl();

                    return;
                }

                view.Rotation = OpenTK.Quaternion.FromAxisAngle(OpenTK.Vector3.UnitY, m_ViewYaw) * OpenTK.Quaternion.FromAxisAngle(OpenTK.Vector3.UnitX, m_ViewPitch);

                view.UpdateProjection();

                foreach (ModelSceneLight sceneLight in sceneLights)
                {
                    sceneLight.Update();
                }

                GLState.ClearColor(new Color4(15, 15, 15, 255));

                GLState.CullFace(OpenTK.Graphics.OpenGL.CullFaceMode.Back);
                GLState.EnableCullFace  = true;
                GLState.EnableDepthMask = true;
                GLState.EnableDepthTest = true;
                GLState.EnableBlend     = true;

                GLState.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GLState.BlendEquation(BlendEquationMode.FuncAdd);
                GLState.ClearDepth(1.0f);
                GLState.Viewport = view.Viewport;

                GLState.ApplyAll(glControl1.Size);

                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                Matrix4 model = Matrix4.Identity;

                OpenTK.Quaternion inverse = OpenTK.Quaternion.Invert(new OpenTK.Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W));

                model *= Matrix4.CreateScale(1f / modelScale);
                model *= Matrix4.CreateScale(3f);
                model *= Matrix4.CreateFromQuaternion(inverse);
                model *= Matrix4.CreateRotationX(-MathHelper.PiOver2);

                OpenTK.Quaternion normalQuaternion = model.ExtractRotation();

                Matrix4 normal = Matrix4.CreateFromQuaternion(normalQuaternion);

                float Emissivity = 0f;
                float Alpha      = 1f;

                OpenTK.Vector3 color      = new OpenTK.Vector3(1f, 1f, 1f);
                OpenTK.Vector3 modelColor = new OpenTK.Vector3(0.6f, 0.6f, 0.6f);
                Vector2        surface    = new Vector2(1f - (Emissivity * Emissivity), Alpha);

                lightingArguments.NormalWorldMatrix = view.NormalWorld;
                lightingArguments.WorldMatrix       = view.World;
                lightingArguments.ProjectionMatrix  = view.Projection;

                for (int i = 0; i < sceneLights.Length; i++)
                {
                    lights[i] = sceneLights[i].ToLightInstance(ref view.World, ref view.NormalWorld);
                }

                ModelLightInstance light = lights[0];

                if (imuModelToolStripMenuItem.Checked == true)
                {
                    material.Render(ref model, ref normal, ref modelColor, ref surface, null, lightingArguments, ref light, imuModel.Vertices);
                }

                if (earthToolStripMenuItem.Checked == true)
                {
                    Matrix4 tileModel       = Matrix4.Identity;
                    Matrix4 tileModelNormal = Matrix4.Identity;

                    tileModel *= Matrix4.CreateScale(4f, 0.1f, 4f);
                    tileModel *= Matrix4.CreateTranslation(new OpenTK.Vector3(0, -3.5f, 0));
                    tileModel *= Matrix4.CreateScale(1f / modelScale);

                    color   = new OpenTK.Vector3(1f, 1f, 1f);
                    surface = new Vector2(1f, 0.5f);

                    tileMaterial.Render(ref tileModel, ref tileModelNormal, ref color, ref surface, tileTexture, lightingArguments, ref light, floorTileModel.Vertices);
                    //material.Render(ref tileModel, ref tileModelNormal, ref color, ref surface, null, lightingArguments, ref light, floorTileModel.Vertices);
                }

                textRenderer.Clear(Color.Transparent);

                if (imuAxesToolStripMenuItem.Checked == true)
                {
                    RenderAxes(model, OpenTK.Vector3.Zero, inverse, normalQuaternion, normal, Emissivity, Alpha, color, surface, light, 1f, 3.5f);

                    Matrix4 earthMatrix = Matrix4.Identity;

                    OpenTK.Vector3 offset = UnProject(ref view.Projection, ref view.View, glControl1.Size, new Vector2(-0.75f, -0.75f));

                    //OpenTK.Vector3 offset = new OpenTK.Vector3(0.5f, 0.5f, 0.1f);

                    OpenTK.Quaternion earthInverse = OpenTK.Quaternion.Identity;
                    OpenTK.Quaternion earthNormal  = OpenTK.Quaternion.Identity;

                    RenderAxes(earthMatrix, offset, earthInverse, earthNormal, earthMatrix, Emissivity, Alpha, color, surface, light, 0.025f, 3.75f);
                }

                if (eulerAnglesToolStripMenuItem.Checked == true)
                {
                    textRenderer.DrawString("Roll", m_BaseFont2, Brushes.LightGray, new PointF(20, 44), false);
                    textRenderer.DrawString("Pitch", m_BaseFont2, Brushes.LightGray, new PointF(20, 84), false);
                    textRenderer.DrawString("Yaw", m_BaseFont2, Brushes.LightGray, new PointF(20, 124), false);

                    int verticleOffset = 4;

                    textRenderer.DrawString(String.Format("{0,7:###0.0}", euler[0]) + "°", m_BaseFont, Brushes.LightGray, new PointF(80, 44 + verticleOffset), false);
                    textRenderer.DrawString(String.Format("{0,7:###0.0}", euler[1]) + "°", m_BaseFont, Brushes.LightGray, new PointF(80, 84 + verticleOffset), false);
                    textRenderer.DrawString(String.Format("{0,7:###0.0}", euler[2]) + "°", m_BaseFont, Brushes.LightGray, new PointF(80, 124 + verticleOffset), false);
                }

                textRenderer.Update();

                texturedQuad.Render(view);

                glControl1.SwapBuffers();
            }
            catch (Exception ex)
            {
                using (ExceptionDialog dialog = new ExceptionDialog())
                {
                    dialog.Title = "An Exception Occurred";

                    dialog.Label  = ex.Message;
                    dialog.Detail = ex.ToString();

                    dialog.ShowDialog(this);
                }

                isInErrorState = true;
            }
        }
Пример #10
0
 protected override void Set(DepthMode value) => GLState.SetDepthMode(value);
Пример #11
0
 protected override void Set(BlendMode value) => GLState.SetBlendMode(value);