Пример #1
0
        public void Draw(Matrix4 transform, oGeometry geometry, int texture, int pgmID)
        {
            //Makes sure that the correct shader is bound for current entity
            if (currentShader != pgmID)
            {
                BindShader(pgmID);
                currentShader = pgmID;
            }
            else
            {
                GL.UseProgram(currentShader);
            }

            GL.Uniform1(uniform_stex, 0);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Viewport(clientRectangle);

            //Calculates and passes world view projection matrix to the shader
            Matrix4 worldViewProjection = transform * camera.View * camera.Projection;

            GL.UniformMatrix4(uniform_mview, false, ref worldViewProjection);

            //Renders entity
            geometry.Render();

            //Clears the vertex array and shader program
            GL.BindVertexArray(0);
            GL.UseProgram(0);
        }
Пример #2
0
        public static oGeometry LoadGeometry(string filename)
        {
            oGeometry geometry;

            geometryDictionary.TryGetValue(filename, out geometry);
            if (geometry == null)
            {
                geometry = new oGeometry();
                geometry.LoadObject(filename);
                geometryDictionary.Add(filename, geometry);
            }

            return(geometry);
        }
Пример #3
0
        public void OnAction()
        {
            foreach (oEntity entity in entityList)
            {
                //Retrieves list of components from current entity
                List <IComponent> components = entity.Components;

                //Retrieves geometry component from current entity
                IComponent geometryComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentMask == ComponentMasks.COMPONENT_GEOMETRY);
                });
                oGeometry geometry = ((cGeometry)geometryComponent).Geometry();

                //Retrieves transform component from current entity
                IComponent transformComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentMask == ComponentMasks.COMPONENT_TRANSFORM);
                });

                //Sets transform if not already set, and retrieves transform value
                if (((cTransform)transformComponent).SetTransform == false)
                {
                    SetTransform((cTransform)transformComponent);
                    ((cTransform)transformComponent).SetTransform = true;
                }
                Matrix4 transform = ((cTransform)transformComponent).Transform;

                //Retrieves texture component from current entity
                IComponent textureComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentMask == ComponentMasks.COMPONENT_TEXTURE);
                });
                int texture = ((cTexture)textureComponent).Texture;

                //Retrieves shader component from current entity
                IComponent shaderComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentMask == ComponentMasks.COMPONENT_SHADER);
                });
                int pgmID = ((cShader)shaderComponent).PgmID;

                Draw(transform, geometry, texture, pgmID);
            }
        }
Пример #4
0
 public cGeometry(string geometryName)
 {
     this.geometry = mResource.LoadGeometry(geometryName);
 }