Ejemplo n.º 1
0
        /// <summary>
        /// Inicialización de la iluminación de la escena.
        /// </summary>
        private void InicializarLuces()
        {
            Gl.glPushMatrix();
            float[] light_color;
            float[] light_ambient;
            float[] secondary_light_color;
            float[] secondary_light_ambient;

            light_color             = (daylight) ? day_light_color : night_light_color;
            light_ambient           = (daylight) ? day_light_ambient : night_light_ambient;
            secondary_light_color   = (daylight) ? secondary_day_light_color : secondary_night_light_color;
            secondary_light_ambient = (daylight) ? secondary_day_light_ambient : secondary_night_light_ambient;

            // Fuente de luz principal
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, new float[4] {
                1f, 1f, 1f, 1f
            });
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, light_color);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, light_ambient);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, light_position);

            // Fuentes de luz secundarias
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_DIFFUSE, secondary_light_color);
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT, secondary_light_ambient);
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_SPECULAR, new float[4] {
                0f, 0f, 0f, 1f
            });
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, new float[4] {
                -100.0f, -100.0f, 50.0f, 1.0f
            });
            Gl.glEnable(Gl.GL_LIGHT1);

            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_DIFFUSE, secondary_light_color);
            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_AMBIENT, secondary_light_ambient);
            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_POSITION, new float[4] {
                -100.0f, 100.0f, 1.0f, 0.0f
            });
            Gl.glLightf(Gl.GL_LIGHT2, Gl.GL_SPOT_CUTOFF, 180.0f);
            Gl.glEnable(Gl.GL_LIGHT2);

            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_DIFFUSE, secondary_light_color);
            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_AMBIENT, secondary_light_ambient);
            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_POSITION, new float[4] {
                100.0f, -100.0f, 1.0f, 0.0f
            });
            Gl.glLightf(Gl.GL_LIGHT3, Gl.GL_SPOT_CUTOFF, 180.0f);
            Gl.glEnable(Gl.GL_LIGHT3);

            Gl.glLightfv(Gl.GL_LIGHT4, Gl.GL_DIFFUSE, secondary_light_color);
            Gl.glLightfv(Gl.GL_LIGHT4, Gl.GL_AMBIENT, secondary_light_ambient);
            Gl.glLightfv(Gl.GL_LIGHT4, Gl.GL_POSITION, new float[4] {
                100.0f, 100.0f, 1.0f, 0.0f
            });
            Gl.glLightf(Gl.GL_LIGHT4, Gl.GL_SPOT_CUTOFF, 180.0f);
            Gl.glEnable(Gl.GL_LIGHT4);

            /* no se para que era esto... avisen
             * Gl.glLightf(Gl.GL_LIGHT6, Gl.GL_SPOT_CUTOFF, 10.0f);
             * Gl.glLightfv(Gl.GL_LIGHT6, Gl.GL_DIFFUSE, day_light_color);
             * Gl.glLightfv(Gl.GL_LIGHT6, Gl.GL_AMBIENT, day_light_ambient);
             * //Gl.glLightfv(Gl.GL_LIGHT6, Gl.GL_SPOT_DIRECTION, this.light_linterna_direction);
             * //Gl.glLighti(Gl.GL_LIGHT6, Gl.GL_QUADRATIC_ATTENUATION, 1);
             **/

            if (daylight)
            {
                Gl.glDisable(Gl.GL_LIGHT6);
                Gl.glEnable(Gl.GL_LIGHT0);
            }
            else
            {
                Gl.glEnable(Gl.GL_LIGHT6);
                Gl.glDisable(Gl.GL_LIGHT0);
            }

            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glPopMatrix();
        }
        //Fragment Lighting Primary Color:
        //Color = SUM((dmp_FragmentLightSource[i].diffuse * dmp_FragmentMaterial.diffuse * DOT(dmp_FragmentLightSource[i].position, NormalVector) * SdwAttPr[i] + dmp_FragmentMaterial.ambient * dmp_FragmentLightSource[i].ambient) * Spot[i] * DistAtt[i]) + dmp_FragmentMaterial.emission + dmp_FragmentMaterial.ambient * dmp_FragmentLighting.ambient

        public void Compile()
        {
            uint sampler_count = (uint)Textures.Length;

            StringBuilder vert_ss = new StringBuilder();

            vert_ss.AppendFormat("vec4 diffuse = {0};\n", GetVec4(Material.MaterialColor.DiffuseU32));
            vert_ss.AppendFormat("vec4 ambient = {0};\n", GetVec4(Material.MaterialColor.Ambient));
            vert_ss.AppendFormat("vec4 spec1 = {0};\n", GetVec4(Material.MaterialColor.Specular0U32));
            vert_ss.AppendFormat("vec4 spec2 = {0};\n", GetVec4(Material.MaterialColor.Specular1U32));

            vert_ss.AppendLine("varying vec3 N;");

            vert_ss.AppendLine("void main()");
            vert_ss.AppendLine("{");
            {
                //vert_ss.AppendLine("gl_FrontColor = gl_Color * ambient;");
                vert_ss.AppendLine("gl_FrontColor = gl_Color;");

                if (Material.Tex0 != null)
                {
                    vert_ss.AppendFormat("gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[0].SourceCoordinate);
                }
                if (Material.Tex1 != null)
                {
                    vert_ss.AppendFormat("gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[1].SourceCoordinate);
                }
                if (Material.Tex2 != null)
                {
                    vert_ss.AppendFormat("gl_TexCoord[2] = gl_TextureMatrix[2] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[2].SourceCoordinate);
                }

                vert_ss.AppendLine("N = normalize(gl_NormalMatrix * gl_Normal);");
                vert_ss.AppendLine("gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;");
            }
            vert_ss.AppendLine("}");

            // create/compile vertex shader
            vertex_shader = Gl.glCreateShader(Gl.GL_VERTEX_SHADER);

            {
                var vert_src_str = vert_ss.ToString();
                Gl.glShaderSource(vertex_shader, 1, new string[] { vert_src_str }, new int[] { vert_src_str.Length });
            }

            Gl.glCompileShader(vertex_shader);


            string[] constant =
            {
                "const0",
                "const1",
                "const2",
                "const3",
                "const4",
                "const5",
                "emission",
                "ambient",
                "diffuse",
                "spec1",
                "spec2"
            };

            /*
             * Confirmed by intermediate file:
             * 0x00 - PrimaryColor
             * 0x01 - FragmentPrimaryColor
             * 0x02 - FragmentSecondaryColor
             * 0x03 - Texture0
             */

            string[] p0 =
            {
                "gl_Color",
                "primaryc",
                "secondc",
                "texture2D(textures0, gl_TexCoord[0].st)",
                "texture2D(textures1, gl_TexCoord[1].st)",
                "texture2D(textures2, gl_TexCoord[2].st)",
                "texture2D(textures3, gl_TexCoord[3].st)",
                "const0",                //?
                "const1",                //?
                "const2",                //?
                "const3",                //?
                "const4",                //?
                "const5",                //?
                "bufin",
                "{0}",
                "previous"
            };

            string[] c_p1 =
            {
                "{0}.rgb",                //0
                "vec3(1.0) - {0}.rgb",    //1
                "{0}.aaa",                //2
                "vec3(1.0) - {0}.aaa",    //3
                "{0}.rrr",                //4
                "vec3(1.0) - {0}.rrr",    //5
                "{0}.rgb",                //?
                "{0}.rgb",                //?
                "{0}.ggg",                //8
                "vec3(1.0) - {0}.ggg",    //9
                "{0}.rgb",                //?
                "{0}.rgb",                //?
                "{0}.bbb",                //c
                "vec3(1.0) - {0}.bbb",    //d
                "{0}.rgb",                //?
                "{0}.rgb",                //?
            };

            string[] a_p1 =
            {
                "{0}.a",
                "1.0 - {0}.a",
                "{0}.r",
                "1.0 - {0}.r",
                "{0}.g",
                "1.0 - {0}.g",
                "{0}.b",
                "1.0 - {0}.b",
                "{0}.a",               //unknown 8
                "{0}.a",               //unknown 9
                "{0}.a",               //unknown A
                "{0}.a",               //unknown B
                "{0}.a",               //unknown C
                "{0}.a",               //unknown D
                "{0}.a",               //unknown E
                "{0}.a"                //unknown F
            };

            string[] c_p2 =
            {
                "j1.rgb",
                "j1.rgb * j2.rgb",
                "j1.rgb + j2.rgb",
                "j1.rgb + j2.rgb - vec3(0.5)",
                "j1.rgb * j3.rgb + j2.rgb * (vec3(1.0) - j3.rgb)",
                "j1.rgb - j2.rgb",
                "vec3(4 * ((j1.r - 0.5) * (j2.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5)))",
                "vec4(4 * ((j1.r - 0.5) * (j2.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5)))",
                "(j1.rgb * j2.rgb) + j3.rgb",                //"j1.rgb * j2.aaa + j3.rgb" //"(vec3(1.0) - ((vec3(1.0) - j1.rgb) + (vec3(1.0) - j2.rgb))) + j3.rgb",//"j2.rgb * j1.rgb + j3.rgb * (vec3(1.0) - j1.rgb)",//"j1.rgb * j2.rgb + j3.rgb * (vec3(1.0) - j2.rgb)",//"j1.rgb * j2.rgb + j3.rgb * (vec3(1.0) - j2.rgb)"//"j2.rgb + j1.rgb - (vec3(1.0) - j3.rgb)",//Unknown 8
                "clamp(j1.rgb + j2.rgb, 0.0, 1.0) * j3.rgb"  //"j2.rgb + (j1.rgb * j3.rgb)"//"j3.rgb * j1.rgb + j2.rgb - vec3(0.1)"//"j2.rgb * j3.rgb + j1.rgb - vec3(0.5)"//"j1.rgb * j2.rgb + j3.rgb * (vec3(1.0) - j2.rgb)"//"j1.rgb + j3.rgb * j2.rgb"//"j3.rgb"//Unknown 9
            };

            string[] a_p2 =
            {
                "j1.a",
                "j1.a * j2.a",
                "j1.a + j2.a",
                "j1.a + j2.a - 0.5",
                "j1.a * j3.a + j2.a * (1.0 - j3.a)",
                "j1.a - j2.a",
                "j1.a",                               //unknown
                "j1.a",                               //unknown
                "(j1.a * j2.a) + j3.a",               //"j2.a * j1.a + j3.a * (1.0 - j1.a)",//Unknown 8
                "clamp(j1.a + j2.a, 0.0, 1.0) * j3.a" //"(1.0 - j2.a) + (j1.a * j3.a)"//"j2.a - (j1.a + j3.a)"//"j3.a * j1.a + j2.a - 0.1"//"j1.a * j2.a + j3.a * (1.0 - j2.a)"//Unknown 9
            };

            string[] scale =
            {
                //"1.0",
                //"1.0",
                //"1.0"
                "1.0",
                "2.0",
                "4.0"
            };

            //SUM((dmp_FragmentLightSource[i].diffuse * dmp_FragmentMaterial.diffuse * DOT(dmp_FragmentLightSource[i].position, NormalVector) * SdwAttPr[i] + dmp_FragmentMaterial.ambient * dmp_FragmentLightSource[i].ambient) * Spot[i] * DistAtt[i]) + dmp_FragmentMaterial.emission + dmp_FragmentMaterial.ambient * dmp_FragmentLighting.ambient

            //Vector3 N = new Vector3();//tmp normal

            /*Vector4 a =
             *      (DefaultLight0.Diffuse
             * Material.MaterialColor.Diffuse
             * (new Vector3(DefaultLight0.Position.X, DefaultLight0.Position.Y, DefaultLight0.Position.Z).Dot(N))
             *      //no SdwAttPr[i], because no shadow map is used
             + Material.MaterialColor.Ambient
             * DefaultLight0.Ambient)
             * DefaultLight0.SpotDirection
             *      //* DefaultFragmentLightingAmbient;
             */
            /*Vector4 PColor = Material.MaterialColor.Emission + DefaultFragmentLightingAmbient * Material.MaterialColor.Ambient;
             * FragmentLightSource[] Lights = new FragmentLightSource[]{DefaultLight0};
             * for (int i = 0; i < Lights.Length; i++)
             * {
             *      PColor += //skip spotlight and distance attenuation
             *                      (Lights[i].Ambient * Material.MaterialColor.Ambient)//skip something vague  (Lights[i].TwoSideDiffuse? Math.Abs(
             * Lights[i].Diffuse * Material.MaterialColor.Diffuse; //skip shadow attenuation
             * }*/


            // generate fragment shader code
            //{
            StringBuilder frag_ss = new StringBuilder();

            //frag_ss += "uniform sampler2D tex;";
            // uniforms
            for (uint i = 0; i != sampler_count; ++i)
            {
                frag_ss.AppendFormat("uniform sampler2D textures{0};\n", i);
            }

            frag_ss.AppendLine("varying vec3 N;");

            frag_ss.AppendFormat("vec4 const0 = {0};\n", GetVec4(Material.MaterialColor.Constant0U32));
            frag_ss.AppendFormat("vec4 const1 = {0};\n", GetVec4(Material.MaterialColor.Constant1U32));
            frag_ss.AppendFormat("vec4 const2 = {0};\n", GetVec4(Material.MaterialColor.Constant2U32));
            frag_ss.AppendFormat("vec4 const3 = {0};\n", GetVec4(Material.MaterialColor.Constant3U32));
            frag_ss.AppendFormat("vec4 const4 = {0};\n", GetVec4(Material.MaterialColor.Constant4U32));
            frag_ss.AppendFormat("vec4 const5 = {0};\n", GetVec4(Material.MaterialColor.Constant5U32));
            frag_ss.AppendFormat("vec4 diffuse = {0};\n", GetVec4(Material.MaterialColor.DiffuseU32));
            frag_ss.AppendFormat("vec4 ambient = {0};\n", GetVec4(Material.MaterialColor.Ambient));
            frag_ss.AppendFormat("vec4 spec1 = {0};\n", GetVec4(Material.MaterialColor.Specular0U32));
            frag_ss.AppendFormat("vec4 spec2 = {0};\n", GetVec4(Material.MaterialColor.Specular1U32));
            frag_ss.AppendFormat("vec4 emission = {0};\n", GetVec4(Material.MaterialColor.EmissionU32));
            frag_ss.AppendFormat("vec4 unk1 = vec4(1.0);\n");
            frag_ss.AppendFormat("vec4 unk2 = vec4(0.0);\n");
            frag_ss.AppendFormat("vec4 unk3 = {0};\n", GetVec4(Material.FragShader.BufferColor));

            if (Material.MaterialColor.Constant0U32 == Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant1U32 == Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant2U32 == Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant3U32 == Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant4U32 == Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant5U32 == Color.FromArgb(0, 0, 0, 0))
            {
                frag_ss.AppendLine("const0 = const1 = const2 = const3 = const4 = const5 = vec4(0, 0, 0, 1);");
            }

            frag_ss.AppendFormat("vec4 buf0 = unk3;\n");
            frag_ss.AppendFormat("vec4 buf1;\n");
            frag_ss.AppendFormat("vec4 buf2;\n");
            frag_ss.AppendFormat("vec4 buf3;\n");
            frag_ss.AppendFormat("vec4 buf4;\n");
            //frag_ss.AppendFormat("vec4 unk3 = gl_Color;\n");
            //frag_ss.AppendFormat("vec4 unk3 = vec4(1.0);\n");

            frag_ss.AppendFormat("vec4 DefFLtAmb = {0};\n", GetVec4(DefaultFragmentLightingAmbient));
            frag_ss.AppendFormat("vec4 DefLt0Amb = {0};\n", GetVec4(DefaultLight0.Ambient));
            frag_ss.AppendFormat("vec4 DefLt0Dif = {0};\n", GetVec4(DefaultLight0.Diffuse));
            frag_ss.AppendFormat("vec4 DefLt0Spec0 = {0};\n", GetVec4(DefaultLight0.Specular0));
            frag_ss.AppendFormat("vec4 DefLt0Spec1 = {0};\n", GetVec4(DefaultLight0.Specular1));
            frag_ss.AppendFormat("vec4 DefLt0Pos = {0};\n", GetVec4(DefaultLight0.Position));

            frag_ss.AppendLine("void main()");
            frag_ss.AppendLine("{");
            {
                frag_ss.AppendLine("vec4 primaryc = emission + DefFLtAmb * ambient;");
                //Use one default light
                frag_ss.AppendLine("primaryc += (DefLt0Amb * ambient + max(dot(DefLt0Pos, vec4(N, 0.0)), 0)) * DefLt0Dif * diffuse;");

                frag_ss.AppendLine("vec4 secondc = DefLt0Spec0 * spec1 + DefLt0Spec1 * spec2;");

                frag_ss.AppendLine("vec4 previous = vec4(1.0);");
                frag_ss.AppendLine("vec4 i1c;");
                frag_ss.AppendLine("vec4 i2c;");
                frag_ss.AppendLine("vec4 i3c;");
                frag_ss.AppendLine("vec4 i1a;");
                frag_ss.AppendLine("vec4 i2a;");
                frag_ss.AppendLine("vec4 i3a;");

                frag_ss.AppendLine("vec4 j1;");
                frag_ss.AppendLine("vec4 j2;");
                frag_ss.AppendLine("vec4 j3;");
                frag_ss.AppendLine("vec4 ConstRgba;");
                frag_ss.AppendLine("vec4 bufin;");
                for (int i = 0; i < 6; i++)
                {
                    if (i > 0 && i < 5)
                    {
                        if (((Material.FragShader.BufferCommand3 >> (i + 7)) & 1) == 1)
                        {
                            frag_ss.AppendFormat("buf{0}.rgb = previous.rgb;\n", i);
                        }
                        else
                        {
                            frag_ss.AppendFormat("buf{0}.rgb = buf{1}.rgb;\n", i, i - 1);
                        }
                        if (((Material.FragShader.BufferCommand3 >> (i + 11)) & 1) == 1)
                        {
                            frag_ss.AppendFormat("buf{0}.a = previous.a;\n", i);
                        }
                        else
                        {
                            frag_ss.AppendFormat("buf{0}.a = buf{1}.a;\n", i, i - 1);
                        }
                    }

                    frag_ss.AppendFormat("ConstRgba = {0};\n", GetVec4(Material.FragShader.TextureCombiners[i].ConstRgba));
                    int c_input1 = (Material.FragShader.TextureCombiners[i].SrcRgb >> 0) & 0xF;
                    int c_input2 = (Material.FragShader.TextureCombiners[i].SrcRgb >> 4) & 0xF;
                    int c_input3 = (Material.FragShader.TextureCombiners[i].SrcRgb >> 8) & 0xF;

                    int a_input1 = (Material.FragShader.TextureCombiners[i].SrcAlpha >> 0) & 0xF;
                    int a_input2 = (Material.FragShader.TextureCombiners[i].SrcAlpha >> 4) & 0xF;
                    int a_input3 = (Material.FragShader.TextureCombiners[i].SrcAlpha >> 8) & 0xF;

                    //String cons;
                    ///*if (Material.Shader.TexEnvSlotInfos[i].ConstRgba.ToArgb() == Color.Black.ToArgb())*/ cons = "const" + (Material.Shader.TexEnvSlotInfos[i].Unknown3 & 0xF);
                    //else cons = "ConstRgba";
                    if (i > 0)
                    {
                        frag_ss.AppendFormat("bufin = buf{0};\n", i - 1);
                    }

                    frag_ss.AppendFormat("i1c = {0};\n", String.Format(p0[c_input1], constant[Material.FragShader.TextureCombiners[i].Constant]));
                    frag_ss.AppendFormat("i2c = {0};\n", String.Format(p0[c_input2], constant[Material.FragShader.TextureCombiners[i].Constant]));
                    frag_ss.AppendFormat("i3c = {0};\n", String.Format(p0[c_input3], constant[Material.FragShader.TextureCombiners[i].Constant]));

                    frag_ss.AppendFormat("i1a = {0};\n", String.Format(p0[a_input1], constant[Material.FragShader.TextureCombiners[i].Constant]));
                    frag_ss.AppendFormat("i2a = {0};\n", String.Format(p0[a_input2], constant[Material.FragShader.TextureCombiners[i].Constant]));
                    frag_ss.AppendFormat("i3a = {0};\n", String.Format(p0[a_input3], constant[Material.FragShader.TextureCombiners[i].Constant]));

                    //frag_ss.AppendFormat("i1 = vec4({0}.rgb, {1}.a);\n", String.Format(p0[c_input1], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF), String.Format(p0[a_input1], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF));
                    //frag_ss.AppendFormat("i2 = vec4({0}.rgb, {1}.a);\n", String.Format(p0[c_input2], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF), String.Format(p0[a_input2], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF));
                    //frag_ss.AppendFormat("i3 = vec4({0}.rgb, {1}.a);\n", String.Format(p0[c_input3], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF), String.Format(p0[a_input3], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF));

                    uint c_p1_1 = (Material.FragShader.TextureCombiners[i].Operands >> 0) & 0xF;
                    uint c_p1_2 = (Material.FragShader.TextureCombiners[i].Operands >> 4) & 0xF;
                    uint c_p1_3 = (Material.FragShader.TextureCombiners[i].Operands >> 8) & 0xF;

                    uint a_p1_1 = (Material.FragShader.TextureCombiners[i].Operands >> 12) & 0xF;
                    uint a_p1_2 = (Material.FragShader.TextureCombiners[i].Operands >> 16) & 0xF;
                    uint a_p1_3 = (Material.FragShader.TextureCombiners[i].Operands >> 20) & 0xF;

                    frag_ss.AppendFormat("j1 = vec4({0}, {1});\n", String.Format(c_p1[c_p1_1], "i1c"), String.Format(a_p1[a_p1_1], "i1a"));
                    frag_ss.AppendFormat("j2 = vec4({0}, {1});\n", String.Format(c_p1[c_p1_2], "i2c"), String.Format(a_p1[a_p1_2], "i2a"));
                    frag_ss.AppendFormat("j3 = vec4({0}, {1});\n", String.Format(c_p1[c_p1_3], "i3c"), String.Format(a_p1[a_p1_3], "i3a"));

                    if (Material.FragShader.TextureCombiners[i].CombineRgb == 7)
                    {
                        frag_ss.AppendFormat("previous = {0};\n", c_p2[Material.FragShader.TextureCombiners[i].CombineRgb]);
                    }
                    else
                    {
                        frag_ss.AppendFormat("previous = clamp(vec4(({0}) * vec3({2}, {2}, {2}), ({1}) * {3}), 0.0, 1.0);\n", c_p2[Material.FragShader.TextureCombiners[i].CombineRgb], a_p2[Material.FragShader.TextureCombiners[i].CombineAlpha], scale[Material.FragShader.TextureCombiners[i].ScaleRgb], scale[Material.FragShader.TextureCombiners[i].ScaleAlpha]);
                    }
                    //else frag_ss.AppendFormat("previous = clamp(vec4(({0}) * vec3({2}), ({1}) * {3}), 0.0, 1.0);\n", c_p2[Material.Shader.TexEnvSlotInfos[i].CombineRgb], a_p2[Material.Shader.TexEnvSlotInfos[i].CombineAlpha], Material.Shader.TexEnvSlotInfos[i].Unknown2Rgb + 1, Material.Shader.TexEnvSlotInfos[i].Unknown2Alpha + 1);
                }
                frag_ss.AppendLine("gl_FragColor = previous;");
                //frag_ss.AppendLine("gl_FragColor = texture2D(textures0, gl_TexCoord[0].st) * vec4(gl_Color.rgb, 1.0);");
            }
            frag_ss.AppendLine("}");

            //std::cout << frag_ss.str() << '\n';

            // create/compile fragment shader
            fragment_shader = Gl.glCreateShader(Gl.GL_FRAGMENT_SHADER);
            {
                var frag_src_str = frag_ss.ToString();
                Gl.glShaderSource(fragment_shader, 1, new String[] { frag_src_str }, new int[] { frag_src_str.Length });
            }

            //}	// done generating fragment shader

            Gl.glCompileShader(fragment_shader);

            // check compile status of both shaders
            //{
            int vert_compiled = 0;
            int frag_compiled = 0;

            Gl.glGetShaderiv(vertex_shader, Gl.GL_COMPILE_STATUS, out vert_compiled);
            Gl.glGetShaderiv(fragment_shader, Gl.GL_COMPILE_STATUS, out frag_compiled);

            if (vert_compiled == 0)
            {
                //std::cout << "Failed to compile vertex shader\n";
            }

            if (frag_compiled == 0)
            {
                //std::cout << "Failed to compile fragment shader\n";
            }

            // create program, attach shaders
            program = Gl.glCreateProgram();
            Gl.glAttachShader(program, vertex_shader);
            Gl.glAttachShader(program, fragment_shader);

            // link program, check link status
            Gl.glLinkProgram(program);
            int link_status;

            Gl.glGetProgramiv(program, Gl.GL_LINK_STATUS, out link_status);

            if (link_status == 0)
            {
                //std::cout << "Failed to link program!\n";
            }

            Gl.glUseProgram(program);

            // set uniforms
            for (uint i = 0; i != sampler_count; ++i)
            {
                String ss = "textures" + i;
                Gl.glUniform1i(Gl.glGetUniformLocation(program, ss), (int)i);
            }
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     Gl.DeleteShader(ShaderName);
 }
Ejemplo n.º 4
0
        private void DrawPolygonStipple()
        {
            var fire = new byte[]
            {
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0xc0,
                0x00, 0x00, 0x01, 0xf0,
                0x00, 0x00, 0x07, 0xf0,
                0x0f, 0x00, 0x1f, 0xe0,
                0x1f, 0x80, 0x1f, 0xc0,
                0x0f, 0xc0, 0x3f, 0x80,
                0x07, 0xe0, 0x7e, 0x00,
                0x03, 0xf0, 0xff, 0x80,
                0x03, 0xf5, 0xff, 0xe0,
                0x07, 0xfd, 0xff, 0xf8,
                0x1f, 0xfc, 0xff, 0xe8,
                0xff, 0xe3, 0xbf, 0x70,
                0xde, 0x80, 0xb7, 0x00,
                0x71, 0x10, 0x4a, 0x80,
                0x03, 0x10, 0x4e, 0x40,
                0x02, 0x88, 0x8c, 0x20,
                0x05, 0x05, 0x04, 0x40,
                0x02, 0x82, 0x14, 0x40,
                0x02, 0x40, 0x10, 0x80,
                0x02, 0x64, 0x1a, 0x80,
                0x00, 0x92, 0x29, 0x00,
                0x00, 0xb0, 0x48, 0x00,
                0x00, 0xc8, 0x90, 0x00,
                0x00, 0x85, 0x10, 0x00,
                0x00, 0x03, 0x00, 0x00,
                0x00, 0x00, 0x10, 0x00
            };


            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            // Запомнить первоначальное состояние матрицы вращения
            Gl.glPushMatrix();

            // Настроить два последовательных поворота
            // для будущей визуализации сцены
            Gl.glRotatef(250, 1.0f, 0.0f, 0.0f); // Первое состояние матрицы вращения
            Gl.glRotatef(0, 0.0f, 1.0f, 0.0f);   // Следующее состояние

            // Включить красный цвет рисования
            Gl.glColor3f(1.0f, 0.0f, 0.0f);

            // Включить фактуру при заполнении полигонов
            Gl.glEnable(Gl.GL_POLYGON_STIPPLE);

            // Адресовать битовую маску костра для фактуры
            Gl.glPolygonStipple(fire);

            // Нарисовать полигон в форме дорожного знака
            // "Движение без остановки запрещено",
            // закрашенного по маске костра красным цветом
            Gl.glBegin(Gl.GL_POLYGON);
            Gl.glVertex2f(-20.0f, 50.0f);
            Gl.glVertex2f(20.0f, 50.0f);
            Gl.glVertex2f(50.0f, 20.0f);
            Gl.glVertex2f(50.0f, -20.0f);
            Gl.glVertex2f(20.0f, -50.0f);
            Gl.glVertex2f(-20.0f, -50.0f);
            Gl.glVertex2f(-50.0f, -20.0f);
            Gl.glVertex2f(-50.0f, 20.0f);
            Gl.glEnd();

            Gl.glColor3f(0.0f, 1.0f, 0.0f); // Восстановить цвет рисования зеленый

            // Выключить фактуру при заполнении полигонов
            Gl.glDisable(Gl.GL_POLYGON_STIPPLE);

            // Восстановить матрицу вращения в исходное состояние
            Gl.glPopMatrix();
        }
Ejemplo n.º 5
0
 public void Bind() => Gl.glBindTexture(Gl.GL_TEXTURE_2D, this.GlId);
Ejemplo n.º 6
0
        public static void SolidCone(double baseRadius, double height, int slices, int stacks)
        {
            int i, j;

            /* Step in z and radius as stacks are drawn. */

            double z0, z1;
            double r0, r1;

            double zStep = height / ((stacks > 0) ? stacks : 1);
            double rStep = baseRadius / ((stacks > 0) ? stacks : 1);

            /* Scaling factors for vertex normals */

            double cosn = (height / Math.Sqrt(height * height + baseRadius * baseRadius));
            double sinn = (baseRadius / Math.Sqrt(height * height + baseRadius * baseRadius));

            /* Pre-computed circle */

            double[] sint, cost;

            fghCircleTable(out sint, out cost, slices);

            /* Cover the circular base with a triangle fan... */

            z0 = 0.0;
            z1 = zStep;

            r0 = baseRadius;
            r1 = r0 - rStep;

            Gl.glBegin(Gl.GL_TRIANGLE_FAN);

            Gl.glNormal3d(0.0, 0.0, -1.0);
            Gl.glVertex3d(0.0, 0.0, z0);

            for (j = 0; j <= slices; j++)
            {
                Gl.glVertex3d(cost[j] * r0, sint[j] * r0, z0);
            }

            Gl.glEnd();

            /* Cover each stack with a quad strip, except the top stack */

            for (i = 0; i < stacks - 1; i++)
            {
                Gl.glBegin(Gl.GL_QUAD_STRIP);

                for (j = 0; j <= slices; j++)
                {
                    Gl.glNormal3d(cost[j] * sinn, sint[j] * sinn, cosn);
                    Gl.glVertex3d(cost[j] * r0, sint[j] * r0, z0);
                    Gl.glVertex3d(cost[j] * r1, sint[j] * r1, z1);
                }

                z0 = z1; z1 += zStep;
                r0 = r1; r1 -= rStep;

                Gl.glEnd();
            }

            /* The top stack is covered with individual triangles */

            Gl.glBegin(Gl.GL_TRIANGLES);

            Gl.glNormal3d(cost[0] * sinn, sint[0] * sinn, cosn);

            for (j = 0; j < slices; j++)
            {
                Gl.glVertex3d(cost[j + 0] * r0, sint[j + 0] * r0, z0);
                Gl.glVertex3d(0, 0, height);
                Gl.glNormal3d(cost[j + 1] * sinn, sint[j + 1] * sinn, cosn);
                Gl.glVertex3d(cost[j + 1] * r0, sint[j + 1] * r0, z0);
            }

            Gl.glEnd();
        }
Ejemplo n.º 7
0
        private void DrawCone()
        {
            float x, y, angle;    // Переменные для координат и угла
            bool  iColor = false; // Флаг переключения цвета

            // Устанавливаем неструктурированный цвет модели затенения
            Gl.glShadeModel(Gl.GL_FLAT);

            // Устанавливаем направление обхода по часовой стрелке
            Gl.glFrontFace(Gl.GL_CW);

            //// Очистить окно и буфер глубины
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            // Включить/Выключить отбор
            if (_isSelection)
            {
                Gl.glEnable(Gl.GL_CULL_FACE);
            }
            else
            {
                Gl.glDisable(Gl.GL_CULL_FACE);
            }

            // Включить/Выключить глубину
            if (_isDepth)
            {
                Gl.glEnable(Gl.GL_DEPTH_TEST);
            }
            else
            {
                Gl.glDisable(Gl.GL_DEPTH_TEST);
            }

            // Включить/Выключить каркас задней стенки
            if (_isBackWall)
            {
                Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_LINE);
            }
            else
            {
                Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_FILL);
            }

            // Запомнить первоначальное состояние матрицы вращения
            Gl.glPushMatrix();

            // Выполнить два последовательных поворота
            // для будущей визуализации сцены
            Gl.glRotatef(xRot, 1.0f, 0.0f, 0.0f); // Новое состояние матрицы вращения
            Gl.glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Следующее новое состояние

            //************  Рисовать конус  ***********************************
            // Рисовать веер треугольников
            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            // Устанавливаем первую точку - вершину конуса ближе к наблюдателю
            Gl.glVertex3f(0.0f, 0.0f, 50.0f);

            // Проходим оборот в плоскости x0y
            for (angle = 0.0f; angle <= 3.0f * Math.PI; angle += (float)Math.PI / 8.0f)
            {
                // Вычисляем очередную точку на окружности
                x = 20.0f * (float)Math.Sin(angle);
                y = 20.0f * (float)Math.Cos(angle);

                // Чередуем цвета
                if (iColor)                         // Деление по модулю
                {
                    Gl.glColor3f(0.0f, 1.0f, 0.0f); // Зеленый
                }
                else
                {
                    Gl.glColor3f(0xFF, 0xFF, 0x00); // Желтый
                }
                iColor = !iColor;                   // Для переключения цвета

                // Установливаем вычисленную точку на плоскости x0y
                Gl.glVertex2f(x, y);
            }

            Gl.glEnd(); // Рисуем веер, имитирующий конус

            //***********  Рисовать основание конуса  *************************
            // Начинаем строить новый веер в плоскости x0y
            // Имитирующий основание конуса в начале координат

            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            // Устанавливаем первую точку центра основания при z=0
            Gl.glVertex2f(0.0f, 0.0f);

            // Проходим оборот в плоскости x0y
            for (angle = 0.0f; angle <= 3.0f * Math.PI; angle += (float)Math.PI / 10.0f)
            {
                // Вычисляем очередную точку на окружности
                x = 20.0f * (float)Math.Sin(angle);
                y = 20.0f * (float)Math.Cos(angle);

                // Чередуем цвета
                if (!(iColor))                      // Деление по модулю
                {
                    Gl.glColor3f(0.0f, 0.0f, 1.0f); // Синий
                }
                else
                {
                    Gl.glColor3f(1.0f, 0.0f, 0.0f); // Красный
                }
                iColor = !iColor;                   // Для переключения цвета

                // Установливаем вычисленную точку на плоскости x0y
                Gl.glVertex2f(x, y);
            }
            Gl.glEnd(); // Рисуем веер, имитирующий основание

            // Восстанавливаем измененные состояния в исходные значения
            Gl.glPopMatrix();
            Gl.glDisable(Gl.GL_CULL_FACE);
            Gl.glDisable(Gl.GL_DEPTH_TEST);
            Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_FILL);
            Gl.glColor3f(0.0f, 1.0f, 0.0f);     // Зеленый
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets the color.
 /// </summary>
 /// <param name="color">The color.</param>
 public static void SetColor(Color color)
 {
     Gl.glColor4f((float)color.R / 255f, (float)color.G / 255f, (float)color.B / 255f, (float)color.A / 255f);
 }
Ejemplo n.º 9
0
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            // set up the viewport and clear the previous depth and color buffers
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // perform rotation of the cube depending on the keyboard state
            if (autoRotate)
            {
                xangle += deltaTime / 2;
                yangle += deltaTime;
            }
            if (right)
            {
                yangle += deltaTime;
            }
            if (left)
            {
                yangle -= deltaTime;
            }
            if (up)
            {
                xangle -= deltaTime;
            }
            if (down)
            {
                xangle += deltaTime;
            }

            // make sure the shader program and texture are being used
            Gl.UseProgram(program);
            Gl.ActiveTexture(TextureUnit.Texture1);
            Gl.BindTexture(brickNormals);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(brickDiffuse);

            // set up the model matrix and draw the cube
            program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle));
            program["enable_lighting"].SetValue(lighting);
            program["enable_mapping"].SetValue(normalMapping);

            Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(cubeTangents, program, "vertexTangent");
            Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
            Gl.BindBuffer(cubeTriangles);

            Gl.DrawElements(BeginMode.Triangles, cubeTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            // bind the font program as well as the font texture
            Gl.UseProgram(fontProgram.ProgramID);
            Gl.BindTexture(font.FontTexture);

            // draw the tutorial information, which is static
            information.Draw();

            Glut.glutSwapBuffers();
        }
Ejemplo n.º 10
0
 public static void Scissor(Rectangle rect)
 {
     Gl.glScissor(rect.X, Globals.ScreenHeight - (rect.Y + rect.Height),
                  rect.Width, rect.Height);
 }
Ejemplo n.º 11
0
        public static void DrawCube(int width, int height, int length, int x, int y, int z, string[] textures)
        {
            //back, top, front, right, left, bottom

            x = x - width / 2;
            z = z - length / 2;

            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, ContentManager.GetTextureByName(textures[0]));

            Gl.glBegin(Gl.GL_QUADS);
            Gl.glNormal3d(-1, 1, 1);
            Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3d(x + width, y, z);
            Gl.glNormal3d(-1, -1, 1);
            Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3d(x + width, y + height, z);
            Gl.glNormal3d(1, -1, 1);
            Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3d(x, y + height, z);
            Gl.glNormal3d(1, 1, 1);
            Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3d(x, y, z);
            Gl.glEnd();

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, ContentManager.GetTextureByName(textures[1]));
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glNormal3d(-1, -1, 1);
            Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3d(x + width, y + height - 0.5f, z);
            Gl.glNormal3d(-1, -1, -1);
            Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3d(x + width, y + height - 0.5f, z + length);
            Gl.glNormal3d(1, -1, -1);
            Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3d(x, y + height - 0.5f, z + length);
            Gl.glNormal3d(1, -1, 1);
            Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3d(x, y + height - 0.5f, z);
            Gl.glEnd();

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, ContentManager.GetTextureByName(textures[2]));
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glNormal3d(1, 1, -1);
            Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3d(x, y, z + length);
            Gl.glNormal3d(1, -1, -1);
            Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3d(x, y + height, z + length);
            Gl.glNormal3d(-1, -1, -1);
            Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3d(x + width, y + height, z + length);
            Gl.glNormal3d(-1, 1, -1);
            Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3d(x + width, y, z + length);
            Gl.glEnd();

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, ContentManager.GetTextureByName(textures[3]));
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glNormal3d(1, -1, 1);
            Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3d(x, y + height, z);
            Gl.glNormal3d(1, -1, -1);
            Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3d(x, y + height, z + length);
            Gl.glNormal3d(1, 1, -1);
            Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3d(x, y, z + length);
            Gl.glNormal3d(1, 1, 1);
            Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3d(x, y, z);
            Gl.glEnd();

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, ContentManager.GetTextureByName(textures[4]));
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glNormal3d(-1, 1, 1);
            Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3d(x + width, y, z);
            Gl.glNormal3d(-1, 1, -1);
            Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3d(x + width, y, z + length);
            Gl.glNormal3d(-1, -1, -1);
            Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3d(x + width, y + height, z + length);
            Gl.glNormal3d(-1, -1, 1);
            Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3d(x + width, y + height, z);
            Gl.glEnd();

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, ContentManager.GetTextureByName(textures[5]));
            Gl.glBegin(Gl.GL_QUADS);

            // Assign the texture coordinates and vertices for the BOTTOM Side
            Gl.glNormal3d(1, 1, 1);
            Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3d(x, y, z);
            Gl.glNormal3d(1, 1, -1);
            Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3d(x, y, z + length);
            Gl.glNormal3d(-1, 1, -1);
            Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3d(x + width, y, z + length);
            Gl.glNormal3d(-1, 1, 1);
            Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3d(x + width, y, z);
            Gl.glEnd();
        }
Ejemplo n.º 12
0
 private void OnViewportResize(IntPtr window, int width, int height)
 {
     Gl.Viewport(0, 0, width, height);
 }
Ejemplo n.º 13
0
 public void Dispose()
 {
     Gl.DeleteTextures(1, m_tex);
 }
Ejemplo n.º 14
0
        protected override void Particular()
        {
            double n1 = 1, n2 = 0.7, n3 = 0.57;

            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlUtils.Texture("AZULEJO"));

            Gl.glBegin(Gl.GL_QUADS);

            //lateral izquierdo
            //Gl.glColor3d(0.95,0.95,1);
            Gl.glColor3d(0.1, 0.15, .1);
            Gl.glNormal3d(-n3, -n3, n3); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(0, 0, 0);
            Gl.glNormal3d(-n3, n3, n3); Gl.glTexCoord2d(6, 0); Gl.glVertex3d(0, alto * 100, 0);
            Gl.glNormal3d(-n3, n3, -n3); Gl.glTexCoord2d(6, 5); Gl.glVertex3d(0, alto * 100, -ancho * 100);
            Gl.glNormal3d(-n3, -n3, -n3); Gl.glTexCoord2d(0, 5); Gl.glVertex3d(0, 0, -ancho * 100);

            //lateral derecho

            Gl.glNormal3d(n3, -n3, n3); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(largo * 100, 0, 0);
            Gl.glNormal3d(n3, -n3, -n3); Gl.glTexCoord2d(5, 0); Gl.glVertex3d(largo * 100, 0, -ancho * 100);
            Gl.glNormal3d(n3, n3, -n3); Gl.glTexCoord2d(5, 6); Gl.glVertex3d(largo * 100, alto * 100, -ancho * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glTexCoord2d(0, 6); Gl.glVertex3d(largo * 100, alto * 100, 0);

            //abajo
            Gl.glNormal3d(-n3, -n3, n3); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(0, 0, 0);
            Gl.glNormal3d(n3, -n3, n3); Gl.glTexCoord2d(1, 0); Gl.glVertex3d(largo * 100, 0, 0);
            Gl.glNormal3d(n3, -n3, -n3); Gl.glTexCoord2d(1, 1); Gl.glVertex3d(largo * 100, 0, -ancho * 100);
            Gl.glNormal3d(-n3, -n3, -n3); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(0, 0, -ancho * 100);

            //frente izquierda

            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(0, 0, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d(anchoF * 100, 0, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(1, 6); Gl.glVertex3d(anchoF * 100, alto * 100, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 6); Gl.glVertex3d(0, alto * 100, 0);

            //frente derecha

            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo - anchoF) * 100, 0, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d(largo * 100, 0, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(1, 6); Gl.glVertex3d(largo * 100, alto * 100, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 6); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, 0);

            //frente arriba

            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(anchoF * 100, (alto - anchoF) * 100, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(10, 0); Gl.glVertex3d((largo - anchoF) * 100, (alto - anchoF) * 100, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(10, 1); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(anchoF * 100, alto * 100, 0);

            //frente abajo

            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(anchoF * 100, 0, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(10, 0); Gl.glVertex3d((largo - anchoF) * 100, 0, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(10, 1); Gl.glVertex3d((largo - anchoF) * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, 1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(anchoF * 100, anchoF * 100, 0);

            Gl.glEnd();

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlUtils.Texture("WOOD2"));

            Gl.glBegin(Gl.GL_QUADS);

            //marco izquierdo
            Gl.glColor3d(0.8, 0.8, 0.8);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(anchoF * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((anchoF + anchoM) * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((anchoF + anchoM) * 100, (alto - anchoF) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(anchoF * 100, (alto - anchoF) * 100, 0);

            //marco derecho
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo - anchoF - anchoM) * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo - anchoF) * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo - anchoF) * 100, (alto - anchoF) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo - anchoF - anchoM) * 100, (alto - anchoF) * 100, 0);

            //marco arriba
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((anchoF + anchoM) * 100, (alto - anchoF - anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 2); Gl.glVertex3d((largo - anchoF - anchoM) * 100, (alto - anchoF - anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 2); Gl.glVertex3d((largo - anchoF - anchoM) * 100, (alto - anchoF) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((anchoF + anchoM) * 100, (alto - anchoF) * 100, 0);

            //marco abajo
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((anchoF + anchoM) * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 2); Gl.glVertex3d((largo - anchoF - anchoM) * 100, anchoF * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 2); Gl.glVertex3d((largo - anchoF - anchoM) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((anchoF + anchoM) * 100, (anchoF + anchoM) * 100, 0);

            //marco medio
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo / 2 - anchoM / 2) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo / 2 + anchoM / 2) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo / 2 + anchoM / 2) * 100, (alto - anchoF - anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo / 2 - anchoM / 2) * 100, (alto - anchoF - anchoM) * 100, 0);

            Gl.glColor3d(0.85, 0.85, 0.85);
            //puerta izquierda
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((anchoF + anchoM) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(2, 1); Gl.glVertex3d((largo / 2 - anchoM / 2) * 100, (alto - anchoF - anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((anchoF + anchoM) * 100, (alto - anchoF - anchoM) * 100, 0);

            //puerta derecha
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo / 2 + anchoM / 2) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(2, 0); Gl.glVertex3d((largo - anchoF - anchoM) * 100, (anchoF + anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(2, 1); Gl.glVertex3d((largo - anchoF - anchoM) * 100, (alto - anchoF - anchoM) * 100, 0);
            Gl.glNormal3d(0, 0, n1); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo / 2 + anchoM / 2) * 100, (alto - anchoF - anchoM) * 100, 0);

            Gl.glEnd();

            //Knobs

            Gl.glDisable(Gl.GL_TEXTURE_2D);
            Gl.glColor3d(0.7, 0.7, 0.7);

            //izquierda
            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(-n3, -n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(-n3, n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);

            Gl.glNormal3d(n3, -n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(-n3, -n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(-n3, n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);

            Gl.glEnd();

//			Gl.glColor3d(0.1,0.15,.1);
            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(-n3, n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(-n3, -n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n3, -n3, n3); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.04) * 100, 0);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.04) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.05) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.05) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 + 0.04) * 100, 0);
            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 + 0.04) * 100, 0);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.04) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.04) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.04) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.04) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.04) * 100, (alto / 2 - 0.05) * 100, 0);
            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 - anchoM / 2 - 0.05) * 100, (alto / 2 - 0.05) * 100, 0);

            Gl.glEnd();

            //derecha
            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(-n3, -n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(-n3, n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);

            Gl.glNormal3d(n3, -n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(-n3, -n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(-n3, n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(-n3, n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(-n3, -n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n3, -n3, n3); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0.03 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.04) * 100, 0);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.04) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.05) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.05) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 + 0.04) * 100, 0);
            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 + 0.04) * 100, 0);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);

            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.04) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.04) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);

            Gl.glEnd();

            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.04) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.04) * 100, 0);
            Gl.glNormal3d(-n2, n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.04) * 100, 0);

            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0.02 * 100);
            Gl.glNormal3d(n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.05) * 100, (alto / 2 - 0.05) * 100, 0);
            Gl.glNormal3d(-n2, -n2, 0); Gl.glVertex3d((largo / 2 + anchoM / 2 + 0.04) * 100, (alto / 2 - 0.05) * 100, 0);

            Gl.glEnd();

            Gl.glColor3d(0.1, 0.15, .1);
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlUtils.Texture("AZULEJO"));

            Gl.glBegin(Gl.GL_QUADS);


            // meseta derecha
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(0, alto * 100, 0);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(6, 0); Gl.glVertex3d(largo / 2 * 100, alto * 100, 0);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(6, 5); Gl.glVertex3d(largo / 2 * 100, alto * 100, -ancho * 100);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 5); Gl.glVertex3d(0, alto * 100, -ancho * 100);


            // meseta izquierda
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, 0);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(1, 0); Gl.glVertex3d(largo * 100, alto * 100, 0);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(1, 5); Gl.glVertex3d(largo * 100, alto * 100, -ancho * 100);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 5); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, -ancho * 100);

            // meseta delante
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(largo / 2 * 100, alto * 100, 0);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(5, 0); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, 0);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(5, 1); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(largo / 2 * 100, alto * 100, -0.1 * 100);

            // meseta detras
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(largo / 2 * 100, alto * 100, (-ancho + 0.1) * 100);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(5, 0); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, (-ancho + 0.1) * 100);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(5, 1); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, -ancho * 100);
            Gl.glNormal3d(0, 1, 0); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(largo / 2 * 100, alto * 100, -ancho * 100);

            Gl.glEnd();

            Gl.glColor3d(1, 1, 1);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlUtils.Texture("ALUMINIO"));

            Gl.glBegin(Gl.GL_QUADS);

            //fregadero izquierda
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(largo / 2 * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-ancho + 0.1) * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 1); Gl.glVertex3d(largo / 2 * 100, alto * 100, (-ancho + 0.1) * 100);

            //fregadero derecha
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo - anchoF) * 100, alto * 100, (-ancho + 0.1) * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, (-ancho + 0.1) * 100);

            //fregadero detras
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-ancho + 0.1 + 0.05) * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, (-ancho + 0.1 + 0.05) * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, (-ancho + 0.1) * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-ancho + 0.1) * 100);

            //fregadero delante
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, -0.1 * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, (-0.1 - 0.05) * 100);
            Gl.glNormal3d(0, n1, 0); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-0.1 - 0.05) * 100);

            Gl.glEnd();

            //fregadero
            Gl.glColor3d(0.95, 0.95, 0.95);
            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glNormal3d(n3, n3, -n3); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, (alto - anchoF) * 100, (-0.1 - 0.05) * 100);
            Gl.glNormal3d(n3, n3, -n3); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-0.1 - 0.05) * 100);

            Gl.glNormal3d(-n3, n3, -n3); Gl.glTexCoord2d(0.4, 0); Gl.glVertex3d((largo - anchoF - 0.05) * 100, (alto - anchoF) * 100, (-0.1 - 0.05) * 100);
            Gl.glNormal3d(-n3, n3, -n3); Gl.glTexCoord2d(0.4, 1); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, (-0.1 - 0.05) * 100);

            Gl.glNormal3d(-n3, n3, n3); Gl.glTexCoord2d(0.5, 0); Gl.glVertex3d((largo - anchoF - 0.05) * 100, (alto - anchoF) * 100, (-ancho + 0.1 + 0.05) * 100);
            Gl.glNormal3d(-n3, n3, n3); Gl.glTexCoord2d(0.5, 1); Gl.glVertex3d((largo - anchoF - 0.05) * 100, alto * 100, (-ancho + 0.1 + 0.05) * 100);

            Gl.glNormal3d(n3, n3, n3); Gl.glTexCoord2d(0.9, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, (alto - anchoF) * 100, (-ancho + 0.1 + 0.05) * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glTexCoord2d(0.9, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-ancho + 0.1 + 0.05) * 100);

            Gl.glNormal3d(n3, n3, -n3); Gl.glTexCoord2d(1, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, (alto - anchoF) * 100, (-0.1 - 0.05) * 100);
            Gl.glNormal3d(n3, n3, -n3); Gl.glTexCoord2d(1, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, alto * 100, (-0.1 - 0.05) * 100);

            Gl.glEnd();

            //fondo del fregadero
            Gl.glColor3d(0.9, 0.9, 0.9);
            Gl.glBegin(Gl.GL_QUADS);

            Gl.glNormal3d(n3, n3, -n3); Gl.glTexCoord2d(0, 0); Gl.glVertex3d((largo / 2 + 0.05) * 100, (alto - anchoF) * 100, (-0.1 - 0.05) * 100);
            Gl.glNormal3d(-n3, n3, -n3); Gl.glTexCoord2d(5, 0); Gl.glVertex3d((largo - anchoF - 0.05) * 100, (alto - anchoF) * 100, (-0.1 - 0.05) * 100);
            Gl.glNormal3d(-n3, n3, n3); Gl.glTexCoord2d(5, 1); Gl.glVertex3d((largo - anchoF - 0.05) * 100, (alto - anchoF) * 100, (-ancho + 0.1 + 0.05) * 100);
            Gl.glNormal3d(n3, n3, n3); Gl.glTexCoord2d(0, 1); Gl.glVertex3d((largo / 2 + 0.05) * 100, (alto - anchoF) * 100, (-ancho + 0.1 + 0.05) * 100);

            Gl.glEnd();
            Gl.glPushMatrix();
            double tph = 10;

            Gl.glTranslated(largo * 100 / 4, Height + tph * .8, -ancho * 100 / 2);
            Gl.glRotated(30, 0, 1, 0);
            Glut.glutSolidTeapot(10);
            Gl.glPopMatrix();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Construct the ViewportState representing the current state.
 /// </summary>
 /// <param name="ctx">
 /// The <see cref="GraphicsContext"/> that specifies
 /// </param>
 public ViewportState(GraphicsContext ctx)
 {
     Gl.Get(GetPName.Viewport, _Viewport);
 }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling makes things beautiful!
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            Gl.Enable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Multisample);

            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

            // set up the projection and view matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0)));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);
            program["normalTexture"].SetValue(1);
            program["enable_mapping"].SetValue(normalMapping);

            brickDiffuse = new Texture("AlternatingBrick-ColorMap.png");
            brickNormals = new Texture("AlternatingBrick-NormalMap.png");

            Vector3[] vertices = new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),         // top
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),     // bottom
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),         // front face
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),     // back face
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),     // left
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1)
            };
            cube = new VBO <Vector3>(vertices);

            Vector2[] uvs = new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            };
            cubeUV = new VBO <Vector2>(uvs);

            List <uint> triangles = new List <uint>();

            for (uint i = 0; i < 6; i++)
            {
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 1);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4 + 3);
            }
            cubeTriangles = new VBO <uint>(triangles.ToArray(), BufferTarget.ElementArrayBuffer);

            Vector3[] normals = Geometry.CalculateNormals(vertices, triangles.ToArray());
            cubeNormals = new VBO <Vector3>(normals);

            Vector3[] tangents = CalculateTangents(vertices, normals, triangles.ToArray(), uvs);
            cubeTangents = new VBO <Vector3>(tangents);

            // load the bitmap font for this tutorial
            font        = new BMFont("font24.fnt", "font24.png");
            fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource);

            fontProgram.Use();
            fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000));
            fontProgram["color"].SetValue(new Vector3(1, 1, 1));

            information = font.CreateString(fontProgram, "OpenGL  C#  Tutorial  13");

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Ejemplo n.º 17
0
        public static void SolidCylinder(double radius, double height, int slices, int stacks)
        {
            int i, j;

            /* Step in z and radius as stacks are drawn. */

            double z0, z1;
            double zStep = height / ((stacks > 0) ? stacks : 1);

            /* Pre-computed circle */

            double[] sint, cost;

            fghCircleTable(out sint, out cost, -slices);

            /* Cover the base and top */

            //Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);
            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            Gl.glNormal3d(0.0, 0.0, -1.0);
            Gl.glVertex3d(0.0, 0.0, 0.0);

            for (j = 0; j <= slices; j++)
            {
                Gl.glVertex3d(cost[j] * radius, sint[j] * radius, 0.0);
            }

            Gl.glEnd();

            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            Gl.glNormal3d(0.0, 0.0, 1.0);
            Gl.glVertex3d(0.0, 0.0, height);

            for (j = slices; j >= 0; j--)
            {
                Gl.glVertex3d(cost[j] * radius, sint[j] * radius, height);
            }

            Gl.glEnd();

            /* Do the stacks */

            z0 = 0.0;
            z1 = zStep;

            for (i = 1; i <= stacks; i++)
            {
                if (i == stacks)
                {
                    z1 = height;
                }

                Gl.glBegin(Gl.GL_QUAD_STRIP);

                for (j = 0; j <= slices; j++)
                {
                    Gl.glNormal3d(cost[j], sint[j], 0.0);
                    Gl.glVertex3d(cost[j] * radius, sint[j] * radius, z0);
                    Gl.glVertex3d(cost[j] * radius, sint[j] * radius, z1);
                }

                Gl.glEnd();

                z0 = z1; z1 = zStep * i;
            }
            //Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            Gl.Disable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            program = new ShaderProgram(VertexShader, FragmentShader);

            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0)));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);

            glassTexture = new Texture("glass.bmp");

            cube = new VBO <Vector3>(new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),         // top
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),     // bottom
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),         // front face
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),     // back face
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),     // left
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1)
            });                                                                                                     // right
            cubeNormals = new VBO <Vector3>(new Vector3[] {
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1),
                new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0),
                new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0)
            });
            cubeUV = new VBO <Vector2>(new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            });

            cubeQuads = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer);


            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
        public void DrawSystem()
        {
            if (n > 0)
            {
                // очищаем буфер цвета
                Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

                // очищаем текущую матрицу
                Gl.glLoadIdentity();

                // устанавливаем текущий цвет - красный
                Gl.glColor3i(0, 0, 0);

                //отрисовка ограничивающего прямоугольника

                Gl.glBegin(Gl.GL_LINE);
                Gl.glVertex2d(min_x, min_y);
                Gl.glVertex2d(max_x, min_y);
                Gl.glVertex2d(max_x, max_y);
                Gl.glVertex2d(min_x, max_y);
                Gl.glEnd();


                int    i, j;
                double x1, x2, y1, y2;
                double hx5, hy5;

                //чёрточки жирные
                Gl.glLineWidth(1);
                Gl.glBegin(Gl.GL_LINES);

                //ось oy
                hx5 = hx / 5.0;
                hy5 = hy / 5.0;
                //левая часть прямоугольника
                x1 = x2 = min_x;
                double lsx;
                lsx = 11 * prx;
                x1  = x1 - lsx / 2;
                x2  = x2 + lsx / 2;

                Gl.glVertex2d((x1 + x2) / 2, min_y);
                Gl.glVertex2d((x1 + x2) / 2, max_y);

                for (j = 0; j < ny + 1; j++)
                {
                    //крупная чёрточка
                    y2 = y1 = min_y + j * hy;
                    Gl.glVertex2d(x1, y1);
                    Gl.glVertex2d(x2, y2);

                    //мелкие чёрточки
                    if (j < ny)
                    {
                        for (i = 1; i < 5; i++)
                        {
                            y2 = y1 = min_y + j * hy + i * hy5;
                            Gl.glVertex2d(min_x + lsx / 4, y1);
                            Gl.glVertex2d(min_x - lsx / 4, y2);
                        }
                    }
                }

                //правая часть прямоугольника
                x1 = x2 = max_x;
                x2 = x2 - lsx / 2;

                Gl.glVertex2d(x1, min_y);
                Gl.glVertex2d(x1, max_y);

                for (j = 0; j < ny + 1; j++)
                {
                    y2 = y1 = min_y + j * hy;
                    Gl.glVertex2d(x1, y1);
                    Gl.glVertex2d(x2, y2);

                    //мелкие чёрточки
                    if (j < ny)
                    {
                        for (i = 1; i < 5; i++)
                        {
                            y2 = y1 = min_y + j * hy + i * hy5;
                            Gl.glVertex2d(max_x - lsx / 4, y1);
                            Gl.glVertex2d(max_x, y2);
                        }
                    }
                }

                //ось ox

                //нижняя часть прямоугольника
                double lsy;
                lsy = pry * 11;
                y1  = y2 = min_y;
                y1  = y1 - lsy / 2;
                y2  = y2 + lsy / 2;
                Gl.glVertex2d(min_x, (y1 + y2) / 2);
                Gl.glVertex2d(max_x, (y1 + y2) / 2);
                for (j = 0; j < nx + 1; j++)
                {
                    x2 = x1 = min_x + j * hx;
                    Gl.glVertex2d(x1, y1);
                    Gl.glVertex2d(x2, y2);

                    //мелкие чёрточки
                    if (j < nx)
                    {
                        for (i = 1; i < 5; i++)
                        {
                            x2 = x1 = min_x + j * hx + i * hx5;
                            Gl.glVertex2d(x1, min_y - lsy / 4);
                            Gl.glVertex2d(x2, min_y + lsy / 4);
                        }
                    }
                }

                //верхняя часть прямоугольника
                y1 = y2 = max_y;
                y2 = y2 - lsy / 2;
                Gl.glVertex2d(min_x, max_y);
                Gl.glVertex2d(max_x, max_y);
                for (j = 0; j < nx + 1; j++)
                {
                    x2 = x1 = min_x + j * hx;
                    Gl.glVertex2d(x1, y1);
                    Gl.glVertex2d(x2, y2);
                    //мелкие чёрточки
                    if (j < nx)
                    {
                        for (i = 1; i < 5; i++)
                        {
                            x2 = x1 = min_x + j * hx + i * hx5;
                            Gl.glVertex2d(x1, max_y - lsy / 2);
                            Gl.glVertex2d(x2, max_y);
                        }
                    }
                }

                Gl.glEnd();

                //надписи
                //ось oy
                string value;
                int    hmark, lmark;
                hmark = Glut.glutBitmapHeight(Glut.GLUT_BITMAP_HELVETICA_18);

                x1 = min_x;
                for (j = 0; j < ny + 1; j++)
                {
                    //значение
                    y1    = min_y + j * hy - 5 * pry;
                    value = (Math.Round((min_y + j * hy), Convert.ToInt32(Math.Abs(pow_x) + 1))).ToString();
                    lmark = Glut.glutBitmapLength(Glut.GLUT_BITMAP_HELVETICA_18, value);
                    Gl.glRasterPos2d(x1 - lmark * prx - 6 * prx, y1);    // Set the position for the string (text)
                    Glut.glutBitmapString(Glut.GLUT_BITMAP_HELVETICA_18, value);
                }
                //подпись оси oy
                //y1 = min_y + j * hy - 5 * pry;
                //value = name_y;
                //lmark = Glut.glutBitmapLength(Glut.GLUT_BITMAP_HELVETICA_18, value);
                //Gl.glRasterPos2d(x1 - lmark * prx - 6 * prx, y1);    // Set the position for the string (text)
                //Glut.glutBitmapString(Glut.GLUT_BITMAP_TIMES_ROMAN_24, value);

                creatLabelY();
                LoadTexture(labelY);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
                Gl.glEnable(Gl.GL_TEXTURE_2D);
                y1 = min_y + j * hy - hy + 31 * pry;

                Gl.glColor3f(255, 255, 255);
                Gl.glBegin(Gl.GL_QUADS);
                Gl.glTexCoord2d(1, 0); Gl.glVertex2d(x1 - ddx + 128 * prx, y1 + 32 * pry);
                Gl.glTexCoord2d(1, 1); Gl.glVertex2d(x1 - ddx + 128 * prx, y1);
                Gl.glTexCoord2d(0, 1); Gl.glVertex2d(x1 - ddx, y1);
                Gl.glTexCoord2d(0, 0); Gl.glVertex2d(x1 - ddx, y1 + 32 * pry);
                Gl.glEnd();
                Gl.glDisable(Gl.GL_TEXTURE_2D);


                //ось ox
                Gl.glColor3f(0, 0, 0);
                y1 = min_y - hmark * pry;
                for (j = 0; j < nx + 1; j++)
                {
                    //значение
                    value = (Math.Round((min_x + j * hx), Convert.ToInt32(Math.Abs(pow_x) + 1))).ToString();
                    lmark = Glut.glutBitmapLength(Glut.GLUT_BITMAP_HELVETICA_18, value);
                    x1    = min_x + j * hx - 0.5 * lmark * prx;
                    Gl.glRasterPos2d(x1, y1);    // Set the position for the string (text)
                    Glut.glutBitmapString(Glut.GLUT_BITMAP_HELVETICA_18, value);
                }

                //подпись оси oх
                //creatLabelX();
                //value = name_x;
                //y1 = min_y - (hmark + Glut.glutBitmapHeight(Glut.GLUT_BITMAP_TIMES_ROMAN_24)) * pry;
                //x1 = (min_x+max_x)/2 - 7.5 * value.Count() * prx;
                //Gl.glRasterPos2d(x1, y1);    // Set the position for the string (text)
                //Glut.glutBitmapString(Glut.GLUT_BITMAP_TIMES_ROMAN_24, value);

                creatLabelX();
                LoadTexture(labelX);
                Gl.glEnable(Gl.GL_TEXTURE_2D);

                y1 = min_y - hmark * pry - 33 * pry;
                x1 = (min_x + max_x) / 2;

                Gl.glColor3f(255, 255, 255);
                Gl.glBegin(Gl.GL_QUADS);
                Gl.glTexCoord2d(1, 0); Gl.glVertex2d(x1 + 64 * prx, y1 + 31 * pry);
                Gl.glTexCoord2d(1, 1); Gl.glVertex2d(x1 + 64 * prx, y1);
                Gl.glTexCoord2d(0, 1); Gl.glVertex2d(x1 - 55 * prx, y1);
                Gl.glTexCoord2d(0, 0); Gl.glVertex2d(x1 - 55 * prx, y1 + 31 * pry);
                Gl.glEnd();
                Gl.glDisable(Gl.GL_TEXTURE_2D);
                //labelX.Save("lx.bmp");
            }
        }
Ejemplo n.º 20
0
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;
            watch.Restart();

            // perform rotation of the scene depending on keyboard input
            if (right) phi += deltaTime;
            if (left) phi -= deltaTime;
            if (up) theta += deltaTime;
            if (down) theta -= deltaTime;
            if (theta < 0) theta += (float)Math.PI * 2;

            // set up the viewport and clear the previous depth and color buffers
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // make sure the shader program and texture are being used
            Gl.UseProgram(program.ProgramID);
            Gl.BindTexture(starTexture);

            // calculate the camera position using some fancy polar co-ordinates
            Vector3 position = 20 * new Vector3((float)(Math.Cos(phi) * Math.Sin(theta)), (float)Math.Cos(theta), (float)(Math.Sin(phi) * Math.Sin(theta)));
            Vector3 upVector = ((theta % (Math.PI * 2)) > Math.PI) ? new Vector3(0, 1, 0) : new Vector3(0, -1, 0);
            program["view_matrix"].SetValue(Matrix4.LookAt(position, Vector3.Zero, upVector));

            // loop through the stars, drawing each one
            for (int i = 0; i < stars.Count; i++)
            {
                // set the position and color of this star
                program["model_matrix"].SetValue(Matrix4.CreateTranslation(new Vector3(stars[i].dist, 0, 0)) * Matrix4.CreateRotationZ(stars[i].angle));
                program["color"].SetValue(stars[i].color);

                Gl.BindBufferToShaderAttribute(star, program, "vertexPosition");
                Gl.BindBufferToShaderAttribute(starUV, program, "vertexUV");
                Gl.BindBuffer(starQuads);

                Gl.DrawElements(BeginMode.Triangles, starQuads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

                // update the position of the star
                stars[i].angle += (float)i / stars.Count * deltaTime * 2;
                stars[i].dist -= 0.2f * deltaTime;

                // if we've reached the center then move this star outwards and give it a new color
                if (stars[i].dist < 0f)
                {
                    stars[i].dist += 5f;
                    stars[i].color = new Vector3((float)generator.NextDouble(), (float)generator.NextDouble(), (float)generator.NextDouble());
                }
            }

            // bind the font program as well as the font texture
            Gl.UseProgram(fontProgram.ProgramID);
            Gl.BindTexture(font.FontTexture);

            // build this string every frame, since theta and phi can change
            FontVAO vao = font.CreateString(fontProgram, string.Format("Theta:   {0:0.000},  Phi:   {1:0.000}", theta, phi), BMFont.Justification.Right);
            vao.Position = new Vector2(width / 2 - 10, height / 2 - font.Height - 10);
            vao.Draw();
            vao.Dispose();

            // draw the tutorial information, which is static
            information.Draw();

            Glut.glutSwapBuffers();
        }
Ejemplo n.º 21
0
        private void DrawStar()
        {
            // Очистить окно просмотра
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            // Включить каркасный режим для обеих сторон звезды
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);

            // Запомнить первоначальное состояние матрицы вращения
            Gl.glPushMatrix();

            // Выполнить два последовательных поворота
            // для будущей визуализации сцены
            Gl.glRotatef(xRot, 1.0f, 0.0f, 0.0f);
            Gl.glRotatef(yRot, 0.0f, 1.0f, 0.0f);

            //************  Рисовать внутренние контуры звезды  *************
            // Рисовать веер треугольников
            Gl.glBegin(Gl.GL_TRIANGLES);
            // Устанавливаем переключатель метки сторон
            Gl.glEdgeFlag(_isEdge);

            // Устанавливаем вершины
            Gl.glVertex2f(0.0f, 0.0f); // Центр звезды
            Gl.glVertex2f(-18.0f, 26.0f);
            Gl.glVertex2f(18.0f, 26.0f);

            Gl.glVertex2f(0.0f, 0.0f);
            Gl.glVertex2f(18.0f, 26.0f);
            Gl.glVertex2f(30.0f, -10.0f);

            Gl.glVertex2f(0.0f, 0.0f);
            Gl.glVertex2f(30.0f, -10.0f);
            Gl.glVertex2f(0.0f, -32.0f);

            Gl.glVertex2f(0.0f, 0.0f);
            Gl.glVertex2f(0.0f, -32.0f);
            Gl.glVertex2f(-30.0f, -10.0f);

            Gl.glVertex2f(0.0f, 0.0f);
            Gl.glVertex2f(-30.0f, -10.0f);
            Gl.glVertex2f(-18.0f, 26.0f);
            Gl.glEnd();

            //***********  Рисовать внешние треугольники звезды **************
            Gl.glBegin(Gl.GL_TRIANGLES);
            Gl.glEdgeFlag(1);
            Gl.glVertex2f(-18.0f, 26.0f);
            Gl.glVertex2f(0.0f, 80.0f); Gl.glEdgeFlag(0);
            Gl.glVertex2f(18.0f, 26.0f);

            Gl.glEdgeFlag(1);
            Gl.glVertex2f(18.0f, 26.0f);
            Gl.glVertex2f(80.0f, 26.0f); Gl.glEdgeFlag(0);
            Gl.glVertex2f(30.0f, -10.0f);

            Gl.glEdgeFlag(1);
            Gl.glVertex2f(30.0f, -10.0f);
            Gl.glVertex2f(50.0f, -68.0f); Gl.glEdgeFlag(0);
            Gl.glVertex2f(0.0f, -32.0f);

            Gl.glEdgeFlag(1);
            Gl.glVertex2f(0.0f, -32.0f);
            Gl.glVertex2f(-50.0f, -68.0f); Gl.glEdgeFlag(0);
            Gl.glVertex2f(-30.0f, -10.0f);

            Gl.glEdgeFlag(1);
            Gl.glVertex2f(-30.0f, -10.0f);
            Gl.glVertex2f(-80.0f, 26.0f); Gl.glEdgeFlag(0);
            Gl.glVertex2f(-18.0f, 26.0f);
            Gl.glEnd();

            // Восстанавливаем измененные состояния в исходные значения
            Gl.glPopMatrix();
            Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_FILL);
        }
Ejemplo n.º 22
0
 static void FramebufferSizeCallback(Glfw.Window window, int width, int height)
 {
     Log("Framebuffer resized to {0}x{1}", width, height);
     Gl.Viewport(0, 0, width, height);
 }
Ejemplo n.º 23
0
        //------------------------------------------------------------------------------
        // render
        public void render(Vectors[][] point, int m, int n, bool texture)
        {
            if (!_valid)
            {
                _valid = true;
                matrices(point, m, n);
                vertices();
                normals();
            }
            double r = (double)_u / (double)(m - 2);
            double g = (double)_v / (double)(n - 2);
            double b = (1.0 - r) * (1.0 - g);

            float[] white     = { 1.0f, 1.0f, 1.0f, 1.0f };
            float[] ambient   = { (float)r, (float)g, (float)b, 1.0f };
            float[] diffuse   = { (float)r, (float)g, (float)b, 1.0f };
            float[] specular  = { 0.5f, 0.5f, 0.5f, 1.0f };
            float   shininess = 10.0f;

            float[] emission = { 0.0f, 0.0f, 0.0f, 0.0f };
            if (texture)
            {
                Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, white);
                Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, white);
            }
            else
            {
                Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, ambient);
                Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, diffuse);
            }
            Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR, specular);
            Gl.glMaterialf(Gl.GL_FRONT_AND_BACK, Gl.GL_SHININESS, shininess);
            Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, emission);
            if (texture)
            {
                Gl.glEnable(Gl.GL_TEXTURE_2D);
            }
            Gl.glBegin(Gl.GL_QUADS);
            for (int i = 0; i < _tiles; i++)
            {
                for (int j = 0; j < _tiles; j++)
                {
                    int      u = _u * _tiles + j;
                    int      v = _v * _tiles + i;
                    double[] point1;
                    Gl.glTexCoord2d((double)u / (double)((m - 1) * _tiles),
                                    (double)v / (double)((n - 1) * _tiles));
                    Gl.glNormal3dv(_normal[i][j].toDouble3(out point1));
                    Gl.glVertex3dv(_vertex[i][j].toDouble3(out point1));
                    u++;
                    Gl.glTexCoord2d((double)u / (double)((m - 1) * _tiles),
                                    (double)v / (double)((n - 1) * _tiles));
                    Gl.glNormal3dv(_normal[i][j + 1].toDouble3(out point1));
                    Gl.glVertex3dv(_vertex[i][j + 1].toDouble3(out point1));
                    v++;
                    Gl.glTexCoord2d((double)u / (double)((m - 1) * _tiles),
                                    (double)v / (double)((n - 1) * _tiles));
                    Gl.glNormal3dv(_normal[i + 1][j + 1].toDouble3(out point1));
                    Gl.glVertex3dv(_vertex[i + 1][j + 1].toDouble3(out point1));
                    u--;
                    Gl.glTexCoord2d((double)u / (double)((m - 1) * _tiles),
                                    (double)v / (double)((n - 1) * _tiles));
                    Gl.glNormal3dv(_normal[i + 1][j].toDouble3(out point1));
                    Gl.glVertex3dv(_vertex[i + 1][j].toDouble3(out point1));
                    v--;
                }
            }
            Gl.glEnd();
            Gl.glDisable(Gl.GL_TEXTURE_2D);
        }
Ejemplo n.º 24
0
        static void TestModes(Glfw.Monitor monitor)
        {
            Glfw.Window window;
            var modes = Glfw.GetVideoModes(monitor);

            for (int i = 0; i < modes.Length; i++)
            {
                var mode = modes[i];
                Glfw.VideoMode current;

                Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits);
                Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits);
                Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits);
                Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate);

                Log("Testing mode {0} on monitor {1}: {2}", i, Glfw.GetMonitorName(monitor), FormatMode(mode));

                window = Glfw.CreateWindow(mode.Width, mode.Height,
                                          "Video Mode Test",
                                          Glfw.GetPrimaryMonitor(),
                                          Glfw.Window.None);
                if (!window)
                {
                    Log("Failed to enter mode {0}: {1}", i, FormatMode(mode));
                    continue;
                }

                Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback);
                Glfw.SetKeyCallback(window, KeyCallback);

                Glfw.MakeContextCurrent(window);
                Glfw.SwapInterval(1);

                Glfw.SetTime(0.0);

                while (Glfw.GetTime() < 5.0)
                {
                    Gl.Clear(ClearBufferMask.ColorBufferBit);
                    Glfw.SwapBuffers(window);
                    Glfw.PollEvents();

                    if (Glfw.WindowShouldClose(window))
                    {
                        Log("User terminated program");

                        Glfw.Terminate();
                        Environment.Exit(0);
                    }
                }

                Gl.Get(GetPName.RedBits, out current.RedBits);
                Gl.Get(GetPName.GreenBits, out current.GreenBits);
                Gl.Get(GetPName.BlueBits, out current.BlueBits);

                Glfw.GetWindowSize(window, out current.Width, out current.Height);

                if (current.RedBits != mode.RedBits ||
                    current.GreenBits != mode.GreenBits ||
                    current.BlueBits != mode.BlueBits)
                {
                    Log("*** Color bit mismatch: ({0} {1} {2}) instead of ({3} {4} {5})\n",
                        current.RedBits, current.GreenBits, current.BlueBits,
                        mode.RedBits, mode.GreenBits, mode.BlueBits);
                }

                if (current.Width != mode.Width || current.Height != mode.Height)
                {
                    Log("*** Size mismatch: %ix%i instead of %ix%i\n",
                        current.Width, current.Height,
                        mode.Width, mode.Height);
                }

                Log("Closing window");

                Glfw.DestroyWindow(window);
                Glfw.PollEvents();
            }
        }
Ejemplo n.º 25
0
        public void Destroy()
        {
            var id = this.GlId;

            Gl.glDeleteTextures(1, ref id);
        }
Ejemplo n.º 26
0
        private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            /*  Gl.glBegin(Gl.GL_LINE_STRIP);
             * for (double x = 0.0; x < 4.0; x += 0.005) //每隔0.005取樣一次
             * {
             *    double fx = Math.Exp(-x) * Math.Cos(2.0 * Math.PI * x);
             *    Gl.glVertex2d(x, fx);
             * }
             * Gl.glEnd();*/
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluOrtho2D(0.0, 4.0, -1.0, 1.0); //正常圖形
            Gl.glViewport(0, 0, simpleOpenGlControl1.Size.Width / 2, simpleOpenGlControl1.Size.Height / 2);
            //繪製函數f(x)的圖形
            Gl.glBegin(Gl.GL_LINE_STRIP);
            for (double x = 0.0; x < 4.0; x += 0.005) //每隔0.005取樣一次
            {
                double fx = Math.Exp(-x) * Math.Cos(2.0 * Math.PI * x);
                Gl.glVertex2d(x, fx);
            }
            Gl.glEnd();


            Gl.glLoadIdentity();
            Glu.gluOrtho2D(0.0, 4.0, 1.0, -1.0); //上下顛倒
            Gl.glViewport(simpleOpenGlControl1.Size.Width / 2, 0, simpleOpenGlControl1.Size.Width / 2, simpleOpenGlControl1.Size.Height / 2);
            //繪製函數f(x)的圖形
            Gl.glBegin(Gl.GL_LINE_STRIP);
            for (double x = 0.0; x < 4.0; x += 0.005) //每隔0.005取樣一次
            {
                double fx = Math.Exp(-x) * Math.Cos(2.0 * Math.PI * x);
                Gl.glVertex2d(x, fx);
            }
            Gl.glEnd();



            Gl.glLoadIdentity();
            Glu.gluOrtho2D(4.0, 0.0, -1.0, 1.0); //左右顛倒
            Gl.glViewport(0, simpleOpenGlControl1.Size.Height / 2, simpleOpenGlControl1.Size.Width / 2, simpleOpenGlControl1.Size.Height / 2);
            //繪製函數f(x)的圖形
            Gl.glBegin(Gl.GL_LINE_STRIP);
            for (double x = 0.0; x < 4.0; x += 0.005) //每隔0.005取樣一次
            {
                double fx = Math.Exp(-x) * Math.Cos(2.0 * Math.PI * x);
                Gl.glVertex2d(x, fx);
            }
            Gl.glEnd();



            Gl.glLoadIdentity();
            Glu.gluOrtho2D(4.0, 0.0, 1.0, -1.0); //上下左右都顛倒
            Gl.glViewport(this.simpleOpenGlControl1.Size.Width / 2, simpleOpenGlControl1.Size.Height / 2, simpleOpenGlControl1.Size.Width / 2, simpleOpenGlControl1.Size.Height / 2);
            //繪製函數f(x)的圖形
            Gl.glBegin(Gl.GL_LINE_STRIP);
            for (double x = 0.0; x < 4.0; x += 0.005) //每隔0.005取樣一次
            {
                double fx = Math.Exp(-x) * Math.Cos(2.0 * Math.PI * x);
                Gl.glVertex2d(x, fx);
            }
            Gl.glEnd();
        }
Ejemplo n.º 27
0
 private void RestoreOpenGl()
 {
     //Gl.PopAttrib();
     Gl.MatrixMode(MatrixMode.Projection);
     Gl.LoadIdentity();
 }
Ejemplo n.º 28
0
 private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program)
 {
     Gl.Viewport(_Viewport[0], _Viewport[1], _Viewport[2], _Viewport[3]);
 }
Ejemplo n.º 29
0
 public void Bind(Texture texture)
 {
     GlHelper.ThrowNullException(Target);
     Gl.BindTexture(Target, texture.Id);
     GlHelper.GetError();
 }
Ejemplo n.º 30
0
 public void Use()
 {
     Gl.UseProgram(Id);
 }