Exemplo n.º 1
0
 public SpriteRenderer(Shader shader)
 {
     this.shader = shader;
     this.initRenderData();
 }
Exemplo n.º 2
0
        public void Init()
        {
            //Initialize game timer
            this.gameTime = new GameTime();

            //OpenGL Config
            GL.ClearColor(Color.Black);
            //GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

            //Initialize our game state
            this.activeState = GameStates.Active;

            //Load Shaders
            Shader shader = new Shader(@"Shaders/vertex.glsl", @"Shaders/fragment.glsl");

            //Configure Shaders
            Matrix4 projection = Matrix4.CreateOrthographic(gameWindow.Width, gameWindow.Height, -1.0f, 1.0f) * Matrix4.CreateTranslation(-1f, -1f, 0f) * Matrix4.CreateScale(1f, -1f, 1f);

            shader.Use();
            shader.SetInteger("image", 0);
            shader.SetMatrix4("proj", projection);

            this.renderer = new SpriteRenderer(shader);

            //Init Game Logic
            this.gameLevels = new List<GameLevel>();
            this.gameLevels.Add(new GameLevel(@"Levels/level_01.level"));
            this.currentLevelIndex = 0;

            Texture2D playerTexture = new Texture2D(@"Textures/paddle.png");
            Vector2 playerSize = new Vector2(100, 20);
            Vector2 playerPos = new Vector2(gameWindow.Width / 2 - playerSize.X / 2, gameWindow.Height - playerSize.Y);

            //Player
            this.player = new GameObject(playerPos, playerSize, playerTexture, Color.White, Vector2.Zero);

            //Ball
            float ballRadius = 12.5f;
            this.ball = new BallObject(
                new Vector2(player.Position.X + (playerSize.X / 2 - ballRadius), player.Position.Y - ballRadius * 2f - 1),
                ballRadius, new Vector2(RNG.NextFloat(-250.0f, 250.0f), -350f), new Texture2D(@"Textures/ball.png"));
        }