public void upload(ref List<VBO> vboList, ref Dictionary<string, int> textureList)
        {
            int vb, eb;
            GL.GenBuffers(1, out vb);
            GL.GenBuffers(1, out eb);

            int buffer = uploadTexture();
            textureList.Add("Overlay " + buffer, buffer);

            //                      Position     |     Normal      | Texture
            float[] verts = {   0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
                                2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
                                2.0f, 2.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
                                0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f
                            };
            uint[] indices = {  
                                0, 1, 2,
                                0, 2, 3
                             };

            VBO quad = new VBO(vb, eb, buffer, 8, indices.Length);
            vboList.Add(quad);

            GL.BindBuffer(BufferTarget.ArrayBuffer, quad.vertexBuffer);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, quad.elementBuffer);

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Length * sizeof(float)), verts, BufferUsageHint.StaticDraw);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(uint)), indices, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }
Example #2
0
        private void drawVBO(VBO vbo)
        {
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.vertexBuffer);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo.elementBuffer);
            GL.BindTexture(TextureTarget.Texture2D, vbo.textureBuffer);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "diffuseTexture"), 0);

            GL.VertexPointer(3, VertexPointerType.Float, vbo.vertexSize * sizeof(float), 0);
            GL.NormalPointer(NormalPointerType.Float, vbo.vertexSize * sizeof(float), 3 * sizeof(float));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, vbo.vertexSize * sizeof(float), 6 * sizeof(float));

            GL.DrawElements(BeginMode.Triangles, vbo.indexElementCount, DrawElementsType.UnsignedInt, 0);
        }
        public void upload(ref List<VBO> vboList, ref Dictionary<String, int> textureList)
        {
            //Make VBOs of each chunk
            foreach (MeshChunk m in model.chunks)
            {
                int vb, eb, tb = 0;
                GL.GenBuffers(1, out vb);
                GL.GenBuffers(1, out eb);
                //find texture buffer
                //*
                if (m.materialObjectName != "")
                {
                    MaterialObject mao = ResourceManager.findFile<MaterialObject>(m.materialObjectName);
                    if (mao != null)
                    {
                        if (mao.textures.ContainsKey(TextureType.Diffuse))
                        {
                            //if we havent already added it to the dictionary
                            if (!textureList.ContainsKey(mao.textures[TextureType.Diffuse]))
                            {
                                int buffer = 0;
                                //find the file and then make a buffer out of it then add it to the dictionary
                                DDS dds = ResourceManager.findFile<DDS>(mao.textures[TextureType.Diffuse]);
                                if (dds != null)
                                {
                                    DDSUploader temp = new DDSUploader(dds);
                                    buffer = temp.uploadTexture();
                                }
                                else
                                {
                                    Console.WriteLine("Couldn't find texture {0}", mao.textures[TextureType.Diffuse]);
                                }

                                textureList.Add(mao.textures[TextureType.Diffuse], buffer);
                            }
                            tb = textureList[mao.textures[TextureType.Diffuse]];
                        }
                        else
                        {
                            Console.WriteLine("Material object {0} doesn't have a diffuse texture", m.materialObjectName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find material object {0}", m.materialObjectName);
                    }
                }
                //*/
                VBO curVBO = new VBO(vb, eb, tb, 8, m.indices.Length);
                vboList.Add(curVBO);

                GL.BindBuffer(BufferTarget.ArrayBuffer, curVBO.vertexBuffer);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, curVBO.elementBuffer);

                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(m.verts.Length * sizeof(float)), m.verts, BufferUsageHint.StaticDraw);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(curVBO.indexElementCount * sizeof(uint)), m.indices, BufferUsageHint.StaticDraw);

                GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            }
        }
Example #4
0
        public void upload(ref List <VBO> vboList, ref Dictionary <String, int> textureList)
        {
            //Make VBOs of each chunk
            foreach (MeshChunk m in model.chunks)
            {
                int vb, eb, tb = 0;
                GL.GenBuffers(1, out vb);
                GL.GenBuffers(1, out eb);
                //find texture buffer
                //*
                if (m.materialObjectName != "")
                {
                    MaterialObject mao = ResourceManager.findFile <MaterialObject>(m.materialObjectName);
                    if (mao != null)
                    {
                        if (mao.textures.ContainsKey(TextureType.Diffuse))
                        {
                            //if we havent already added it to the dictionary
                            if (!textureList.ContainsKey(mao.textures[TextureType.Diffuse]))
                            {
                                int buffer = 0;
                                //find the file and then make a buffer out of it then add it to the dictionary
                                DDS dds = ResourceManager.findFile <DDS>(mao.textures[TextureType.Diffuse]);
                                if (dds != null)
                                {
                                    DDSUploader temp = new DDSUploader(dds);
                                    buffer = temp.uploadTexture();
                                }
                                else
                                {
                                    Console.WriteLine("Couldn't find texture {0}", mao.textures[TextureType.Diffuse]);
                                }

                                textureList.Add(mao.textures[TextureType.Diffuse], buffer);
                            }
                            tb = textureList[mao.textures[TextureType.Diffuse]];
                        }
                        else
                        {
                            Console.WriteLine("Material object {0} doesn't have a diffuse texture", m.materialObjectName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find material object {0}", m.materialObjectName);
                    }
                }
                //*/
                VBO curVBO = new VBO(vb, eb, tb, 8, m.indices.Length);
                vboList.Add(curVBO);

                GL.BindBuffer(BufferTarget.ArrayBuffer, curVBO.vertexBuffer);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, curVBO.elementBuffer);

                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(m.verts.Length * sizeof(float)), m.verts, BufferUsageHint.StaticDraw);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(curVBO.indexElementCount * sizeof(uint)), m.indices, BufferUsageHint.StaticDraw);

                GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            }
        }