Exemple #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Constructor. </summary>
        /// <param name="a_oEffect"> The shader program. </param>
        /// <param name="a_v3Pos">          The position of the first character. </param>
        /// <param name="a_v2Size">         Size of the first character. </param>
        /// <param name="a_oColor">         The color. </param>
        /// <param name="a_szFontDataFile"> (optional) the font data file. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public GLFont(GLEffect a_oEffect, Vector3 a_v3Pos, Vector2 a_v2Size, System.Drawing.Color a_oColor, string a_szFontDataFile, string a_szText = "")
        {
            // load in data:
            m_oFontData = Helpers.ResourceManager.Instance.LoadGLFont(a_szFontDataFile);

            m_v3Position = a_v3Pos;
            m_v2Size     = a_v2Size;
            m_szText     = a_szText;

            // Creat some working vars:
            Vector3 v3CharPos = new Vector3();

            // create quads and position them accordingly:
            for (uint i = 0; i < c_uiMaxNumberOfChars; ++i)
            {
                // Create offseted position:
                v3CharPos.X = a_v3Pos.X + i * a_v2Size.X;
                v3CharPos.Y = a_v3Pos.Y;
                // Create Quad and set its texture:
                GLQuad oQuad = new GLQuad(a_oEffect, v3CharPos, a_v2Size, a_oColor);
                oQuad.TextureID = m_oFontData.m_uiTextureID;

                // add quad to the list:
                m_lQuads.Add(oQuad);
            }

            UpdateUVCoords();
        }
        //have to add new entry for GL Circle to draw sensor bubbles around taskgroups/populations/missile contacts
        //CircleElement has the circle in it already, but that might be inappropriate for what I want
        //SceenElement has the lable properly done.

        public SensorElement(GLEffect a_oDefaultEffect, Vector3 a_oPosition, float a_fRadius, System.Drawing.Color a_oColor, String LabelText, GameEntity Ent,  ComponentTypeTN SType, Sceen ParentSceenArg)
            : base()
        {
            _ParentSceen = ParentSceenArg;

            _DisplayRadius = a_fRadius;

            m_oPrimaryPrimitive = new GLCircle(a_oDefaultEffect,
                        a_oPosition,
                        a_fRadius,
                        a_oColor,
                        UIConstants.Textures.DEFAULT_TEXTURE);

            m_lPrimitives.Add(m_oPrimaryPrimitive);

            int LabelMid = LabelText.Length / 4;
            float xAdjust = -LabelMid * (UIConstants.DEFAULT_TEXT_SIZE.X / _ParentSceen.ZoomSclaer);
            float yAdjust = 10.0f / ParentSceenArg.ZoomSclaer;
            Vector3 LPos = new Vector3(xAdjust, (a_fRadius + yAdjust), 0.0f);
            LPos = LPos + a_oPosition;
            Lable = new GLUtilities.GLFont(a_oDefaultEffect, LPos, UIConstants.DEFAULT_TEXT_SIZE, a_oColor, UIConstants.Textures.DEFAULT_GLFONT2, LabelText);
            Lable.Size = UIConstants.DEFAULT_TEXT_SIZE / ParentSceenArg.ZoomSclaer;
            SetActualPosition(a_oPosition);

            SceenEntity = Ent;
            _SensorType = SType;
        }
        public CircleElement(GLEffect a_oDefaultEffect, Vector3 a_oPosition, OrbitingEntity a_oOrbitEntity, System.Drawing.Color a_oColor)
            : base()
        {

            m_oPrimaryPrimitive = new GLCircle(a_oDefaultEffect,
                        a_oPosition,
                        a_oOrbitEntity,
                        a_oColor,
                        UIConstants.Textures.DEFAULT_TEXTURE);

            m_lPrimitives.Add(m_oPrimaryPrimitive);
        }
Exemple #4
0
        public StarElement(Star a_oStar, GLEffect a_oDefaultEffect, Vector3 a_oPosition, System.Drawing.Color a_oColor, bool a_bPrimary = true)
            : base(a_oStar)
        {
            if (!a_bPrimary)
            {
                // Do Non Primary Star Stuff here (e.g. orbit circle).
                ///< @todo...

                m_oOrbitCircle = new CircleElement(a_oDefaultEffect, a_oPosition, a_oStar, a_oColor);
#warning As with planet, m_oOrbitCircle will not be added as a child.
            }
            else
                m_oOrbitCircle = null;


        }
Exemple #5
0
        /// <summary>
        /// Removes a contact element from the display. This is controlled by SystemContact.ContactElementCreated.
        /// </summary>
        /// <param name="a_oDefaultEffect"></param>
        /// <param name="oContact"></param>
        public void RemoveContactElement(GLEffect a_oDefaultEffect, SystemContact oContact)
        {
            foreach (SceenElement Ele in m_lElements)
            {
                /// <summary>
                /// Have to use Guid to identify elements and get rid of the one we no longer want. 
                /// Update: as it turns out Id was not being declared anywhere.
                /// </summary>
                if (Ele.EntityID == oContact.Id)
                {
                    m_lElements.Remove(Ele);
                    break;
                }
            }

        }
Exemple #6
0
        /// <summary>
        /// creates a new post sceen creation contact element.
        /// </summary>
        /// <param name="a_oDefaultEffect">default effect, I don't know what these are really.</param>
        /// <param name="oContact">The system contact to be created.</param>
        public void AddContactElement(GLEffect a_oDefaultEffect, SystemContact oContact)
        {
            SceenElement oContactElement;
            Vector3 v3ContactPos;
            GLUtilities.GLFont oNameLable;
            GLUtilities.GLQuad oContactQuad;

            switch (oContact.SSEntity)
            {
                case StarSystemEntityType.TaskGroup:
                    TaskGroupTN TaskGroup = oContact.Entity as TaskGroupTN;
                    oContactElement = new ContactElement(a_oDefaultEffect, oContact);
                    oContactElement.EntityID = oContact.Id;

                    v3ContactPos = new Vector3((float)TaskGroup.Contact.Position.X, (float)TaskGroup.Contact.Position.Y, 0.0f);

                    oContactQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                                                                    v3ContactPos,
                                                                    new Vector2(0.0001f, 0.0001f),                   // what size is a task groug anyway???
                                                                    oContact.faction.FactionColor,
                                                                    UIConstants.Textures.DEFAULT_TASKGROUP_ICON);

                    oNameLable = new GLUtilities.GLFont(a_oDefaultEffect, v3ContactPos,
                    UIConstants.DEFAULT_TEXT_SIZE, oContact.faction.FactionColor, UIConstants.Textures.DEFAULT_GLFONT2, TaskGroup.Name);

                    oContactElement.Lable = oNameLable;
                    oContactElement.Lable.Size = UIConstants.DEFAULT_TEXT_SIZE / m_fZoomScaler; //Initial taskgroup names weren't being scaled properly for whatever reason.
                    oContactElement.PrimaryPrimitive = oContactQuad;
                    oContactElement.AddPrimitive(oContactQuad);
                    oContactElement.RealSize = new Vector2(0.0001f, 0.0001f);
                    this.AddElement(oContactElement);
                    (oContactElement as ContactElement).ParentSceen = this;
                    break;
                case StarSystemEntityType.Missile:
                    OrdnanceGroupTN MissileGroup = oContact.Entity as OrdnanceGroupTN;
                    oContactElement = new ContactElement(a_oDefaultEffect, oContact);
                    oContactElement.EntityID = oContact.Id;

                    v3ContactPos = new Vector3((float)MissileGroup.contact.Position.X, (float)MissileGroup.contact.Position.Y, 0.0f);

                    oContactQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                                                                v3ContactPos,
                                                                new Vector2(0.0001f, 0.0001f),                   // what size is a missile?
                                                                oContact.faction.FactionColor,
                                                                UIConstants.Textures.DEFAULT_TASKGROUP_ICON);

                    oNameLable = new GLUtilities.GLFont(a_oDefaultEffect, v3ContactPos,
                    UIConstants.DEFAULT_TEXT_SIZE, oContact.faction.FactionColor, UIConstants.Textures.DEFAULT_GLFONT2, MissileGroup.Name);

                    oContactElement.Lable = oNameLable;
                    oContactElement.Lable.Size = UIConstants.DEFAULT_TEXT_SIZE / m_fZoomScaler; //Same problem may exist with missile labels.
                    oContactElement.PrimaryPrimitive = oContactQuad;
                    oContactElement.AddPrimitive(oContactQuad);
                    oContactElement.RealSize = new Vector2(0.0001f, 0.0001f);
                    this.AddElement(oContactElement);
                    (oContactElement as ContactElement).ParentSceen = this;
                    break;
                case StarSystemEntityType.Population:
                    Population CurrentPopulation = oContact.Entity as Population;
                    oContactElement = new ContactElement(a_oDefaultEffect, oContact);
                    oContactElement.EntityID = oContact.Id;

                    v3ContactPos = new Vector3((float)CurrentPopulation.Contact.Position.X, (float)CurrentPopulation.Contact.Position.Y, 0.0f);

                    oContactQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                                                                v3ContactPos,
                                                                new Vector2(0.0001f, 0.0001f),                   // what size is a population?
                                                                oContact.faction.FactionColor,
                                                                UIConstants.Textures.DEFAULT_TASKGROUP_ICON);

                    oNameLable = new GLUtilities.GLFont(a_oDefaultEffect, v3ContactPos,
                    UIConstants.DEFAULT_TEXT_SIZE, oContact.faction.FactionColor, UIConstants.Textures.DEFAULT_GLFONT2, CurrentPopulation.Name);

                    oContactElement.Lable = oNameLable;
                    oContactElement.Lable.Size = UIConstants.DEFAULT_TEXT_SIZE / m_fZoomScaler; //Same problem may exist with population labels.
                    oContactElement.PrimaryPrimitive = oContactQuad;
                    oContactElement.AddPrimitive(oContactQuad);
                    oContactElement.RealSize = new Vector2(0.0001f, 0.0001f);
                    this.AddElement(oContactElement);
                    (oContactElement as ContactElement).ParentSceen = this;
                    break;
            }

        }
Exemple #7
0
        public void AddMapMarker(Vector3 a_v3Pos, GLEffect a_oDefaultEffect)
        {
            MapMarker oMapMarker = new MapMarker();

            GLUtilities.GLQuad oMarkerQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                                                                        a_v3Pos,
                                                                        new Vector2(0.0001f, 0.0001f),
                                                                        Color.Tan,
                                                                        UIConstants.Textures.DEFAULT_PLANET_ICON);
            // create name lable:
            int m_Count = m_lMapMarkers.Count + 1;
            string name = "WP" + m_Count.ToString();
            GLUtilities.GLFont oNameLable = new GLUtilities.GLFont(a_oDefaultEffect, a_v3Pos,
                UIConstants.DEFAULT_TEXT_SIZE, Color.Tan, UIConstants.Textures.DEFAULT_GLFONT, name);

            oMapMarker.AddPrimitive(oMarkerQuad);
            oMapMarker.PrimaryPrimitive = oMarkerQuad;
            oMapMarker.Lable = oNameLable;

            oMapMarker.ParentSceen = this;

            m_lMapMarkers.Add(oMapMarker);

            Refresh();
        }
Exemple #8
0
        public Sceen(StarSystem a_oStarSystem, GLEffect a_oDefaultEffect, Pulsar4X.UI.Handlers.SystemMap ParentSM)
        {
            // set member vars:
            m_v3ViewOffset = Vector3.Zero;
            MeasureMode = false;

            ParentSystemMap = ParentSM;
            SceenDefaultEffect = a_oDefaultEffect;

            /// <summary>
            /// These have to be initialized before the contactElements are created as contactElement uses these.
            /// </summary>
            ShowActives = true;
            ShowPassives = true;
            ShowPassiveSignatureRange = (int)Constants.SensorTN.DefaultPassiveSignature;

            // Set Sceen Vars:
            m_oSceenEntity = a_oStarSystem;
            SceenID = a_oStarSystem.Id;

            // Create measurement element:
            m_oMeasurementElement = new MeasurementElement();
            m_oMeasurementElement.PrimaryPrimitive = new GLLine(a_oDefaultEffect, Vector3.Zero, new Vector2(1.0f, 1.0f), Color.Yellow, UIConstants.Textures.DEFAULT_TEXTURE);
            m_oMeasurementElement.AddPrimitive(m_oMeasurementElement.PrimaryPrimitive);
            m_oMeasurementElement.Lable = new GLUtilities.GLFont(a_oDefaultEffect, Vector3.Zero, UIConstants.DEFAULT_TEXT_SIZE, Color.Yellow, UIConstants.Textures.DEFAULT_GLFONT2, "");

            // Creat Working Vars:
            //double dKMperAUdevby10 = (Pulsar4X.Constants.Units.KmPerAu / 10); // we scale everthing down by 10 to avoid float buffer overflows.
            int iStarCounter = 0;                                               // Keeps track of the number of stars.
            int iPlanetCounter = 0;                                             // Keeps track of the number of planets around the current star
            int iMoonCounter = 0;                                               // Keeps track of the number of moons around the current planet.
            double dMaxOrbitDist = 0;                                           // used for fit to zoom.
            Vector3 v3StarPos = new Vector3(0, 0, 0);                           // used for storing the psoition of the current star in the system
            float fStarSize = 0.0f;                                             // Size of a star
            double dPlanetOrbitRadius = 0;                                      // used for holding the orbit in Km for a planet.
            Vector3 v3PlanetPos = new Vector3(0, 0, 0);                         // Used to store the planet Pos.
            float fPlanetSize = 0;                                              // used to hold the planets size.
            double dMoonOrbitRadius = 0;                                        // used for holding the orbit in Km for a Moon.
            float fMoonSize = 0;                                                // used to hold the Moons size.
            Vector3 v3MoonPos = Vector3.Zero;                                   // Used to store the Moons Position.

            // start creating star branches in the sceen graph:
            SceenElement oRootStar;
            SceenElement oCurrStar;
            foreach (Pulsar4X.Entities.Star oStar in a_oStarSystem.Stars)
            {

                if (iStarCounter <= 0)
                {
                    // then we have a secondary, etc star give random position around its orbit!
                    oRootStar = new StarElement(oStar, a_oDefaultEffect, Vector3.Zero, Pulsar4X.Constants.StarColor.LookupColor(oStar), true);
                    oCurrStar = oRootStar;
                }
                else
                {
                    Random rnd = new Random();
                    v3StarPos.X = (float)(oStar.Position.X);
                    v3StarPos.Y = (float)(oStar.Position.Y);    
                    MaxOrbitDistTest(ref dMaxOrbitDist, oStar.Orbit.SemiMajorAxis);
                    oCurrStar = new StarElement(oStar, a_oDefaultEffect, v3StarPos, Pulsar4X.Constants.StarColor.LookupColor(oStar), false);
                }


                fStarSize = (float)(oStar.Radius * 2.0 * (Constants.Units.SolarRadiusInAu));

                GLUtilities.GLQuad oStarQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                                                                        v3StarPos,
                                                                        new Vector2(fStarSize, fStarSize),
                                                                        Pulsar4X.Constants.StarColor.LookupColor(oStar),
                                                                        UIConstants.Textures.DEFAULT_PLANET_ICON);
                // create name lable:
                GLUtilities.GLFont oNameLable = new GLUtilities.GLFont(a_oDefaultEffect,
                    new Vector3((float)(v3StarPos.X), (float)(v3StarPos.Y - (oStar.Radius / Constants.Units.KmPerAu)), 0),
                    UIConstants.DEFAULT_TEXT_SIZE, Color.White, UIConstants.Textures.DEFAULT_GLFONT2, oStar.Name);

                oCurrStar.AddPrimitive(oStarQuad); // Add star icon to the Sceen element.
                oCurrStar.Lable = oNameLable;
                oCurrStar.PrimaryPrimitive = oStarQuad;
                oCurrStar.RealSize = new Vector2(fStarSize, fStarSize);
                this.AddElement(oCurrStar);

                // now go though and add each planet to render list.
                foreach (Pulsar4X.Entities.SystemBody oPlanet in oStar.Planets)
                {
                    SceenElement oPlanetElement = new PlanetElement(a_oDefaultEffect, v3StarPos, oPlanet, Color.FromArgb(255, 0, 205, 0));
                    oPlanetElement.EntityID = oPlanet.Id;

                    if (iPlanetCounter == 0)
                    {
                        oCurrStar.SmallestOrbit = (float)(oPlanet.Orbit.SemiMajorAxis * 2);
                    }
                    dPlanetOrbitRadius = oPlanet.Orbit.SemiMajorAxis;

                    fPlanetSize = (float)((oPlanet.Radius * 2.0) / Constants.Units.KmPerAu);
                    MaxOrbitDistTest(ref dMaxOrbitDist, dPlanetOrbitRadius);

                    GLUtilities.GLQuad oPlanetQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                        v3PlanetPos,
                        new Vector2(fPlanetSize, fPlanetSize),
                        Color.FromArgb(255, 0, 255, 0),  // lime green
                        UIConstants.Textures.DEFAULT_PLANET_ICON);

                    // create name lable:
                    GLUtilities.GLFont oPlanetNameLable = new GLUtilities.GLFont(a_oDefaultEffect,
                        new Vector3((float)(v3PlanetPos.X), (float)(v3PlanetPos.Y - (oPlanet.Radius / Constants.Units.KmPerAu)), 0),
                        UIConstants.DEFAULT_TEXT_SIZE, Color.AntiqueWhite, UIConstants.Textures.DEFAULT_GLFONT2, oPlanet.Name);

                    oPlanetElement.AddPrimitive(oPlanetQuad);

                    oPlanetElement.Lable = oPlanetNameLable;
                    oPlanetElement.PrimaryPrimitive = oPlanetQuad;
                    oPlanetElement.RealSize = new Vector2(fPlanetSize, fPlanetSize);
                    oCurrStar.AddChildElement(oPlanetElement);

                    iPlanetCounter++;

                    // now again for the moons:
                    foreach (Pulsar4X.Entities.SystemBody oMoon in oPlanet.Moons)
                    {
                        SceenElement oMoonElement = new PlanetElement(a_oDefaultEffect, v3PlanetPos, oMoon, Color.FromArgb(255, 0, 205, 0));
                        oMoonElement.EntityID = oMoon.Id;

                        if (iMoonCounter == 0)
                        {
                            oPlanetElement.SmallestOrbit = (float)(oMoon.Orbit.SemiMajorAxis);
                        }

                        dMoonOrbitRadius = oMoon.Orbit.SemiMajorAxis;
                        fMoonSize = (float)((oMoon.Radius * 2.0) / Constants.Units.KmPerAu);
                        v3MoonPos = new Vector3((float)(oMoon.Position.X), (float)(oMoon.Position.Y), 0);
                        oMoon.Position.X = oMoon.Position.X + v3PlanetPos.X;
                        oMoon.Position.Y = oMoon.Position.Y + v3PlanetPos.Y;

                        GLUtilities.GLQuad oMoonQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
                            v3MoonPos,                                    // offset Pos by parent planet pos
                            new Vector2(fMoonSize, fMoonSize),
                            Color.FromArgb(255, 0, 205, 0),  // lime green
                            UIConstants.Textures.DEFAULT_PLANET_ICON);

                        GLUtilities.GLFont oMoonNameLable = new GLUtilities.GLFont(a_oDefaultEffect,
                        new Vector3((float)(v3MoonPos.X), (float)(v3MoonPos.Y - (oMoon.Radius / Constants.Units.KmPerAu)), 0),
                        UIConstants.DEFAULT_TEXT_SIZE, Color.AntiqueWhite, UIConstants.Textures.DEFAULT_GLFONT2, oMoon.Name);

                        oMoonElement.AddPrimitive(oMoonQuad);

                        oMoonElement.Lable = oMoonNameLable;
                        oMoonElement.PrimaryPrimitive = oMoonQuad;
                        oMoonElement.RealSize = new Vector2(fMoonSize, fMoonSize);
                        oPlanetElement.AddChildElement(oMoonElement);

                        iMoonCounter++;
                    }
                    iMoonCounter = 0;
                }
                iPlanetCounter = 0;
                foreach (Pulsar4X.Entities.JumpPoint oJumpPoint in a_oStarSystem.JumpPoints)
                {
                    CreateJumpPoint(oCurrStar, oJumpPoint);
                }

                iStarCounter++;
            }

            foreach (Pulsar4X.Entities.SystemContact systemContact in a_oStarSystem.SystemContactList)
            {
                AddContactElement(SceenDefaultEffect, systemContact);
            }

            a_oStarSystem.JumpPoints.ListChanged += JumpPoints_ListChanged;
            a_oStarSystem.SystemContactList.ListChanging += SystemContactList_ListChanging;

            // Set Sceen Size basd on Max Orbit:
            m_v2SceenSize = new Vector2d(dMaxOrbitDist * 2, dMaxOrbitDist * 2);
        }
        public ContactElement(GLEffect a_oDefaultEffect, SystemContact a_oContact)
            : base(a_oContact)
        {
            // Create travel Line element:
            m_oTravelLine = new TravelLine(a_oDefaultEffect, a_oContact.faction.FactionColor);
            this.Children.Add(m_oTravelLine);

            _LastSensorUpdateAck = 0;
            _SensorContactElements = new Dictionary<Guid,SensorElement>();
            _DefaultEffect = a_oDefaultEffect;
        }
Exemple #10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Constructor. </summary>
        /// <param name="a_oEffect"> The shader program. </param>
        /// <param name="a_v3Pos">          The position of the first character. </param>
        /// <param name="a_v2Size">         Size of the first character. </param>
        /// <param name="a_oColor">         The color. </param>
        /// <param name="a_szFontDataFile"> (optional) the font data file. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public GLFont(GLEffect a_oEffect, Vector3 a_v3Pos, Vector2 a_v2Size, System.Drawing.Color a_oColor, string a_szFontDataFile, string a_szText = "")
        {
            // load in data:
            m_oFontData = Helpers.ResourceManager.Instance.LoadGLFont(a_szFontDataFile);

            m_v3Position = a_v3Pos;
            m_v2Size = a_v2Size;
            m_szText = a_szText;

            // Creat some working vars:
            Vector3 v3CharPos = new Vector3();

            // create quads and position them accordingly:
            for (uint i = 0; i < c_uiMaxNumberOfChars; ++i)
            {
                // Create offseted position:
                v3CharPos.X = a_v3Pos.X + i * a_v2Size.X;
                v3CharPos.Y = a_v3Pos.Y;
                // Create Quad and set its texture:
                GLQuad oQuad = new GLQuad(a_oEffect, v3CharPos, a_v2Size, a_oColor);
                oQuad.TextureID = m_oFontData.m_uiTextureID;

                // add quad to the list:
                m_lQuads.Add(oQuad);
            }

            UpdateUVCoords();
        }
Exemple #11
0
 public MapMarker(GLEffect a_oDefaultEffect, System.Drawing.Color MMColor)
 {
 }
Exemple #12
0
        private void InitOpenGL21()
        {
            //this.Context.SwapInterval = 1; // this prevents us using 100% GPU/CPU.
            GraphicsContext.CurrentContext.SwapInterval = 1; // this prevents us using 100% GPU/CPU
            Loaded = true;           // So we know we have a valid Loaded OpenGL context.

            m_eGLError = GL.GetError();
            if (m_eGLError != ErrorCode.NoError)
            {
#if LOG4NET_ENABLED
                logger.Info("OpenGL Pre State Config Error Check: " + m_eGLError.ToString());
#endif
            }
            //GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.ReadBuffer(ReadBufferMode.Back);
            GL.DrawBuffer(DrawBufferMode.Back);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.DepthMask(true);
            GL.Disable(EnableCap.StencilTest);
            GL.StencilMask(0xFFFFFFFF);
            GL.StencilFunc(StencilFunction.Equal, 0x00000000, 0x00000001);
            GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);
            GL.ClearColor(System.Drawing.Color.MidnightBlue);
            GL.ClearDepth(1.0);
            GL.ClearStencil(0);
            GL.Enable(EnableCap.VertexArray);
            m_eGLError = GL.GetError();
            if (m_eGLError != ErrorCode.NoError)
            {
#if LOG4NET_ENABLED
                logger.Info("OpenGL Post State Config Error Check: " + m_eGLError.ToString());
#endif
            }

#if LOG4NET_ENABLED
            logger.Info("UI: GLCanvas2.X Loaded Successfully, Open GL Version: " + GL.GetString(StringName.Version));
            // Log out OpeGL specific stuff if debug build.
            logger.Info("UI: GLSL Version: " + GL.GetString(StringName.ShadingLanguageVersion));
            logger.Info("UI: Renderer: " + GL.GetString(StringName.Renderer));
            logger.Info("UI: Vender: " + GL.GetString(StringName.Vendor));
            logger.Info("UI: Extensions: " + GL.GetString(StringName.Extensions));
#endif
            m_eGLError = GL.GetError();
            if (m_eGLError != ErrorCode.NoError)
            {
#if LOG4NET_ENABLED
                logger.Info("OpenGL Error Check, InvalidEnum or NoError Expected: " + m_eGLError.ToString());
#endif
            }

            m_oEffect = new GLUtilities.GLEffectBasic21("./Resources/Shaders/Basic20_Vertex_Shader.glsl", "./Resources/Shaders/Basic20_Fragment_Shader.glsl");

            // Setup Our View Port, this sets Our Projection and View Matricies.
            SetupViewPort(0, 0, this.Size.Width, this.Size.Height);

            m_oSW.Start();
        }
Exemple #13
0
        /// <summary>   Constructor. </summary>
        /// <param name="a_oEffect"> The Shader program to use when rendering. </param>
        /// <param name="a_v3Pos">          The Position of the circle. </param>
        /// <param name="a_fRadus">         The Radius of the circle. </param>
        /// <param name="a_oColor">         The color of the circle. </param>
        /// <param name="a_szTexture">      (optional) the texture file. </param>
        public GLCircle(GLEffect a_oEffect, Vector3 a_v3Pos, float a_fRadus, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Save some stuff to member vars:
            m_v3Position = a_v3Pos;
            m_v2Size.X   = a_fRadus;

            // calculate the number of verts, min is 90 for a good looking circle, max is 360 for performace reasons.
            int iNumOfVerts = (int)(a_fRadus * MathHelper.PiOver4);

            if (iNumOfVerts < 90)
            {
                iNumOfVerts = 90;
            }
            else if (iNumOfVerts > 360)
            {
                iNumOfVerts = 360;
            }

            // create some working vars:
            double dAngle;
            float  fX, fY;

            //create our Vertex and index arrays:
            m_aoVerticies = new GLVertex[iNumOfVerts];
            m_auiIndicies = new ushort[iNumOfVerts + 1]; // make this one longer so it can loop back around to the begining!!

            for (int i = 0; i < iNumOfVerts; ++i)
            {
                dAngle = i * (MathHelper.TwoPi / iNumOfVerts);
                fX     = (float)Math.Cos(dAngle) * 1;
                fY     = (float)Math.Sin(dAngle) * 1;

                m_aoVerticies[i].m_v4Position.X = fX;
                m_aoVerticies[i].m_v4Position.Y = fY;
                m_aoVerticies[i].m_v4Position.Z = 0;
                m_aoVerticies[i].SetColor(a_oColor);
                m_auiIndicies[i] = (ushort)i;
            }

            // set last index:
            m_auiIndicies[iNumOfVerts] = 0;

            // Setup Matrix:
            m_m4ModelMatrix = Matrix4.CreateScale(a_fRadus * 2) * Matrix4.CreateTranslation(a_v3Pos);

            // Set our shader program:
            m_oEffect = a_oEffect;

            // Load texture if specified:
            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }


            // tell Opgl about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                                                                                                             // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                                          // Lets Open GL know that this is the current active buffer object.
            GL.BufferData <GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                                                                                                  //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle);                                                                        // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //    logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                         // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);                                           // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes);                          // tells OpenGL about the floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //    logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //     logger.Info("OpenGL Create Circle Primitive: " + GL.GetError().ToString());
            //#endif
        }
Exemple #14
0
        public GLCircle(GLEffect a_oEffect, Vector3 a_v3Pos, OrbitingEntity a_oOrbitEntity, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Save some stuff to member vars:
            //double dKMperAUdevby10 = (Pulsar4X.Constants.Units.KM_PER_AU / 10); // we scale everthing down by 10 to avoid float buffer overflows.
            m_v3Position = a_v3Pos;
            m_v2Size.X   = 1;

            // set verts to 360, looks good at any zoom.
            int iNumOfVerts = 360;

            //create our Vertex and index arrays:
            m_aoVerticies = new GLVertex[iNumOfVerts];
            m_auiIndicies = new ushort[iNumOfVerts + 1]; // make this one longer so it can loop back around to the begining!!

            for (int i = 0; i < iNumOfVerts; ++i)
            {
                double dAngle = i * (MathHelper.TwoPi / iNumOfVerts);

                double x, y;
                a_oOrbitEntity.Orbit.GetPosition(dAngle, out x, out y);

                m_aoVerticies[i].m_v4Position.X = (float)x;
                m_aoVerticies[i].m_v4Position.Y = (float)y;
                m_aoVerticies[i].m_v4Position.Z = 0;
                m_aoVerticies[i].SetColor(a_oColor);
                m_auiIndicies[i] = (ushort)i;
            }

            // set last index:
            m_auiIndicies[iNumOfVerts] = 0;

            // Setup Matrix:
            m_m4ModelMatrix = Matrix4.Identity * Matrix4.CreateTranslation(a_v3Pos);

            // Set our shader program:
            m_oEffect = a_oEffect;

            // Load texture if specified:
            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }


            // tell Opgl about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                                                                                                             // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                                          // Lets Open GL know that this is the current active buffer object.
            GL.BufferData <GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                                                                                                  //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle);                                                                        // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //    logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                         // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);                                           // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes);                          // tells OpenGL about the 4 floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //    logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //     logger.Info("OpenGL Create Circle Primitive: " + GL.GetError().ToString());
            //#endif
        }
Exemple #15
0
 public TravelLine(GLEffect a_oDefaultEffect, System.Drawing.Color a_oColor)
     : base()
 {
     m_oPrimaryPrimitive = new GLLine(a_oDefaultEffect, Vector3.Zero, new Vector2(1f, 1f), a_oColor, UIConstants.Textures.DEFAULT_TEXTURE);
     m_lPrimitives.Add(m_oPrimaryPrimitive);
 }
Exemple #16
0
        /// <summary>   Constructor. </summary>
        /// <param name="a_oEffect"> The shader program to use. </param>
        /// <param name="a_v2Pos">          The position of the quad (centre). </param>
        /// <param name="a_v2Size">         Size of the Quad. </param>
        /// <param name="a_oColor">         The color to apply to the quad. </param>
        /// <param name="a_szTexture">      (optional) the texture file. </param>
        public GLLine(GLEffect a_oEffect, Vector3 a_v3Pos, Vector2 a_v2Size, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Setup Member Vars:
            m_oColor        = a_oColor;
            m_v2Size        = a_v2Size;
            m_v3Position    = a_v3Pos;
            m_oEffect       = a_oEffect;
            m_m4ModelMatrix = Matrix4.Identity;
            m_m4ModelMatrix = Matrix4.CreateTranslation(a_v3Pos);
            m_V3PosEnd      = Vector3.Zero;

            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }

            //setup our lines vertcies:
            m_aoVerticies    = new GLVertex[2];
            m_aoVerticies[0] = new GLVertex(new Vector4(0.0f, 0.0f, 0.0f, 1.0f), a_oColor, new Vector2(0.0f, 0.0f));
            m_aoVerticies[1] = new GLVertex(new Vector4(0.0f, 0.0f, 0.0f, 1.0f), a_oColor, new Vector2(1.0f, 1.0f));


            // Setup Draw order. *this apears to have no effect under GL2.X*
            m_auiIndicies    = new ushort[2];
            m_auiIndicies[0] = 0;
            m_auiIndicies[1] = 1;

            // tell OpenGL about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                                                                                                             // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                                          // Lets Open GL know that this is the current active buffer object.
            GL.BufferData <GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                                                                                                  //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle);                                                                        // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //        logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);                                                                         // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);                                           // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes);                          // tells OpenGL about the 4 half floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //        logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //    logger.Info("OpenGL Create Line Primitive: " + GL.GetError().ToString());
            //#endif
        }
Exemple #17
0
        public GLCircle(GLEffect a_oEffect, Vector3 a_v3Pos, OrbitingEntity a_oOrbitEntity, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Save some stuff to member vars:
            //double dKMperAUdevby10 = (Pulsar4X.Constants.Units.KM_PER_AU / 10); // we scale everthing down by 10 to avoid float buffer overflows.
            m_v3Position = a_v3Pos;
            m_v2Size.X = 1;

            // set verts to 360, looks good at any zoom.
            int iNumOfVerts = 360;
            
            //create our Vertex and index arrays:
            m_aoVerticies = new GLVertex[iNumOfVerts];
            m_auiIndicies = new ushort[iNumOfVerts + 1]; // make this one longer so it can loop back around to the begining!!

            for (int i = 0; i < iNumOfVerts; ++i)
            {
                double dAngle = i * (MathHelper.TwoPi / iNumOfVerts);

                double x, y;
                a_oOrbitEntity.Orbit.GetPosition(dAngle, out x, out y);

                m_aoVerticies[i].m_v4Position.X = (float)x;
                m_aoVerticies[i].m_v4Position.Y = (float)y;
                m_aoVerticies[i].m_v4Position.Z = 0;
                m_aoVerticies[i].SetColor(a_oColor);
                m_auiIndicies[i] = (ushort)i;
            }

            // set last index:
            m_auiIndicies[iNumOfVerts] = 0;

            // Setup Matrix:
            m_m4ModelMatrix = Matrix4.Identity * Matrix4.CreateTranslation(a_v3Pos);

            // Set our shader program:
            m_oEffect = a_oEffect;

            // Load texture if specified:
            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }


            // tell Opgl about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                   // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);// Lets Open GL know that this is the current active buffer object.
            GL.BufferData<GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                    //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle); // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //    logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);    // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);  // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes); // tells OpenGL about the 4 floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //    logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //     logger.Info("OpenGL Create Circle Primitive: " + GL.GetError().ToString());
            //#endif
        }
Exemple #18
0
        /// <summary>   Constructor. </summary>
        /// <param name="a_oEffect"> The Shader program to use when rendering. </param>
        /// <param name="a_v3Pos">          The Position of the circle. </param>
        /// <param name="a_fRadus">         The Radius of the circle. </param>
        /// <param name="a_oColor">         The color of the circle. </param>
        /// <param name="a_szTexture">      (optional) the texture file. </param>
        public GLCircle(GLEffect a_oEffect, Vector3 a_v3Pos, float a_fRadus, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Save some stuff to member vars:
            m_v3Position = a_v3Pos;
            m_v2Size.X = a_fRadus;

            // calculate the number of verts, min is 90 for a good looking circle, max is 360 for performace reasons.
            int iNumOfVerts = (int)(a_fRadus * MathHelper.PiOver4);
            if (iNumOfVerts < 90)
            {
                iNumOfVerts = 90;
            }
            else if (iNumOfVerts > 360)
            {
                iNumOfVerts = 360;
            }

            // create some working vars:
            double dAngle;
            float fX, fY;

            //create our Vertex and index arrays:
            m_aoVerticies = new GLVertex[iNumOfVerts];
            m_auiIndicies = new ushort[iNumOfVerts + 1]; // make this one longer so it can loop back around to the begining!!

            for (int i = 0; i < iNumOfVerts; ++i)
            {
                dAngle = i * (MathHelper.TwoPi / iNumOfVerts);
                fX = (float)Math.Cos(dAngle) * 1;
                fY = (float)Math.Sin(dAngle) * 1;

                m_aoVerticies[i].m_v4Position.X = fX;
                m_aoVerticies[i].m_v4Position.Y = fY;
                m_aoVerticies[i].m_v4Position.Z = 0;
                m_aoVerticies[i].SetColor(a_oColor);
                m_auiIndicies[i] = (ushort)i;
            }

            // set last index:
            m_auiIndicies[iNumOfVerts] = 0;

            // Setup Matrix:
            m_m4ModelMatrix = Matrix4.CreateScale(a_fRadus * 2) * Matrix4.CreateTranslation(a_v3Pos);

            // Set our shader program:
            m_oEffect = a_oEffect;

            // Load texture if specified:
            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }


            // tell Opgl about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                   // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);// Lets Open GL know that this is the current active buffer object.
            GL.BufferData<GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                    //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle); // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //    logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);    // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);  // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes); // tells OpenGL about the floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //    logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //     logger.Info("OpenGL Create Circle Primitive: " + GL.GetError().ToString());
            //#endif
        }
        public PlanetElement(GLEffect a_oDefaultEffect, Vector3 a_oPosition, SystemBody a_oPlanet, System.Drawing.Color a_oColor)
            : base(a_oPlanet)
        {
            m_oOrbitCircle = new CircleElement(a_oDefaultEffect, a_oPosition, a_oPlanet, a_oColor);
#warning Cannot add m_oOrbitCircle to children for Planet Element
        }
Exemple #20
0
        private void InitOpenGL21()
        {
            //this.Context.SwapInterval = 1; // this prevents us using 100% GPU/CPU.
            GraphicsContext.CurrentContext.SwapInterval = 1; // this prevents us using 100% GPU/CPU
            Loaded = true;                                   // So we know we have a valid Loaded OpenGL context.

            m_eGLError = GL.GetError();
            if (m_eGLError != ErrorCode.NoError)
            {
#if LOG4NET_ENABLED
                logger.Info("OpenGL Pre State Config Error Check: " + m_eGLError.ToString());
#endif
            }
            //GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.ReadBuffer(ReadBufferMode.Back);
            GL.DrawBuffer(DrawBufferMode.Back);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.DepthMask(true);
            GL.Disable(EnableCap.StencilTest);
            GL.StencilMask(0xFFFFFFFF);
            GL.StencilFunc(StencilFunction.Equal, 0x00000000, 0x00000001);
            GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);
            GL.ClearColor(System.Drawing.Color.MidnightBlue);
            GL.ClearDepth(1.0);
            GL.ClearStencil(0);
            GL.Enable(EnableCap.VertexArray);
            m_eGLError = GL.GetError();
            if (m_eGLError != ErrorCode.NoError)
            {
#if LOG4NET_ENABLED
                logger.Info("OpenGL Post State Config Error Check: " + m_eGLError.ToString());
#endif
            }

#if LOG4NET_ENABLED
            logger.Info("UI: GLCanvas2.X Loaded Successfully, Open GL Version: " + GL.GetString(StringName.Version));
            // Log out OpeGL specific stuff if debug build.
            logger.Info("UI: GLSL Version: " + GL.GetString(StringName.ShadingLanguageVersion));
            logger.Info("UI: Renderer: " + GL.GetString(StringName.Renderer));
            logger.Info("UI: Vender: " + GL.GetString(StringName.Vendor));
            logger.Info("UI: Extensions: " + GL.GetString(StringName.Extensions));
#endif
            m_eGLError = GL.GetError();
            if (m_eGLError != ErrorCode.NoError)
            {
#if LOG4NET_ENABLED
                logger.Info("OpenGL Error Check, InvalidEnum or NoError Expected: " + m_eGLError.ToString());
#endif
            }

            m_oEffect = new GLUtilities.GLEffectBasic21("./Resources/Shaders/Basic20_Vertex_Shader.glsl", "./Resources/Shaders/Basic20_Fragment_Shader.glsl");

            // Setup Our View Port, this sets Our Projection and View Matricies.
            SetupViewPort(0, 0, this.Size.Width, this.Size.Height);

            m_oSW.Start();
        }
Exemple #21
0
        /// <summary>   Constructor. </summary>
        /// <param name="a_oEffect"> The shader program to use. </param>
        /// <param name="a_v2Pos">          The position of the quad (centre). </param>
        /// <param name="a_v2Size">         Size of the Quad. </param>
        /// <param name="a_oColor">         The color to apply to the quad. </param>
        /// <param name="a_szTexture">      (optional) the texture file. </param>
        public GLLine(GLEffect a_oEffect, Vector3 a_v3Pos, Vector2 a_v2Size, System.Drawing.Color a_oColor, string a_szTexture = "")
            : base()
        {
            // Setup Member Vars:
            m_oColor = a_oColor;
            m_v2Size = a_v2Size;
            m_v3Position = a_v3Pos;
            m_oEffect = a_oEffect;
            m_m4ModelMatrix = Matrix4.Identity;
            m_m4ModelMatrix = Matrix4.CreateTranslation(a_v3Pos);
            m_V3PosEnd = Vector3.Zero;

            if (a_szTexture != "")
            {
                // We can assuem we have been provided with a texture to load:
                m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(a_szTexture);
            }
            else
            {
                m_uiTextureID = 0; // set texture to none!
            }

            //setup our lines vertcies:
            m_aoVerticies = new GLVertex[2];
            m_aoVerticies[0] = new GLVertex(new Vector4(0.0f, 0.0f, 0.0f, 1.0f), a_oColor, new Vector2(0.0f, 0.0f));
            m_aoVerticies[1] = new GLVertex(new Vector4(0.0f, 0.0f, 0.0f, 1.0f), a_oColor, new Vector2(1.0f, 1.0f));


            // Setup Draw order. *this apears to have no effect under GL2.X*
            m_auiIndicies = new ushort[2];
            m_auiIndicies[0] = 0;
            m_auiIndicies[1] = 1;

            // tell OpenGL about our VBOs:
            GL.GenVertexArrays(1, out m_uiVextexArrayHandle);               // Generate Our Vertex Array and get the handle to it.
            GL.BindVertexArray(m_uiVextexArrayHandle);                      // Lets OpenGL that this is the current "active" vertex array.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VAO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiVertexBufferHandle);                   // Generate our Vertex Buffer Object and get the handle to it.
            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);// Lets Open GL know that this is the current active buffer object.
            GL.BufferData<GLVertex>(BufferTarget.ArrayBuffer, new IntPtr(m_aoVerticies.Length * GLVertex.SizeInBytes()), m_aoVerticies, BufferUsageHint.StaticDraw); // tells OpenGL about the structure of the data.
            //#if DEBUG
            //    logger.Info("OpenGL Generate VBO: " + GL.GetError().ToString());
            //#endif

            GL.GenBuffers(1, out m_uiIndexBufferHandle);                    //Generate Our index Buffer and get handle to it.
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, m_uiIndexBufferHandle); // Lets Open GL know that this is the current active buffer object.
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(m_auiIndicies.Length * sizeof(ushort)), m_auiIndicies, BufferUsageHint.StaticDraw); // Tells OpenGL how the data is structured.
            //#if DEBUG
            //        logger.Info("OpenGL Generate EBO: " + GL.GetError().ToString());
            //#endif

            GL.BindBuffer(BufferTarget.ArrayBuffer, m_uiVertexBufferHandle);    // Switch back to our Buffer Object as the current buffer.
            GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), 0);  // Tells OpenGL about the first three doubles in the vbo, i.e the position of the vertex.
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, true, GLVertex.SizeInBytes(), Vector4.SizeInBytes); // tells OpenGL about the 4 half floats used to repesent color.
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, GLVertex.SizeInBytes(), (Vector4.SizeInBytes + Vector4.SizeInBytes)); // tells OpenGL about the 2 floats in the vertgexc used to repesent UV coords.
            //#if DEBUG
            //        logger.Info("OpenGL Create Vertes Attribute Pointers: " + GL.GetError().ToString());
            //#endif

            // Turn on the Vertex Attribs:
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            // #if DEBUG
            //    logger.Info("OpenGL Create Line Primitive: " + GL.GetError().ToString());
            //#endif
        }
 public ContactElement()
     : base()
 {
     _LastSensorUpdateAck = 0;
     _SensorContactElements = new Dictionary<Guid,SensorElement>();
     _DefaultEffect = null;
 }