Esempio n. 1
0
        public Torus3D(Vector3 position, float scale, Color4 color, int textureId = 0)
            : base()
        {
            Bounding = new Bounding(this, scale);

            Model = @"Models\Torus.xml";

            if (vid is VertexsIndicesData)
            {
                VertexsIndicesData = vid;
            }
            else
            {
                vid = Tools.DeserializeModel(Model);

                VertexsIndicesData = vid;
            }


            Scale(scale);

            Position = position;

            FirstPosition = Position;

            ShapeVersorsUVW = Matrix4.Identity;

            TextureID = textureId;

            if (textureId == 0)
            {
                foreach (Vertex vertex in VertexsIndicesData.Vertexs)
                {
                    vertex.Color = color;
                }

                // initialize shaders
                string vs = File.ReadAllText("Shaders\\vShader_Color_Normal_Torus.txt");
                string fs = File.ReadAllText("Shaders\\fShader_Color_Normal_Torus.txt");
                Shader = new Shader(ref vs, ref fs, this);
                // initialize buffer
                VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_COLOR;
                VertexBuffer = new VertexFloatBuffer(VertexFormat, 7650, BeginMode.Triangles);
            }
            else
            {
                // initialize shaders
                string vs = File.ReadAllText("Shaders\\vShader_UV_Normal.txt");
                string fs = File.ReadAllText("Shaders\\fShader_UV_Normal_sphere.txt");
                Shader = new Shader(ref vs, ref fs, this);
                // initialize buffer
                VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_UV_COLOR;
                VertexBuffer = new VertexFloatBuffer(VertexFormat, 7650);
            }
        }
Esempio n. 2
0
        public Sphere3DEnvCubeMap(Vector3 position, float r) : base()
        {
            this.r = r;

            Bounding = new Bounding(this, r * 1.5f);

            if (vid is VertexsIndicesData)
            {
                VertexsIndicesData = vid;
            }
            else
            {
                vid = Tools.DeserializeModel(@"Models\sphere3D64x64x1.xml");
                //vid = Tools.DeserializeModel(@"Models\cube3D1x1.xml");
                VertexsIndicesData = vid;
            }


            Model = @"Models\Sphere3D.xml";

            //RotateU(MathHelper.PiOver2);

            Scale(r);

            Position = position;

            ShapeVersorsUVW = Matrix4.Identity;

            //GL.Disable(EnableCap.Texture2D);

            //GL.Enable(EnableCap.TextureCubeMap);

            // create cubemap

            int cubemapTexture = 0;

            cubemapTexture = GL.GenTexture();
            TextureID      = cubemapTexture;
            GL.BindTexture(TextureTarget.TextureCubeMap, cubemapTexture);
            //GL.TexStorage2D(TextureTarget2d.TextureCubeMap, 0, SizedInternalFormat.Rgba8, textSize, textSize);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            foreach (TextureTarget target in new TextureTarget[] {
                TextureTarget.TextureCubeMapPositiveX,
                TextureTarget.TextureCubeMapNegativeX,
                TextureTarget.TextureCubeMapPositiveY,
                TextureTarget.TextureCubeMapNegativeY,
                TextureTarget.TextureCubeMapPositiveZ,
                TextureTarget.TextureCubeMapNegativeZ,
            })
            {
                GL.TexImage2D(target, 0, PixelInternalFormat.Rgba8, textSize, textSize, 0,
                              PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            }

            // create FBO
            textureCubeFBO = new int[6];

            for (int i = 0; i < 6; i++)
            {
                GL.GenFramebuffers(1, out textureCubeFBO[i]);
            }

            GL.GenRenderbuffers(1, out textureCubeDepth);

            for (int i = 0; i < 6; i++)
            {
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, textureCubeFBO[i]);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt,
                                        FramebufferAttachment.ColorAttachment0Ext, TextureTarget.TextureCubeMapPositiveX, cubemapTexture, 0);

                GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, textureCubeDepth);
                GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, (RenderbufferStorage)All.DepthComponent24, textSize, textSize);
                GL.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt,
                                           RenderbufferTarget.RenderbufferExt, textureCubeDepth);
            }


            GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
            GL.BindTexture(TextureTarget.TextureCubeMap, 0);

            // initialize shaders
            string vs = File.ReadAllText("Shaders\\vShader_UV_Normal_CubeMap.txt");
            string fs = File.ReadAllText("Shaders\\fShader_UV_Normal_CubeMap.txt");

            Shader = new Shader(ref vs, ref fs, this);
            // initialize buffer
            VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL;
            VertexBuffer = new VertexFloatBuffer(VertexFormat, 97920);
        }