Пример #1
0
        public void Draw(uint shader, Transform transform, Camera camera, Projection projection, Lighting lighting)
        {
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vbo);
            Gl.glBufferData(Gl.GL_ARRAY_BUFFER, (IntPtr)(vertices.Length * sizeof(float)), vertices, Gl.GL_STATIC_DRAW);

            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 3 * sizeof(float), new IntPtr(0));
            Gl.glEnableVertexAttribArray(0);

            Gl.glUseProgram(shader);

            transform.Setup(shader);
            camera.Setup(shader);
            projection.Setup(shader);

            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, vertices.Length / 3);
        }
Пример #2
0
        public void Draw(uint shader, Transform transform, Camera camera, Projection projection, Lighting lighting)
        {
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vbo);
            Gl.glBufferData(Gl.GL_ARRAY_BUFFER, (IntPtr)(vertices.Length * sizeof(float)), vertices, Gl.GL_STATIC_DRAW);

            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), new IntPtr(0));
            Gl.glEnableVertexAttribArray(0);

            Gl.glVertexAttribPointer(1, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), new IntPtr(3 * sizeof(float)));
            Gl.glEnableVertexAttribArray(1);

            Gl.glVertexAttribPointer(2, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), new IntPtr(5 * sizeof(float)));
            Gl.glEnableVertexAttribArray(2);

            Gl.glUseProgram(shader);

            Gl.glActiveTexture(Gl.GL_TEXTURE0);
            int textureDiffuseLoc = Gl.glGetUniformLocation(shader, "material.textureDiffuse1");

            Gl.glUniform1i(textureDiffuseLoc, 0);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, DiffuseMap);

            Gl.glActiveTexture(Gl.GL_TEXTURE1);
            int textureSpecularLoc = Gl.glGetUniformLocation(shader, "material.textureSpecular1");

            Gl.glUniform1i(textureSpecularLoc, 1);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, SpecularMap);

            Gl.glActiveTexture(Gl.GL_TEXTURE0);

            int shininessLoc = Gl.glGetUniformLocation(shader, "material.shininess");

            Gl.glUniform1f(shininessLoc, 32f);

            lighting.Setup(shader);
            transform.Setup(shader);
            camera.Setup(shader);
            projection.Setup(shader);

            Gl.glDrawArrays(Gl.GL_QUADS, 0, vertices.Length / 8);
        }
Пример #3
0
        public void Draw(uint shader, Transform transform, Camera camera, Projection projection, Lighting lighting)
        {
            uint diffuseNumber  = 1;
            uint specularNumber = 1;

            if (Textures.Count == 0)
            {
                Gl.glActiveTexture(Gl.GL_TEXTURE0);
                int textureLoc = Gl.glGetUniformLocation(shader, "material.textureDiffuse1");
                Gl.glUniform1i(textureLoc, 0);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, CustomTexture);
            }

            for (int i = 0; i < Textures.Count; ++i)
            {
                Gl.glActiveTexture(Gl.GL_TEXTURE0 + i);
                string name = "texture" + Textures[i].Type.ToString();
                if (Textures[i].Type == Texture.TextureType.Diffuse)
                {
                    name += diffuseNumber.ToString();
                    ++diffuseNumber;
                }
                else
                {
                    name += specularNumber.ToString();
                    ++specularNumber;
                }

                int textureLoc = Gl.glGetUniformLocation(shader, "material." + name.ToString());
                Gl.glUniform1i(textureLoc, i);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, Textures[i].Id);
            }

            Gl.glUseProgram(shader);
            Gl.glActiveTexture(Gl.GL_TEXTURE0);

            Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, ebo);
            Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER, (IntPtr)(Indices.Count * sizeof(float)), Indices.ToArray(), Gl.GL_STATIC_DRAW);

            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vbo);
            var buf = GetVertices();

            Gl.glBufferData(Gl.GL_ARRAY_BUFFER, (IntPtr)(buf.Length * sizeof(float)), GetVertices(), Gl.GL_STATIC_DRAW);

            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), new IntPtr(0));
            Gl.glEnableVertexAttribArray(0);

            Gl.glVertexAttribPointer(1, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), new IntPtr(3 * sizeof(float)));
            Gl.glEnableVertexAttribArray(1);

            Gl.glVertexAttribPointer(2, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), new IntPtr(5 * sizeof(float)));
            Gl.glEnableVertexAttribArray(2);

            int shininessLoc = Gl.glGetUniformLocation(shader, "material.shininess");

            Gl.glUniform1f(shininessLoc, 32.0f);

            lighting.Setup(shader);
            transform.Setup(shader);
            camera.Setup(shader);
            projection.Setup(shader);

            Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, ebo);
            Gl.glDrawElements(Gl.GL_TRIANGLES, Indices.Count, Gl.GL_UNSIGNED_INT, new IntPtr(0));
        }