예제 #1
0
 private void OnLoad(object sender, EventArgs e)
 {
     // initialize shader
     _program = ProgramFactory.Create<SkyboxProgram>();
     // initialize cube shape
     _cube = new Cube();
     _cube.UpdateBuffers();
     // initialize vertex array and attributes
     _vao = new VertexArray();
     _vao.Bind();
     _vao.BindAttribute(_program.InPosition, _cube.VertexBuffer);
     _vao.BindElementBuffer(_cube.IndexBuffer);
     // create cubemap texture and load all faces
     for (var i = 0; i < 6; i++)
     {
         using (var bitmap = new Bitmap(string.Format("Data/Textures/city{0}.jpg", i)))
         {
             bitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
             if (_skybox == null) BitmapTexture.CreateCompatible(bitmap, out _skybox, 1);
             _skybox.LoadBitmap(bitmap, i);
         }
     }
     // activate shader and bind texture to it
     _program.Use();
     _program.Texture.BindTexture(TextureUnit.Texture0, _skybox);
     // enable seamless filtering to reduce artifacts at the edges of the cube faces
     GL.Enable(EnableCap.TextureCubeMapSeamless);
     // cull front faces because we are inside the cube
     // this is not really necessary but removes some artifacts when the user leaves the cube
     // which should be impossible for a real skybox, but in this demonstration it is possible by zooming out
     GL.Enable(EnableCap.CullFace);
     GL.CullFace(CullFaceMode.Front);
     // set a nice clear color
     GL.ClearColor(Color.MidnightBlue);
 }
예제 #2
0
        public ColorCube()
        {
            DefaultMode = PrimitiveType.Triangles;

            // use default cube
            using (var cube = new Cube())
            {
                Vertices = cube.Vertices;
                Indices = cube.Indices;
            }

            // add color to the vertices
            Colors = new List<Color>
            {
                Color.DarkRed,
                Color.DarkRed,
                Color.Gold,
                Color.Gold,
                Color.DarkRed,
                Color.DarkRed,
                Color.Gold,
                Color.Gold
            }.Select(_ => _.ToRgba32()).ToArray();
        }