public SpriteBatch(OpenGL gl, int triCount = 4000)
        {
            this.gl = gl;

            var textureLoaded = this.white1x1Tex.Create(gl, Properties.Resources.white1x1);

            if (textureLoaded == false)
            {
                throw new Exception("white1x1Tex loading failed");
            }

            _shaderProgram.Create(gl, Properties.Resources.SimpleVS, Properties.Resources.SimplePS, null);

            _shaderProgram.BindAttributeLocation(gl, VertexAttributes.Pos, nameof(VertexAttributes.Pos));
            _shaderProgram.BindAttributeLocation(gl, VertexAttributes.Color, nameof(VertexAttributes.Color));
            _shaderProgram.BindAttributeLocation(gl, VertexAttributes.TexCoord, nameof(VertexAttributes.TexCoord));

            _shaderProgram.Bind(gl);

            vertices = new VertexPosTexColor[triCount * 3];
            indices  = new int[triCount * 3];

            gl.GenBuffers(1, vertexBufferIds);
            gl.BindBuffer(GL_ARRAY_BUFFER, vertexBufferIds[0]);
            gl.BufferData(GL_ARRAY_BUFFER, vertices.Length * VertexPosTexColor.SizeOf, IntPtr.Zero, GL_DYNAMIC_DRAW);

            gl.GenBuffers(1, indexBufferIds);
            gl.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferIds[0]);
            gl.BufferData(GL_ELEMENT_ARRAY_BUFFER, indices.Length * sizeof(int), IntPtr.Zero, GL_DYNAMIC_DRAW);

            gl.GenVertexArrays(1, vaos);
            gl.BindVertexArray(vaos[0]);

            gl.EnableVertexAttribArray(VertexAttributes.Pos);
            gl.VertexAttribPointer(VertexAttributes.Pos, 3, GL_FLOAT, false, VertexPosTexColor.SizeOf, new IntPtr(0));

            gl.EnableVertexAttribArray(VertexAttributes.Color);
            gl.VertexAttribPointer(VertexAttributes.Color, 4, GL_UNSIGNED_BYTE, true, VertexPosTexColor.SizeOf, new IntPtr(3 * sizeof(float)));

            gl.EnableVertexAttribArray(VertexAttributes.TexCoord);
            gl.VertexAttribPointer(VertexAttributes.TexCoord, 2, GL_FLOAT, false, VertexPosTexColor.SizeOf, new IntPtr(3 * sizeof(float) + 4 * sizeof(byte)));
        }
Esempio n. 2
0
 public void Bind()
 {
     shader.Bind(gl);
 }