Exemple #1
0
        public Model(ObjFile objModel, int groupNum, ShaderProgram program)
        {
            var group = objModel.Groups[groupNum];
            var tempPos = new List<Vector3> ();
            var tempTex = new List<Vector2> ();
            foreach (ObjFace f in group.Faces) {
                foreach (ObjFaceVertex vert in f.Vertices) {
                    tempPos.Add (objModel.Vertices[vert.VertexIndex - 1]);
                    tempTex.Add (objModel.Textures[vert.TextureIndex - 1]);
                }
            }
            var v_pos = new GLBuffer<Vector3> (GLBufferSettings.StaticDraw3FloatArray, tempPos);
            var v_tex = new GLBuffer<Vector2> (GLBufferSettings.StaticDraw2FloatArray, tempTex);
            var m_ind = new GLBuffer<uint> (GLBufferSettings.StaticIndices, Array.ConvertAll<int, uint> (Enumerable.Range (0, tempPos.Count).ToArray (), x => (uint) x));
            Geometry = new Geometry (BeginMode.Quads)
                .AddBuffer ("v_pos", v_pos)
                .AddBuffer ("v_tex", v_tex);

            Position = Vector3.Zero;
            Scale = Vector3.One;
            Rotation = Vector3.Zero;
        }
Exemple #2
0
        protected override void Initialize()
        {
            texture = Content.Load<Texture2D> ("particles_test.png", TextureConfiguration.Nearest);

            program = Content.Load<ShaderProgram> ("particle");

            positions = new GLBuffer<Vector4> (GLBufferSettings.StaticDraw4FloatArray, pos);
            texCoords = new GLBuffer<Vector2> (GLBufferSettings.StaticDraw2FloatArray, textureCoords);
            colors = new GLBuffer<Vector4> (GLBufferSettings.StaticDraw4FloatArray, col);

            abo = GL.GenVertexArray ();
            GL.BindVertexArray (abo);
            positions.PointTo (program.Attrib ("v_pos"));
            texCoords.PointTo (program.Attrib ("v_tex"));
            colors.PointTo (program.Attrib ("v_col"));

            camera = new Camera (60f, Resolution, 0.1f, 64f);

            camera.SetRelativePosition (new Vector3 (0, 0, 5));

            base.Initialize ();
        }
Exemple #3
0
 public void DrawRaw(ShaderProgram program, Matrix4 MVP)
 {
     Geometry.DrawRaw (program, MVP);
 }
Exemple #4
0
 /// <summary>
 /// Draw the specified program and camera.
 /// </summary>
 /// <param name="program">Program.</param>
 /// <param name="camera">Camera.</param>
 public void Draw(ShaderProgram program, Matrix4 VP)
 {
     // Draw the geometry
     Geometry.Draw (program, Matrix, VP);
 }
Exemple #5
0
 /// <summary>
 /// Draw the specified program and camera.
 /// </summary>
 /// <param name="program">Program.</param>
 /// <param name="camera">Camera.</param>
 public void Draw(ShaderProgram program, Camera camera)
 {
     // Draw the geometry
     Geometry.Draw (program, Matrix, camera);
 }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="nginz.SpriteBatch"/> class.
        /// </summary>
        /// <param name = "game">The game.</param>
        /// <param name="shader">Shader.</param>
        public SpriteBatch(Game game, ShaderProgram shader = null)
        {
            // Set the game
            Game = game;

            // Compile predefined shaders if no shader program is given
            if (shader == null) {
                var vertShader = new VertexShader (vert_source);
                var fragShader = new FragmentShader (frag_source);
                Program = new ShaderProgram (vertShader, fragShader);
                Program.Link ();
            } else
                Program = shader;

            // Create the optimal buffer settings
            var settings = new GLBufferSettings {
                AttribSize = 0,
                Hint = BufferUsageHint.DynamicDraw,
                Normalized = false,
                Offset = 0,
                Target = BufferTarget.ArrayBuffer,
                Type = VertexAttribPointerType.Float
            };

            // Create temp variables for indices
            int indPtr = 0;
            var tempIndices = new uint[MAX_INDICES];

            // Fill temporary indices
            for (uint i = 0; i < MAX_VERTICES; i += 4) {

                // Triangle 1
                tempIndices [indPtr++] = i;
                tempIndices [indPtr++] = i + 1;
                tempIndices [indPtr++] = i + 2;

                // Triangle 2
                tempIndices [indPtr++] = i + 1;
                tempIndices [indPtr++] = i + 3;
                tempIndices [indPtr++] = i + 2;
            }

            // Set camera
            InternalCamera = new Camera (60f, game.Resolution, 0, 16, type: ProjectionType.Orthographic);

            // Set current texture
            CurrentTexture = Texture2D.Dot;

            // Generate array buffer object
            abo = GL.GenVertexArray ();

            // Create vertex buffer object
            vbo = new GLBufferDynamic<Vertex2D> (settings, Vertex2D.Size, MAX_VERTICES);

            // Create index buffer object
            ibo = new GLBuffer<uint> (GLBufferSettings.DynamicIndices, tempIndices);

            // Initialize vertices
            Vertices = new Vertex2D[MAX_VERTICES];

            framebuffer = new Framebuffer (FramebufferTarget.Framebuffer, Game.Resolution.Width, game.Resolution.Height)
                            .AttachTexture (FboAttachment.DiffuseAttachment, DrawBuffersEnum.ColorAttachment0, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="nginz.SpriteBatch"/> class.
        /// </summary>
        /// <param name = "game">The game.</param>
        /// <param name="shader">Shader.</param>
        public SpriteBatch(Game game, ShaderProgram shader = null)
        {
            // Set the game
            Game = game;

            // Compile predefined shaders if no shader program is given
            if (shader == null)
            {
                var vertShader = new VertexShader(vert_source);
                var fragShader = new FragmentShader(frag_source);
                Program = new ShaderProgram(vertShader, fragShader);
                Program.Link();
            }
            else
            {
                Program = shader;
            }

            // Create the optimal buffer settings
            var settings = new GLBufferSettings {
                AttribSize = 0,
                Hint       = BufferUsageHint.DynamicDraw,
                Normalized = false,
                Offset     = 0,
                Target     = BufferTarget.ArrayBuffer,
                Type       = VertexAttribPointerType.Float
            };

            // Create temp variables for indices
            int indPtr      = 0;
            var tempIndices = new uint[MAX_INDICES];

            // Fill temporary indices
            for (uint i = 0; i < MAX_VERTICES; i += 4)
            {
                // Triangle 1
                tempIndices [indPtr++] = i;
                tempIndices [indPtr++] = i + 1;
                tempIndices [indPtr++] = i + 2;

                // Triangle 2
                tempIndices [indPtr++] = i + 1;
                tempIndices [indPtr++] = i + 3;
                tempIndices [indPtr++] = i + 2;
            }

            // Set camera
            InternalCamera = new Camera(60f, game.Resolution, 0, 16, type: ProjectionType.Orthographic);

            // Set current texture
            CurrentTexture = Texture2D.Dot;

            // Generate array buffer object
            abo = GL.GenVertexArray();

            // Create vertex buffer object
            vbo = new GLBufferDynamic <Vertex2D> (settings, Vertex2D.Size, MAX_VERTICES);

            // Create index buffer object
            ibo = new GLBuffer <uint> (GLBufferSettings.DynamicIndices, tempIndices);

            // Initialize vertices
            Vertices = new Vertex2D[MAX_VERTICES];

            framebuffer = new Framebuffer(FramebufferTarget.Framebuffer, Game.Resolution.Width, game.Resolution.Height)
                          .AttachTexture(FboAttachment.DiffuseAttachment, DrawBuffersEnum.ColorAttachment0, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte, InterpolationMode.Linear);
        }