상속: IDeletable
예제 #1
0
파일: Mesh.cs 프로젝트: LukaHorvat/Electric
        public Mesh(MeshData data)
        {
            Camera3D.CameraChanged += UpdateShaderMatrix;
            children = new LinkedList<Mesh>();

            Data = data;

            vertexShader = new VertexShader();
            vertexShader.LoadFromSource(vertexShaderSource);
            fragmentShader = new FragmentShader();
            fragmentShader.LoadFromSource(fragmentShaderSource);

            shaderProgram = new ShaderProgram(vertexShader, fragmentShader);
            shaderProgram.Link();
            shaderProgram.Use();

            shaderProgram.AddAttribLocation("position");
            shaderProgram.AddAttribLocation("color");
            shaderProgram.AddAttribLocation("normal");
            shaderProgram.AddUniformLocation("matrix");
            shaderProgram.AddUniformLocation("rotation");

            rotation = Matrix4.Identity;
            scale = Matrix4.Identity;
            translation = Matrix4.Identity;
            projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 2.5F, 1, 0.1F, 100F);
            shaderModelMatrix = Matrix4.Identity;
            shaderRotationMatrix = Matrix4.Identity;

            window = Matrix4.Scale(Firefly.Window.Height / (float)Firefly.Window.Width, 1, 1);

            UpdateShaderMatrix();
        }
예제 #2
0
 public Uniform(string identifier, ShaderProgram program)
 {
     this.identifier = identifier;
     this.location = GL.GetUniformLocation(program.Id, identifier);
 }
예제 #3
0
        public static void Initialize( int Width, int Height, string Title, OnLoadHandler LoadHandler, bool UseOGL3 = false )
        {
            window = new Window( Width, Height, Title, LoadHandler, UseOGL3 );

            defaultTextureVertexShader = new VertexShader();
            defaultTextureVertexShader.LoadFromFile( @"shaders\defTextureVert.vert.c" );
            defaultTexturedFragmentShader = new FragmentShader();
            defaultTexturedFragmentShader.LoadFromFile( @"shaders\defTextureFrag.frag.c" );
            defaultShapeVertexShader = new VertexShader();
            defaultShapeVertexShader.LoadFromFile( @"shaders\defShapeVert.vert.c" );
            defaultShapeFragmentShader = new FragmentShader();
            defaultShapeFragmentShader.LoadFromFile( @"shaders\defShapeFrag.frag.c" );

            defaultShapeProgram = new ShaderProgram( defaultShapeVertexShader, defaultShapeFragmentShader );
            defaultShapeProgram.Link();
            defaultShapeProgram.AddUniformLocation( "window_matrix" );
            defaultShapeProgram.AddUniformLocation( "model_matrix" );
            defaultShapeProgram.AddUniformLocation( "projection_matrix" );
            defaultShapeProgram.AddUniformLocation( "camera_matrix" );
            defaultShapeProgram.AddAttribLocation( "vertex_coord" );
            defaultShapeProgram.AddAttribLocation( "vertex_color" );

            defaultTextureProgram = new ShaderProgram( defaultTextureVertexShader, defaultTexturedFragmentShader );
            defaultTextureProgram.Link();
            defaultTextureProgram.AddUniformLocation( "window_matrix" );
            defaultTextureProgram.AddUniformLocation( "model_matrix" );
            defaultTextureProgram.AddUniformLocation( "projection_matrix" );
            defaultTextureProgram.AddUniformLocation( "camera_matrix" );
            defaultTextureProgram.AddUniformLocation( "texture" );
            defaultTextureProgram.AddAttribLocation( "vertex_coord" );
            defaultTextureProgram.AddAttribLocation( "vertex_texcoord" );

            windowMatrix = Matrix4.Identity;
            projectionMatrix = new Matrix4( new Vector4( 2F / window.Width, 0, 0, 0 ),
                new Vector4( 0, -2F / window.Height, 0, 0 ),
                new Vector4( 0, 0, 1, 0 ),
                new Vector4( 0, 0, 0, 1 ) ) * Matrix4.CreateTranslation( -1, 1, 0 );

            Camera newCam = new Camera();
            newCam.Activate();

            renderList = new LinkedList<IRenderable>();
            updateList = new LinkedList<IUpdatable>();
            renderRemoveList = new LinkedList<IRenderable>();
            updateRemoveList = new LinkedList<IUpdatable>();

            Utility.ProcessOGLErrors();

            window.GameWindow.Load += new EventHandler<EventArgs>( mainLoop );
            window.GameWindow.Run();
        }
예제 #4
0
 public Attribute(string identifier, ShaderProgram program)
 {
     this.identifier = identifier;
     location = GL.GetAttribLocation(program.Id, identifier);
 }
예제 #5
0
        public static Stage Initialize(int width, int height, string title, OnLoadHandler loadHandler,
									  bool useLatestAvailable = false)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            window = new Window(width, height, title, useLatestAvailable);

            Title = title;

            if (useLatestAvailable)
            {
                Console.WriteLine(@"Using latest available version: " + LatestAvailableVersion / 10F);
            }
            else
            {
                Console.WriteLine(@"Using OpenGL 2.0, latest version available on the system is: " + LatestAvailableVersion / 10F);
            }

            if (useLatestAvailable && LatestAvailableVersion >= 40)
            {
                defaultTextureVertexShader = new VertexShader();
                defaultTextureVertexShader.LoadFromSource(DefaultShaders.OGL4TexturedVert);
                defaultTexturedFragmentShader = new FragmentShader();
                defaultTexturedFragmentShader.LoadFromSource(DefaultShaders.OGL4TexturedFrag);
                defaultShapeVertexShader = new VertexShader();
                defaultShapeVertexShader.LoadFromSource(DefaultShaders.OGL4ShapeVert);
                defaultShapeFragmentShader = new FragmentShader();
                defaultShapeFragmentShader.LoadFromSource(DefaultShaders.OGL4ShapeFrag);
            }
            else
            {
                defaultTextureVertexShader = new VertexShader();
                defaultTextureVertexShader.LoadFromSource(DefaultShaders.TexturedVert);
                defaultTexturedFragmentShader = new FragmentShader();
                defaultTexturedFragmentShader.LoadFromSource(DefaultShaders.TexturedFrag);
                defaultShapeVertexShader = new VertexShader();
                defaultShapeVertexShader.LoadFromSource(DefaultShaders.ShapeVert);
                defaultShapeFragmentShader = new FragmentShader();
                defaultShapeFragmentShader.LoadFromSource(DefaultShaders.ShapeFrag);
            }

            DefaultShapeProgram = new ShaderProgram(defaultShapeVertexShader, defaultShapeFragmentShader);
            DefaultShapeProgram.Link();
            DefaultShapeProgram.AddUniformLocation("window_matrix");
            DefaultShapeProgram.AddUniformLocation("model_matrix");
            DefaultShapeProgram.AddUniformLocation("projection_matrix");
            DefaultShapeProgram.AddUniformLocation("camera_matrix");
            DefaultShapeProgram.AddUniformLocation("alpha");
            DefaultShapeProgram.AddUniformLocation("tintR");
            DefaultShapeProgram.AddUniformLocation("tintG");
            DefaultShapeProgram.AddUniformLocation("tintB");
            DefaultShapeProgram.AddUniformLocation("tintA");
            DefaultShapeProgram.AddAttribLocation("vertex_coord");
            DefaultShapeProgram.AddAttribLocation("vertex_color");

            DefaultTextureProgram = new ShaderProgram(defaultTextureVertexShader, defaultTexturedFragmentShader);
            DefaultTextureProgram.Link();
            DefaultTextureProgram.AddUniformLocation("window_matrix");
            DefaultTextureProgram.AddUniformLocation("model_matrix");
            DefaultTextureProgram.AddUniformLocation("projection_matrix");
            DefaultTextureProgram.AddUniformLocation("camera_matrix");
            DefaultTextureProgram.AddUniformLocation("texture");
            DefaultTextureProgram.AddUniformLocation("alpha");
            DefaultTextureProgram.AddUniformLocation("tintR");
            DefaultTextureProgram.AddUniformLocation("tintG");
            DefaultTextureProgram.AddUniformLocation("tintB");
            DefaultTextureProgram.AddUniformLocation("tintA");
            DefaultTextureProgram.AddAttribLocation("vertex_coord");
            DefaultTextureProgram.AddAttribLocation("vertex_texcoord");

            if (LatestAvailableVersion >= 40 && useLatestAvailable)
            {
                GL.BindFragDataLocation(DefaultShapeProgram.Id, 0, "FragColor");
                GL.BindFragDataLocation(DefaultTextureProgram.Id, 0, "FragColor");
            }

            WindowMatrix = Matrix4.Identity;
            ProjectionMatrix = new Matrix4(new Vector4(2F / window.Width, 0, 0, 0),
                                           new Vector4(0, -2F / window.Height, 0, 0),
                                           new Vector4(0, 0, 1, 0),
                                           new Vector4(0, 0, 0, 1)) * Matrix4.CreateTranslation(-1, 1, 0);

            var newCam = new Camera();
            newCam.Activate();

            renderList = new LinkedList<IRenderable>();
            updateList = new LinkedList<IUpdatable>();
            renderRemoveList = new LinkedList<IRenderable>();
            updateRemoveList = new LinkedList<IUpdatable>();

            Utility.Utility.ProcessOGLErrors();

            CreatePrimitives();

            ChangeViewPort(window.Width, window.Height);
            Camera.CurrentCamera.X = ViewportWidth / 2;
            Camera.CurrentCamera.Y = ViewportHeight / 2;

            var stage = new Stage();
            AddEntity(stage);
            window.GameWindow.Load += ((x, y) => loadHandler(stage));
            window.GameWindow.Load += MainLoop;

            window.GameWindow.Run();

            return stage;
        }