Exemplo n.º 1
2
        public override void Draw3D(OpenGL gl)
        {
            float drawCoord = (int)(y * 2) % pieces;

            float size = 2;
            double theta = 0;
            if (fever)
            {
                size = 3f;
                if (xpos < -4)
                    theta = (xpos + 4) * Math.PI / 4;
                else if (xpos > 4)
                    theta = (xpos - 4) * Math.PI / 4;
            }

            gl.Begin(BeginMode.Quads);
            {
                if (fever)
                    gl.Color(1.0f, 0.5f, 0.5f);
                gl.TexCoord(drawCoord / pieces, 1);
                gl.Vertex(xpos * 0.5f - (0.4f * size) * Math.Cos(theta), y - (0.4f * size) * Math.Sin(theta), 0);
                gl.TexCoord(drawCoord / pieces, 0);
                gl.Vertex(xpos * 0.5f - (0.4f * size) * Math.Cos(theta), y - (0.4f * size) * Math.Sin(theta), size);
                gl.TexCoord((drawCoord + 1) / pieces, 0);
                gl.Vertex(xpos * 0.5f + (0.4f * size) * Math.Cos(theta), y + (0.4f * size) * Math.Sin(theta), size);
                gl.TexCoord((drawCoord + 1) / pieces, 1);
                gl.Vertex(xpos * 0.5f + (0.4f * size) * Math.Cos(theta), y + (0.4f * size) * Math.Sin(theta), 0);
                gl.Color(1.0f, 1.0f, 1.0f);
            }
            gl.End();
        }
Exemplo n.º 2
0
Arquivo: VAO.cs Projeto: rho24/OpenCAD
        public VAO(OpenGL gl, IShaderProgram program, VBO vbo)
        {
            _gl = gl;
            _program = program;
            VBO = vbo;

            var buffers = new uint[1];
            gl.GenVertexArrays(1, buffers);
            Handle = buffers[0];

            using (new Bind(program))
            using (new Bind(this))
            using (new Bind(vbo))
            {
                var stride = Vect3f.SizeInBytes * 2 + Vect4f.SizeInBytes;

                gl.EnableVertexAttribArray(0);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, true, stride, IntPtr.Zero);
                gl.BindAttribLocation(program.Handle, 0, "vert_position");

                gl.EnableVertexAttribArray(1);
                gl.VertexAttribPointer(1, 3, OpenGL.GL_FLOAT, true, stride, new IntPtr(Vect3f.SizeInBytes));
                gl.BindAttribLocation(program.Handle, 1, "vert_normal");

                gl.EnableVertexAttribArray(2);
                gl.VertexAttribPointer(2, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(Vect3f.SizeInBytes * 2));
                gl.BindAttribLocation(program.Handle, 2, "vert_colour");
            }
        }
Exemplo n.º 3
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();

            gl.LookAt(0, 20, 30, 0, 0, 0, 0, 1, 0);

            //desenha o piso
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            grass.Bind(gl);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-100.0f, 0.0f, -100.0f);
            gl.TexCoord(100.0f, 0.0f); gl.Vertex(100.0f, 0.0f, -100.0f);
            gl.TexCoord(100.0f, 100.0f); gl.Vertex(100.0f, 0.0f, 100.0f);
            gl.TexCoord(0.0f, 100.0f); gl.Vertex(-100.0f, 0.0f, 100.0f);
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);

            foreach (Polygon polygon in polygons)
            {
                polygon.PushObjectSpace(gl);
                polygon.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
                polygon.PopObjectSpace(gl);
            }

            gl.Flush();
        }
        public void RenderWithStruct(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode)
        {
            //if (!this.IsRenderable())
            //return;

            ShaderProgram shader = this.shader; //GetShader(gl, renderMode);

            shader.Bind(gl);

            // 用VAO+EBO进行渲染。
            //  Bind the out vertex array.
            //gl.BindVertexArray(vao[0]);
            gl.BindVertexArray(vertexArrayObject);
            //  Draw the square.
            //gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, ebo[0]);
            gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.triangleBufferObject);

            // 启用Primitive restart
            gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
            gl.PrimitiveRestartIndex(uint.MaxValue);// 截断图元(四边形带、三角形带等)的索引值。
            gl.DrawElements(this.primitiveMode, this.triangleIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);

            //  Unbind our vertex array and shader.
            gl.BindVertexArray(0);
            gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);

            shader.Unbind(gl);
        }
Exemplo n.º 5
0
        public DatumPlaneLeaf(OpenGL gl, IShaderProgram shader, IEnumerable<DatumPlane> planes)
        {
            _gl = gl;
            _shader = shader;
            var linedata = new List<Vert>();
            var quaddata = new List<Vert>();

            const float size = 20f;
            foreach (var plane in planes)
            {

                var v1 = (plane.Transform * Mat4.Translate(new Vect3(-size / 2.0, -size / 2.0, 0))).ToVect3();
                var v2 = (plane.Transform * Mat4.Translate(new Vect3(size / 2.0, -size / 2.0, 0))).ToVect3();
                var v3 = (plane.Transform * Mat4.Translate(new Vect3(size / 2.0, size / 2.0, 0))).ToVect3();
                var v4 = (plane.Transform * Mat4.Translate(new Vect3(-size / 2.0, size / 2.0, 0))).ToVect3();

                linedata.Add(new Vert(v1, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v2, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v2, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v3, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v3, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v4, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v4, Vect3.Zero, _edgecolour));
                linedata.Add(new Vert(v1, Vect3.Zero, _edgecolour));

                quaddata.AddRange(new[] { new Vert(v1, Vect3.Zero, _basecolour), new Vert(v2, Vect3.Zero, _basecolour), new Vert(v3, Vect3.Zero, _basecolour), new Vert(v4, Vect3.Zero, _basecolour) });
                quaddata.AddRange(new[] { new Vert(v4, Vect3.Zero, _basecolour), new Vert(v3, Vect3.Zero, _basecolour), new Vert(v2, Vect3.Zero, _basecolour), new Vert(v1, Vect3.Zero, _basecolour) });

            }
            _lineVAO = new VAO(gl, _shader, new VBO(gl, BeginMode.Lines, linedata));
            _quadVAO = new VAO(gl, _shader, new VBO(gl, BeginMode.Quads, quaddata));
        }
Exemplo n.º 6
0
        public FormSharpGLTexturesSample()
        {
            InitializeComponent();

            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            //  A bit of extra initialisation here, we have to enable textures.
            gl.Enable(OpenGL.GL_TEXTURE_2D);

            //  Create our texture object from a file. This creates the texture for OpenGL.
            texture.Create(gl, "Crate.bmp");

            //  Create a light.

            /*
             * Light light = new Light()
             * {
             *  On = true,
             *  Position = new Vertex(0, 0, 0),
             *  GLCode = OpenGL.GL_LIGHT0
             * };
             */

            //Camera numbers set up
            float fov           = 70.0f,
                  aspect        = (float)openGLControl1.Width / (float)openGLControl1.Height,
                  zNear         = 0.1f,
                  zFar          = 100.0f;
            Vertex eyeVertex    = new Vertex(2.0f, 2.0f, 2.0f);
            Vertex centerVertex = new Vertex(0.0f, 0.0f, 0.0f);
            Vertex upVertex     = new Vertex(0.0f, 1.0f, 0.0f);

            cam = new Camera(gl, fov, aspect, zNear, zFar, eyeVertex, centerVertex, upVertex);
        }
Exemplo n.º 7
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            gl.PushAttrib(AttributeMask.Lighting);
            gl.Translate(position.x, position.y + 1 * scaleKoef, position.z);
            gl.Scale(scaleKoef, scaleKoef, scaleKoef);

            gl.Color(color.GetInArrWithAlpha());

            float[] specular1 = { 1, 1, 1, 1 };
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_SPECULAR, specular1);
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_SHININESS, 60);
            gl.Material(OpenGL.GL_FRONT, OpenGL.GL_SHININESS, 128);

            for (int i = 0; i < 20; i++)
            {
                subdivine(gl,
                          new Vector3d(vdata[tindices[i][0]]),
                          new Vector3d(vdata[tindices[i][1]]),
                          new Vector3d(vdata[tindices[i][2]]),
                          divineCount);
            }
            gl.PopAttrib();
            gl.PopMatrix();
        }
Exemplo n.º 8
0
        public static void DrawDetectRectRegion(SharpGL.OpenGL gl_object, DetectedRectRegion DetectField, double ColorR, double ColorG, double ColorB)
        {
            gl_object.LoadIdentity();
            gl_object.Translate(_LX, _LY, _LZ);
            gl_object.Rotate(_RoX, 0.0, 1.0, 0.0);
            gl_object.Rotate(_RoY, 1.0, 0.0, 0.0);
            gl_object.Rotate(_RoZ, 0.0, 0.0, 1.0);

            //畫範圍
            gl_object.Color(ColorR, ColorG, ColorB);
            gl_object.Begin(OpenGL.GL_LINE_STRIP);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY1, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY1, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY2, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY2, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY1, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY1, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY1, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY1, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY1, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY2, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY2, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX2, DetectField.DetectRegionY2, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY2, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY2, DetectField.DetectRegionZ1);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY2, DetectField.DetectRegionZ2);
            gl_object.Vertex(DetectField.DetectRegionX1, DetectField.DetectRegionY1, DetectField.DetectRegionZ2);
            gl_object.End();
        }
Exemplo n.º 9
0
        private void CreateDisplayList(OpenGL gl)
        {
            displayList = new DisplayList();

            displayList.Generate(gl);
            displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);

            //Push all attributes, disable lighting and depth testing.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.DepthFunc(OpenGL.GL_ALWAYS);

            //Set line width.
            gl.LineWidth(lineWidth);

            //Draw the line.
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(Convert.ColorToGLColor(c1));
            gl.Vertex(v1.X, v1.Y, v1.Z);
            gl.Color(Convert.ColorToGLColor(c2));
            gl.Vertex(v2.X, v2.Y, v2.Z);
            gl.End();

            //  Restore attributes.
            gl.PopAttrib();

            displayList.End(gl);
        }
Exemplo n.º 10
0
 public override void Draw(SharpGL.OpenGL gl)
 {
     gl.PushAttrib(AttributeMask.All);
     gl.PushMatrix();
     if (texture != null)
     {
         gl.Enable(OpenGL.GL_TEXTURE_2D);
         texture.Push(gl);
     }
     gl.Begin(BeginMode.Quads);
     {
         gl.Color(color.GetInArrWithAlpha());
         gl.Normal(0, 1, 0);
         gl.TexCoord(0, 0);
         gl.Vertex(position.x - lenByX / 2, position.y, position.z + lenByZ / 2);
         gl.TexCoord(lenByX, 0);
         gl.Vertex(position.x + lenByX / 2, position.y, position.z + lenByZ / 2);
         gl.TexCoord(lenByX, lenByZ);
         gl.Vertex(position.x + lenByX / 2, position.y, position.z - lenByZ / 2);
         gl.TexCoord(0, lenByZ);
         gl.Vertex(position.x - lenByX / 2, position.y, position.z - lenByZ / 2);
     }
     gl.End();
     if (texture != null)
     {
         texture.Pop(gl);
     }
     gl.PopMatrix();
     gl.PopAttrib();
 }
Exemplo n.º 11
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            if (_trail > 1)
            {
                for (int t = 0; t < _trail; t++)
                {
                    PointFloat   trailPos  = GetPosition();
                    PointFloat   vel       = GetVelocity();
                    PointFloat   dit       = new PointFloat(trailPos.x - vel.x * t, trailPos.y - vel.y * t);
                    PointFloat[] pointData = RenderLogics.RectPoint(dit, GetSize(), GetRotation());

                    GetTexture().UseTexure(gl);
                    gl.Begin(OpenGL.GL_QUADS);
                    byte[] col = GetColor();
                    gl.Color(col[0], col[1], col[2]);
                    gl.TexCoord(0, 0);
                    gl.Vertex(pointData[1].x, pointData[1].y);
                    gl.TexCoord(0, 1);
                    gl.Vertex(pointData[0].x, pointData[0].y);
                    gl.TexCoord(1, 1);
                    gl.Vertex(pointData[3].x, pointData[3].y);
                    gl.TexCoord(1, 0);
                    gl.Vertex(pointData[2].x, pointData[2].y);
                    gl.End();
                }
            }
            base.Draw(gl);
        }
Exemplo n.º 12
0
        public static void Draw(OpenGL gl, double height, double length, double width)
        {
            gl.LineWidth(1);
            gl.Color(0.7, 0.7, 0.7);
            gl.Begin(OpenGL.GL_LINE_LOOP);
            gl.Vertex(0, height, 0 );
            gl.Vertex(0, height, width);
            gl.Vertex(length, height, width);
            gl.Vertex(length, height, 0 );
            gl.End();

            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0, height, 0);
            gl.Vertex(0, 0, 0);

            gl.Vertex(length, height, 0);
            gl.Vertex(length, 0, 0);

            gl.Vertex(0, height, width);
            gl.Vertex(0, 0, width);

            gl.Vertex(length, height, width);
            gl.Vertex(length, 0, width);
            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            gl.Vertex(0, 0, 0);
            gl.Vertex(0, 0, width);
            gl.Vertex(length, 0, width);
            gl.Vertex(length, 0, 0);
            gl.End();
        }
Exemplo n.º 13
0
        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            if (positionBuffer != null && colorBuffer != null && radiusBuffer != null)
            {
                if (this.shaderProgram == null)
                {
                    this.shaderProgram = InitShader(gl, renderMode);
                }
                if (this.vertexArrayObject == null)
                {
                    CreateVertexArrayObject(gl, renderMode);
                }

                BeforeRendering(gl, renderMode);

                if (this.RenderGrid && this.vertexArrayObject != null)
                {
                    gl.Enable(OpenGL.GL_BLEND);
                    gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                    gl.BindVertexArray(this.vertexArrayObject[0]);
                    gl.DrawArrays(OpenGL.GL_POINTS, 0, count);
                    gl.BindVertexArray(0);

                    gl.Disable(OpenGL.GL_BLEND);
                }

                AfterRendering(gl, renderMode);
            }
        }
Exemplo n.º 14
0
 private void RenderVertices_VertexArray(OpenGL gl)
 {
     gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
     gl.VertexPointer(3, 0, vertexArrayValues);
     gl.DrawArrays(OpenGL.GL_POINTS, 0, 2);//vertices.Length);
     gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
 }
Exemplo n.º 15
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            //Process alignment in baseclass
            base.Draw(gl);

            //Draw arms
            _arm1.Draw(gl);
            _arm2.Draw(gl);
            _arm3.Draw(gl);

            //Draw middle triangle. At each vertex of this triangle two arms meet.
            //So for color merging we will give each vertex the average color of the two
            //adjacent arms - precalculated in constructor

            gl.Begin(SharpGL.Enumerations.BeginMode.Triangles);

            gl.Color(_vertex32.R, _vertex32.G, _vertex32.B);
            gl.Vertex(_arm3.Corner1.x, _arm3.Corner1.y);

            gl.Color(_vertex21.R, _vertex21.G, _vertex21.B);
            gl.Vertex(_arm1.Corner4.x, _arm1.Corner4.y);

            gl.Color(_vertex13.R, _vertex13.G, _vertex13.B);
            gl.Vertex(_arm1.Corner1.x, _arm1.Corner1.y);



            gl.End();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initialises the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="width">The width of the screen.</param>
        /// <param name="height">The height of the screen.</param>
        public void Initialise(OpenGL gl, float width, float height)
        {
            //  Set a blue clear colour.
            gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);

            //  Create the shader program.
            var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
            shaderProgram = new ShaderProgram();
            shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
            shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
            shaderProgram.AssertValid(gl);

            //  Create a perspective projection matrix.
            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
            projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);

            //  Create a view matrix to move us back a bit.
            viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));

            //  Create a model matrix to make the model a little bigger.
            modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));

            //  Now create the geometry for the square.
            CreateVerticesForSquare(gl);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initialises the Scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void Initialise(OpenGL gl)
        {
            //  We're going to specify the attribute locations for the position and normal, 
            //  so that we can force both shaders to explicitly have the same locations.
            const uint positionAttribute = 0;
            const uint normalAttribute = 1;
            var attributeLocations = new Dictionary<uint, string>
            {
                {positionAttribute, "Position"},
                {normalAttribute, "Normal"},
            };

            //  Create the per pixel shader.
            shaderPerPixel = new ShaderProgram();
            shaderPerPixel.Create(gl, 
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), attributeLocations);
            
            //  Create the toon shader.
            shaderToon = new ShaderProgram();
            shaderToon.Create(gl,
                ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.frag"), attributeLocations);
            
            //  Generate the geometry and it's buffers.
            trefoilKnot.GenerateGeometry(gl, positionAttribute, normalAttribute);
        }
Exemplo n.º 18
0
 public void InitTexture(OpenGL gl)
 {
     _texture = new SharpGL.SceneGraph.Assets.Texture();
     _texture.Create(gl, _image);
     Id = _texture.TextureName;
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, _texture.TextureName);
 }
Exemplo n.º 19
0
        void setCamera(SharpGL.OpenGL gl)
        {
            //OpenGL gl = openGLControl.OpenGL;

            //  设置当前矩阵模式,对投影矩阵应用随后的矩阵操作
            gl.MatrixMode(OpenGL.GL_PROJECTION);

            // 重置当前指定的矩阵为单位矩阵,将当前的用户坐标系的原点移到了屏幕中心
            gl.LoadIdentity();

            // 创建透视投影变换
            gl.Perspective(30.0f, (double)Width / (double)Height, 0.05, 1000.0);

            //增加移动代码
            // double dRad = dAngleXY / 180 * 3.1415926;
            double dRad = dAngleXY / 180 * 3.1415926;
            double dx   = vEye.dx + 100 * Math.Cos(dRad);
            double dy   = vEye.dy + 100 * Math.Sin(dRad);

            vLookAt.dx = dx;
            vLookAt.dy = dy;

            // 视点变换
            gl.LookAt(vEye.dx, vEye.dy, vEye.dz, vLookAt.dx, vLookAt.dy, vLookAt.dz, vUp.dx, vUp.dy, vUp.dz);

            // 设置当前矩阵为模型视图矩阵
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
Exemplo n.º 20
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.LoadIdentity();

            gl.Translate(-1.5f, 0f, -6f);

            gl.Begin(OpenGL.GL_TRIANGLES);
            {
                gl.Vertex(0.0f, 1.0f, 0.0f);
                gl.Vertex(-1.0f, -1.0f, 0.0f);
                gl.Vertex(1.0f, -1.0f, 0.0f);
            }
            gl.End();

            gl.Translate(3f, 0f, 0f);

            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.Vertex(-1.0f, 1.0f, 0.0f);
                gl.Vertex(1.0f, 1.0f, 0.0f);
                gl.Vertex(1.0f, -1.0f, 0.0f);
                gl.Vertex(-1.0f, -1.0f, 0.0f);
            }
            gl.End();
            gl.Flush();
        }
Exemplo n.º 21
0
        public void DrawSprite(float posX, float posY, Sprite sprite, OpenGL gl)
        {
            float[] verts = {
                posX, posY,
                posX + 32, posY,
                posX + 32, posY + 32,
                posX, posY + 32
            };
            float tw = sprite.spriteWidth;
            float th = sprite.spriteHeight;
            float tx = sprite.spriteX;
            float ty = sprite.spriteY;
            float[] texVerts = {
                tx, ty,
                tx + tw, ty,
                tx + tw, ty + th,
                tx, ty + th
            };

            gl.Color(1.0, 1.0, 1.0, 1.0); // reset gl color
            tex.Bind(gl);

            gl.Begin(OpenGL.GL_QUADS);
            gl.TexCoord(texVerts[0], texVerts[1]); gl.Vertex(verts[0], verts[1], 0.0f);	// Bottom Left Of The Texture and Quad
            gl.TexCoord(texVerts[2], texVerts[3]); gl.Vertex(verts[2], verts[3], 0.0f);	// Bottom Right Of The Texture and Quad
            gl.TexCoord(texVerts[4], texVerts[5]); gl.Vertex(verts[4], verts[5], 0.0f);	// Top Right Of The Texture and Quad
            gl.TexCoord(texVerts[6], texVerts[7]); gl.Vertex(verts[6], verts[7], 0.0f);	// Top Left Of The Texture and Quad
            gl.End();

            //this is sposed to be better but doesnt seem to work
            //gl.VertexPointer(2, OpenGL.GL_FLOAT, 0, verts);
            //gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 0, texVerts);
            //gl.DrawArrays(OpenGL.GL_TRIANGLE_STRIP,0,4);
        }
Exemplo n.º 22
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);


            gl.Color(1.0f, 1.0f, 1.0f);

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();

            cam.Look();

            gl.Disable(OpenGL.GL_TEXTURE_2D);
            PlaneSurfaceRenderer psr = new PlaneSurfaceRenderer(16);

            psr.render(gl);


            texture.Bind(gl);
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            foreach (ShapeRenderer shape in listShape)
            {
                shape.render(gl);
            }
        }
Exemplo n.º 23
0
 public void paint(OpenGL gl)
 {
     gl.Color(1f, 1f, 1f);
     gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
         gl.Vertex(x, y + height, 0);
         gl.Vertex(x, y, 0);
         gl.Vertex(x+width, y + height, 0);
         gl.Vertex(x+width, y, 0);
     gl.End();
     gl.LineWidth(1);
     gl.Begin(OpenGL.GL_LINES);
     gl.Color(0, 0, 0);
         if (centerCoordinateX <= x + width && centerCoordinateX >= x)
         {
             gl.Vertex4d(centerCoordinateX, y, 0, 1);
             gl.Vertex4d(centerCoordinateX, y + height, 0, 1);
         }
         if (centerCoordinateY <= y + height && centerCoordinateY >= y)
         {
             gl.Vertex4d(x, centerCoordinateY, 0, 1);
             gl.Vertex4d(x+width, centerCoordinateY, 0, 1);
         }
     gl.End();
     for(int i = 0; i < functions.Count; i++)
     {
         drawFunction(gl, functions.ElementAt(i));
     }
 }
Exemplo n.º 24
0
        public BackgroundShader(OpenGL gl)
            : base(gl)
        {
            _program = new ShaderProgram();
            var vertex = new VertexShader();
            var fragment = new FragmentShader();

            vertex.CreateInContext(gl);
            vertex.SetSource(File.ReadAllText("Shaders/Background.vert.glsl"));
            vertex.Compile();

            fragment.CreateInContext(gl);
            fragment.SetSource(File.ReadAllText("Shaders/Background.frag.glsl"));
            fragment.Compile();

            _program.CreateInContext(gl);
            _program.AttachShader(vertex);
            _program.AttachShader(fragment);
            _program.Link();

            Debug.WriteLine(_program.InfoLog);
            foreach (var attachedShader in _program.AttachedShaders)
            {
                Debug.WriteLine(attachedShader.InfoLog);
            }
        }
Exemplo n.º 25
0
        public Shader(OpenGL gl, string vertexShaderSource, string fragmentShaderSource,
            Dictionary<uint, string> attributeLocations)
        {
            this.gl = gl;

            Compiled = false;
            CompilerOutput = null;

            shader = new SharpGL.Shaders.ShaderProgram();
            try
            {
                shader.Create(gl, vertexShaderSource, fragmentShaderSource, attributeLocations);
            }
            catch (SharpGL.Shaders.ShaderCompilationException ex)
            {
                CompilerOutput = ex.CompilerOutput;
                return;
            }

            try
            {
                shader.AssertValid(gl);
            }
            catch (Exception ex)
            {
                CompilerOutput = ex.Message;
                return;
            }

            Compiled = true;
        }
Exemplo n.º 26
0
 public override void Render(OpenGL gl)
 {
     if (displayList == null)
         CreateDisplayList(gl);
     else
         displayList.Call(gl);
 }
Exemplo n.º 27
0
        public void drawEnemy(SharpGL.OpenGL gl)
        {
            switch (enemyType)
            {
            case 1:
                texture.Create(gl, "..\\..\\gem1.png");
                break;

            case 2:
                texture.Create(gl, "..\\..\\gem2.png");
                break;

            case 3:
                texture.Create(gl, "..\\..\\gem3.png");
                break;

            case 4:
                texture.Create(gl, "..\\..\\gem4.png");
                break;
            }
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -19.0f);
            gl.Begin(OpenGL.GL_QUADS);

            gl.TexCoord(0, 0); gl.Vertex(positionX - 1, positionY);
            gl.TexCoord(1, 0); gl.Vertex(positionX, positionY);
            gl.TexCoord(1, 1); gl.Vertex(positionX, positionY - 1);
            gl.TexCoord(0, 1); gl.Vertex(positionX - 1, positionY - 1);
            gl.End();
            gl.PopMatrix();
        }
Exemplo n.º 28
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            //float defaultHeight = 0.3f * 3 + 0.2f;
            gl.PushMatrix();
            gl.Translate(position.x, position.y, position.z);
            gl.Rotate(-90, 1, 0, 0);
            gl.Scale(scaleKoef, scaleKoef, scaleKoef);
            //gl.Color(color.GetInArr());
            //float curHeight = 0.25f;

            //gl.Cylinder(gl.NewQuadric(), curHeight / 2, curHeight / 2, curHeight, 20, 20);
            //gl.Translate(0, 0, 0.25f);
            //curHeight = 5f / 14f;
            //gl.Cylinder(gl.NewQuadric(), curHeight, 0, curHeight, 20, 20);
            //gl.Translate(0, 0, 0.25f);
            //curHeight = 4f / 14f;
            //gl.Cylinder(gl.NewQuadric(), curHeight, 0, curHeight, 20, 20);
            //gl.Translate(0, 0, 0.25f);
            //curHeight = 3f / 14f;
            //gl.Cylinder(gl.NewQuadric(), curHeight, 0, curHeight, 20, 20);
            gl.Color(trunkColor.GetInArrWithAlpha());
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE, trunkColor.GetInArrWithAlpha());
            gl.Cylinder(gl.NewQuadric(), 0.1, 0.1, 0.4, 20, 20);
            gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE, color.GetInArrWithAlpha());
            gl.Color(color.GetInArrWithAlpha());
            gl.Translate(0, 0, 0.2);
            gl.Cylinder(gl.NewQuadric(), 0.5, 0, 0.5, 20, 20);
            gl.Translate(0, 0, 0.3);
            gl.Cylinder(gl.NewQuadric(), 0.4, 0, 0.4, 20, 20);
            gl.Translate(0, 0, 0.3);
            gl.Cylinder(gl.NewQuadric(), 0.3, 0, 0.3, 20, 20);

            gl.PopMatrix();
        }
Exemplo n.º 29
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            gl.PushAttrib(AttributeMask.All);
            gl.PushClientAttrib(OpenGL.GL_CLIENT_ALL_ATTRIB_BITS);

            gl.VertexPointer(3, 0, vertexs);
            gl.NormalPointer(OpenGL.GL_FLOAT, 0, normals);
            gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 0, texCoord);

            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            gl.EnableClientState(OpenGL.GL_NORMAL_ARRAY);
            gl.EnableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);

            gl.Translate(position.x, position.y + sizeY / 2, position.z);

            gl.Color(color.GetInArrWithAlpha());

            DrawArrayWithTexture(gl, OpenGL.GL_QUADS, 0, 4, textureZplus);   //z+
            DrawArrayWithTexture(gl, OpenGL.GL_QUADS, 4, 4, textureYplus);   //y+
            DrawArrayWithTexture(gl, OpenGL.GL_QUADS, 8, 4, textureZminus);  //z-
            DrawArrayWithTexture(gl, OpenGL.GL_QUADS, 12, 4, textureYminus); //y-
            DrawArrayWithTexture(gl, OpenGL.GL_QUADS, 16, 4, textureXminus); //x-
            DrawArrayWithTexture(gl, OpenGL.GL_QUADS, 20, 4, texture);       //x+

            gl.PopClientAttrib();
            gl.PopAttrib();
            gl.PopMatrix();
        }
Exemplo n.º 30
0
        static void ArrowShaftCylinder(SharpGL.OpenGL gl, float r_Arrow_shaft_cylinder, float cyl_height, double step, double zscale)
        {
            double stopper = Math.PI - step;

            for (double i = 0.0; i < stopper; i += step)
            {
                float       x = r_Arrow_shaft_cylinder * ( float )Math.Sin(i);
                float       y = r_Arrow_shaft_cylinder * ( float )Math.Cos(i);
                const float z = 0.0f;

                float x0 = x;
                float y0 = y;
                float z0 = cyl_height * ( float )zscale;

                double i0 = i + step;

                float       x1 = r_Arrow_shaft_cylinder * ( float )Math.Sin(i0);
                float       y1 = r_Arrow_shaft_cylinder * ( float )Math.Cos(i0);
                const float z1 = 0.0f;

                float x2 = x1;
                float y2 = y1;
                float z2 = cyl_height * ( float )zscale;

                float [] Vertex0 = { x, y, z };
                float [] Vertex1 = { x0, y0, z0 };
                float [] Vertex2 = { x1, y1, z1 };
                float [] Vertex3 = { x2, y2, z2 };
                //Triangle . Draw ( gl , Vertex0 , Vertex1 , Vertex2 , true , false );
                //Triangle . Draw ( gl , Vertex1 , Vertex2 , Vertex3 , false , false );
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Creates the display list. This function draws the
        /// geometry as well as compiling it.
        /// </summary>
        void CreateDisplayList(SharpGL.OpenGL gl)
        {
            //  Create the display list.
            this.displayList = new DisplayList();

            //  Generate the display list and
            this.displayList.Generate(gl);
            this.displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);

            //  Push attributes, set the color.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                          OpenGL.GL_LINE_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.LineWidth(1.0f);

            //  Draw the grid lines.
            gl.Begin(SharpGL.OpenGL.GL_LINES);
            for (int i = -10; i <= 10; i++)
            {
                float fcol = ((i % 10) == 0) ? 0.3f : 0.15f;
                gl.Color(fcol, fcol, fcol);
                gl.Vertex(i, -10, 0);
                gl.Vertex(i, 10, 0);
                gl.Vertex(-10, i, 0);
                gl.Vertex(10, i, 0);
            }
            gl.End();

            //  Restore attributes.
            gl.PopAttrib();

            //  End the display list.
            this.displayList.End(gl);
        }
Exemplo n.º 32
0
        public static void LocalAxis(SharpGL.OpenGL gl)
        {
            double[] Reddish  = { 0.9, 0.3, 0.4 };
            double[] Greenish = { 0.1, 0.8, 0.3 };
            double[] Bluish   = { 0.1, 0.2, 0.8 };

            gl.PushAttrib(SharpGL.OpenGL.GL_LIGHTING);
            gl.Disable(SharpGL.OpenGL.GL_LIGHTING);
            gl.LineWidth(3);

            gl.Color(Reddish);
            gl.Begin(SharpGL.Enumerations.BeginMode.LineLoop);
            gl.Vertex(0f, 0f, 0f);
            gl.Vertex(1f, 0f, 0f);
            gl.End( );

            gl.Color(Greenish);
            gl.Begin(SharpGL.Enumerations.BeginMode.LineLoop);
            gl.Vertex(0f, 0f, 0f);
            gl.Vertex(0f, 1f, 0f);
            gl.End( );

            gl.Color(Bluish);
            gl.Begin(SharpGL.Enumerations.BeginMode.LineLoop);
            gl.Vertex(0f, 0f, 0f);
            gl.Vertex(0f, 0f, 1f);
            gl.End( );

            gl.PopAttrib( );
        }
        /// <summary>
        /// Draw a BuildingObjectLib3DS object.
        /// </summary>
        /// <param name="gl">Opengl handler.</param>
        /// <param name="buildingObj">The BuildingObjectLib3DS object.</param>
        public void DrawBuildingPart(OpenGL gl, BuildingObjectLib3DS buildingObj, DrawType type)
        {
            // Return when the input object is null
            if (buildingObj == null)
                return;

            // Draw all the children when type is Building, Floor or room. Or draw a Object.
            switch (buildingObj.GetBuildingType())
            {
                case BuildingObjectType.Building:
                case BuildingObjectType.Floor:
                case BuildingObjectType.Room:
                    foreach (BuildingObjectLib3DS child in buildingObj.GetChilds().Values)
                    {
                        DrawBuildingPart(gl, child, type);
                    }
                    break;
                case BuildingObjectType.Outside:
                case BuildingObjectType.Object:
                    DrawObject(gl, buildingObj, type);
                    break;
                default:
                    break;
            }
        }
Exemplo n.º 34
0
 public void InitTextures(OpenGL gl)
 {
     gl.GenerateMipmapEXT(OpenGL.GL_TEXTURE_2D);
     foreach(ImageTexture tex in _textures){
         tex.InitTexture(gl);
     }
 }
Exemplo n.º 35
0
 public override void Draw(SharpGL.OpenGL gl)
 {
     base.Draw(gl);
     if (_data == null)
     {
     }
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
     gl.Begin(OpenGL.GL_QUAD_STRIP);
     for (int i = 0; i < _data.Length; i++)
     {
         gl.Color(_data[i], _data[i], _data[i]);
         _x = ((GetSize().x / 256f) * i) + CamController.X - (GetSize().x / 2f);
         gl.Vertex(_x, GetPosition().y + _data[i] * _height);
         //gl.Vertex(_x, GetPosition().y + _data[i] * _height - 1.0f);
         gl.Vertex(_x, GetPosition().y);
     }
     gl.End();
     gl.Begin(OpenGL.GL_QUAD_STRIP);
     for (int i = 0; i < _data.Length; i++)
     {
         gl.Color(_data[i] - 0.5f, _data[i] - 0.5f, _data[i] - 0.5f);
         _x = ((GetSize().x / 256f) * i) + CamController.X - (GetSize().x / 2f);
         gl.Vertex(_x, GetPosition().y - _data[i] * _height / 10.0f);
         //gl.Vertex(_x, GetPosition().y + _data[i] * _height - 1.0f);
         gl.Color(_data[i], _data[i], _data[i]);
         gl.Vertex(_x, GetPosition().y);
     }
     gl.End();
 }
Exemplo n.º 36
0
 public void PushObjectSpace(OpenGL gl)
 {
     gl.PushMatrix();
     gl.Translate(pos.X, pos.Y, pos.Z);
     if (material != null)
         material.Push(gl);
 }
Exemplo n.º 37
0
        private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            //  Clear and load the identity.
            gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);
            gl.LoadIdentity();

            //  View from a bit away the y axis and a few units above the ground.
            gl.LookAt(0, -5, 3, 0, 0, 0, 0, 1, 0);

            //  Rotate the objects every cycle.
            gl.Rotate(rotate, 0.0f, 0.0f, 1.0f);

            //  Move the objects down a bit so that they fit in the screen better.
            gl.Translate(0, 0, -1);

            //  Draw some axies.
            gl.StockDrawing.Axies.Call(gl);

            //  Draw every polygon in the collection.
            foreach (Polygon polygon in polygons)
            {
                polygon.Draw(gl);
            }

            //  Rotate a bit more each cycle.
            rotate += 1.0f;
        }
Exemplo n.º 38
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            float halfSize = size / 2;

            gl.Translate(position.x, position.y + halfSize, position.z);
            gl.Color(color.GetInArrWithAlpha());
            Point3D[] vertex = new Point3D[]
            {
                new Point3D(halfSize, halfSize, halfSize),
                new Point3D(-halfSize, halfSize, halfSize),
                new Point3D(-halfSize, -halfSize, halfSize),
                new Point3D(halfSize, -halfSize, halfSize),
                new Point3D(halfSize, halfSize, -halfSize),
                new Point3D(-halfSize, halfSize, -halfSize),
                new Point3D(-halfSize, -halfSize, -halfSize),
                new Point3D(halfSize, -halfSize, -halfSize)
            };
            DrawPrimitive.Quard(gl, vertex[0], vertex[1], vertex[2], vertex[3], false);
            DrawPrimitive.Quard(gl, vertex[0], vertex[4], vertex[5], vertex[1], false);
            DrawPrimitive.Quard(gl, vertex[7], vertex[6], vertex[5], vertex[4], false);
            DrawPrimitive.Quard(gl, vertex[3], vertex[2], vertex[6], vertex[7], false);
            DrawPrimitive.Quard(gl, vertex[1], vertex[5], vertex[6], vertex[2], false);
            DrawPrimitive.Quard(gl, vertex[0], vertex[3], vertex[7], vertex[4], false);
            gl.PopMatrix();
        }
Exemplo n.º 39
0
        public void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode)
        {
            // update matrix and bind shader program
            mat4 projectionMatrix = camera.GetProjectionMat4();

            mat4 viewMatrix = camera.GetViewMat4();

            mat4 modelMatrix = glm.scale(mat4.identity(), new vec3(1, 1, this.ZAxisScale));

            shaderProgram.Bind(gl);

            shaderProgram.SetUniformMatrix4(gl, strprojectionMatrix, projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, strviewMatrix, viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, strmodelMatrix, modelMatrix.to_array());

            gl.BindVertexArray(vao[0]);

            // 启用Primitive restart
            gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
            gl.PrimitiveRestartIndex(uint.MaxValue);// 截断图元(四边形带、三角形带等)的索引值。

            //GL.DrawArrays(primitiveMode, 0, vertexCount);
            gl.DrawElements((uint)primitiveMode, vertexCount + (this.pipe.Count - 1) * 2, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);

            gl.BindVertexArray(0);

            gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);

            // unbind shader program
            shaderProgram.Unbind(gl);
        }
Exemplo n.º 40
0
        /// <summary>
        /// Предполагается, что текущая матрица видовая.
        /// (Modelview)
        /// </summary>
        /// <param name="gl"></param>
        public void Draw(SharpGL.OpenGL gl)
        {
            //! свет важно задавать после установки видовой матрицы!
            light0.Draw();
            light1.Draw();
            if (ShowAxis)
            {
                axis.Draw(gl);
            }
            if (ShowGrid)
            {
                grid.Draw(gl);
            }
            //версия с отражением от пола
            //gl.PushMatrix();
            //gl.PushAttrib(AttributeMask.All);
            //gl.Scale(1, -1, 1);
            //gl.FrontFace(OpenGL.GL_CW);
            //figs.ForEach(x => x.Draw(gl));
            //gl.PopMatrix();
            //gl.Enable(OpenGL.GL_BLEND);
            //gl.FrontFace(OpenGL.GL_CCW);
            //(new Ground(new ColorF(0.5f, 0.5f, 0.5f, 0.8f), new Point3D(0, 0, 0), 200, 200)).Draw(gl);
            //gl.PopAttrib();

            //без отражения
            figs.ForEach(x => x.Draw(gl));
        }
Exemplo n.º 41
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            gl.PushAttrib(AttributeMask.All);
            gl.PushClientAttrib(OpenGL.GL_CLIENT_ALL_ATTRIB_BITS);

            gl.VertexPointer(3, 0, vertexs);
            gl.NormalPointer(OpenGL.GL_FLOAT, 0, normals);
            gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 0, texCoord);

            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            //gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
            gl.EnableClientState(OpenGL.GL_NORMAL_ARRAY);
            gl.EnableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);

            gl.Translate(position.x, position.y + sizeY / 2, position.z);

            gl.Color(color.GetInArrWithAlpha());

            if (texture != null)
            {
                gl.Enable(OpenGL.GL_TEXTURE_2D);
                texture.Bind(gl);
            }
            else
            {
                gl.Disable(OpenGL.GL_TEXTURE_2D);
            }

            gl.DrawArrays(OpenGL.GL_QUADS, 0, 24);

            gl.PopClientAttrib();
            gl.PopAttrib();
            gl.PopMatrix();
        }
Exemplo n.º 42
0
        //rysowanie siatki
        private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
            gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);

            gl.LoadIdentity();
            gl.Translate(0, 0, tz);
            gl.Rotate(rotX, 1, 0, 0);
            gl.Rotate(rotZ, 0, 0, 1);


            gl.Begin(OpenGL.TRIANGLES);
            gl.Color(1, 0, 0, 1);
            int multt = 1;

            gl.Vertex((minY - (heightArray.Length / 2)) * multt, (minX - (heightArray.Length / 2)) * multt, heightArray[minY][minX]);
            gl.Vertex((minY - (heightArray.Length / 2)) * multt, (minX + 1 - (heightArray.Length / 2)) * multt, heightArray[minY + 1][minX]);
            gl.Vertex((minY + 1 - (heightArray.Length / 2)) * multt, (minX - (heightArray.Length / 2)) * multt, heightArray[minY][minX + 1]);

            gl.End();

            gl.Color(1, 1, 1, 1);
            gl.Begin(OpenGL.LINES);
            for (int i = 0; i < heightArray.Length - 1; i++)
            {
                for (int j = 0; j < heightArray[0].Length - 1; j++)
                {
                    DrawTriangle(gl, i, j);
                }
            }
            gl.End();
        }
Exemplo n.º 43
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gl">OpenGLControl.OpenGL</param>
        /// <param name="camera"></param>
        public SimLabGrid(OpenGL gl, IScientificCamera camera)
        {
            if (gl == null || camera == null) { throw new ArgumentNullException(); }

            this.gl = gl;
            this.camera = camera;
        }
Exemplo n.º 44
0
        public TileSetEditor()
        {
            InitializeComponent();

            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl1 = this.openGLControl1.OpenGL;
            SharpGL.OpenGL gl2 = this.openGLControl2.OpenGL;
            //  A bit of extra initialisation here, we have to enable textures.
            gl1.Enable(OpenGL.GL_TEXTURE_2D);
            gl2.Enable(OpenGL.GL_TEXTURE_2D);

            //transparancy crap needs to work at somepoint
            //gl1.Enable(OpenGL.GL_BLEND);
            //gl1.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
            //gl1.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA, imgWidth, imgHeight, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE,);

            openGLControl1.MouseClick += HandleMouseClick1;
            openGLControl2.MouseClick += HandleMouseClick2;
            //openGLControl2.MouseDown += HandleMouseDown; Deal with this crap later
            //openGLControl2.MouseUp += HandleMouseUp;

            tileSet.ChangeTileSetSize(100);

            hScrollBar1.Visible = false;
            vScrollBar1.Visible = false;

            hScrollBar2.Visible = false;
            vScrollBar2.Visible = false;
        }
Exemplo n.º 45
0
        private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
        {
            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            //  We need to load the texture from file.
            textureImage = new Bitmap("Crate.bmp");

            //  A bit of extra initialisation here, we have to enable textures.
            gl.Enable(OpenGL.GL_TEXTURE_2D);

            //  Get one texture id, and stick it into the textures array.
            gl.GenTextures(1, textures);

            //  Bind the texture.
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);

            //  Tell OpenGL where the texture data is.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE,
                          textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height),
                                                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);

            //  Specify linear filtering.
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
        }
Exemplo n.º 46
0
        //-------------------------------------
        public override void ConvertPrimitive(I3DPrimitive primitive, SharpGL.OpenGL gl)
        {
            C3DPrimitiveQuad quad = primitive as C3DPrimitiveQuad;

            if (quad == null || quad.Points == null || quad.Points.Length != 4)
            {
                return;
            }
            for (int nTmp = 0; nTmp < 2; nTmp++)
            {
                if (nTmp == 0)
                {
                    gl.PolygonMode(OpenGL.FRONT_AND_BACK, OpenGL.FILL);
                    gl.Color(GetComposantsCouleur(quad.Couleur));
                }
                else
                {
                    gl.PolygonMode(OpenGL.FRONT_AND_BACK, OpenGL.LINE);
                    gl.Color(0.0f, 0.0f, 0.0f, 1.0f);
                }

                gl.Material(OpenGL.FRONT_AND_BACK, OpenGL.SPECULAR, GetComposantsCouleur(quad.Couleur));
                gl.Material(OpenGL.FRONT_AND_BACK, OpenGL.SHININESS, 100.0f);

                gl.Begin(OpenGL.QUADS);
                //Fond
                //gl.Normal3f(0f, 0f, -1.0f);
                for (int n = 0; n < 4; n++)
                {
                    gl.Vertex(quad.Points[n].X, quad.Points[n].Y, quad.Points[n].Z);
                }

                gl.End();
            }
        }
Exemplo n.º 47
0
        public FormExample2()
        {
            InitializeComponent();

            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            //  We need to load the texture from file.
            textureImage = new Bitmap("Crate.bmp");

            //  A bit of extra initialisation here, we have to enable textures.
            gl.Enable(OpenGL.TEXTURE_2D);

            //  Get one texture id, and stick it into the textures array.
            gl.GenTextures(1, textures);

            //  Bind the texture.
            gl.BindTexture(OpenGL.TEXTURE_2D, textures[0]);

            //  Tell OpenGL where the texture data is.
            gl.TexImage2D(OpenGL.TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.RGB, OpenGL.UNSIGNED_BYTE,
                          textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height),
                                                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);

            gl.TexParameter(OpenGL.TEXTURE_2D, OpenGL.TEXTURE_MIN_FILTER, OpenGL.LINEAR);               // Linear Filtering
            gl.TexParameter(OpenGL.TEXTURE_2D, OpenGL.TEXTURE_MAG_FILTER, OpenGL.LINEAR);               // Linear Filtering
        }
Exemplo n.º 48
0
        private void openGLControl2_Load(object sender, EventArgs e)
        {
            this.openGLControl2.OpenGLDraw += new System.Windows.Forms.PaintEventHandler(this.openGLControl2_OpenGLDraw);

            SharpGL.OpenGL gl = this.openGLControl2.OpenGL;
            gl.Color(0.0f, 0.0f, 0.0f);
        }
Exemplo n.º 49
0
        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.LookAt(camera.eyex, camera.eyey, camera.eyez, camera.centerx, camera.centery, camera.centerz, 0, 1, 0);

            /*gl.LookAt(
             *  2, 2, 2,
             *  0, 0, 0,
             *  0, 1, 0);*/

            //gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);
            ShowGrid(gl);
            if (isDrawCube)
            {
                drawCube(gl);
            }
            else if (isDrawPyramid)
            {
                drawPyramid(gl);
            }
            else if (isDrawPrism)
            {
                drawPrism(gl);
            }
            rtri += 1.0f;
        }
        public LinesBase(OpenGL gl, List<Tuple<vec3, vec3>> lines, Material material = null, OGLModelUsage usage = OGLModelUsage.StaticRead)
        {
            var verts = new vec3[lines.Count * 2];
            var normals = new vec3[lines.Count * 2];
            var indices = new uint[lines.Count * 2];

            for (int i = 0; i < lines.Count; i++)
            {
                var i2 = i * 2;
                verts[i2] = lines[i].Item1;
                verts[i2 + 1] = lines[i].Item2;

                normals[i2] = new vec3(1, 1, 1);
                normals[i2 + 1] = new vec3(1, 1, 1);

                indices[i2] = (uint)i2;
                indices[i2 + 1] = (uint)(i2 + 1);
            }

            if (material != null)
                Material = material;

            Vertices = verts;
            Normals = normals;
            Indices = indices;
            GlDrawMode = OpenGL.GL_LINES;

            if (gl != null)
                GenerateGeometry(gl, usage);
        }
Exemplo n.º 51
0
        public static void Initialize(OpenGL gl)
        {
            ShaderManager.gl = gl;

            vertexShaders = new Dictionary<string, VertexShader>();
            geometryShaders = new Dictionary<string, GeometryShader>();
            fragmentShaders = new Dictionary<string, FragmentShader>();
        }
        private static void InitView(OpenGLControl control, OpenGL gl)
        {
            gl.MatrixMode(MatrixMode.Projection);
            gl.LoadIdentity();
            gl.Ortho(0, control.ActualWidth, control.ActualHeight, 0, -10, 10);

            gl.MatrixMode(MatrixMode.Modelview);
        }
Exemplo n.º 53
0
 private void DrawTrefoilVertices(OpenGL gl)
 {
     //  Render each vertex.
     gl.Begin(BeginMode.Points);
     foreach(var vertex in trefoilKnot.Vertices)
         gl.Vertex(vertex);
     gl.End();
 }
Exemplo n.º 54
0
        public Shader(OpenGL gl, uint shaderType, string name, string source)
        {
            Name = name;
            Source = source;

            ID = gl.CreateShader(shaderType);
            gl.ShaderSource(ID, Source);
            gl.CompileShader(ID);
        }
Exemplo n.º 55
0
 public uint CreateShader(OpenGL gl, string source, uint mode)
 {
     uint shaderId = gl.CreateShader(mode);
     gl.ShaderSource(shaderId, source);
     gl.CompileShader(shaderId);
     StringBuilder glError = new StringBuilder();
     gl.GetShaderInfoLog(shaderId, 1000, new IntPtr(), glError);
     return shaderId;
 }
Exemplo n.º 56
0
 public override void OnResize(OpenGL gl, int width, int height)
 {
     if (width == -1 || height == -1) return;
     using (new Bind(_shader))
     {
         _camera.Resize(width, height);
         gl.UniformMatrix4(_projectionUniform, 1, false, _camera.Projection.ToColumnMajorArray());
     }
 }
Exemplo n.º 57
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationState"/> class.
        /// </summary>
        private ApplicationState()
        {
            //  Create the OpenGL instance.
            OpenGL = new OpenGL();

            //  Initialise the OpenGL instance.
            OpenGL.Create(RenderContextType.FBO,
                800, 600, 24, null);
        }
        /// <summary>
        /// Create and add a new ShaderProgram from the given sources. 
        /// Call this function if you decide to add your own shaders.
        /// </summary>
        /// <param name="gl">The OpenGL</param>
        /// <param name="vertexShaderSource">The path to the vertex shader code.</param>
        /// <param name="fragmentShaderSource">The path to the fragment shader code.</param>
        /// <param name="shaderName">The name for the shader.</param>
        public static ExtShaderProgram CreateShader(OpenGL gl, IShaderParameterIds parameters, string vertexShaderSource, string fragmentShaderSource)
        {
            //  Create the per pixel shader.
            ShaderProgram shader = new ShaderProgram();
            shader.Create(gl,
                ManifestResourceLoader.LoadTextFile(vertexShaderSource),
                ManifestResourceLoader.LoadTextFile(fragmentShaderSource), _attributeLocations);

            return new ExtShaderProgram(shader, parameters);
        }
Exemplo n.º 59
0
        private static string getProgramInfoLog(OpenGL gl, uint programHandle)
        {
            int[] logLength = new int[1];
            gl.GetProgram(programHandle, OpenGL.GL_INFO_LOG_LENGTH, logLength);

            StringBuilder log = new StringBuilder(logLength[0]);
            gl.GetProgramInfoLog(programHandle, logLength[0], IntPtr.Zero, log);

            return log.ToString();
        }
Exemplo n.º 60
-29
 /// <summary>
 /// Function to draw the model
 /// </summary>
 private void drawModel(OpenGL gl) 
 {
     if(l_vboId != null)
     {
         gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
         gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
         // itering over each list of points
         for(int k = 0; k < l_vboId.Count; k++)
         {
             gl.PushMatrix();
                 //transformations
                 gl.Scale(1.0f / f_scale, 1.0f / f_scale, 1.0f / f_scale);
                 gl.Translate(-v_center.X, -v_center.Y, -v_center.Z);
                 //vertexes
                 gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][0]);
                 gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
                 //color
                 gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][1]);
                 gl.ColorPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
                 //draw l_sizes[k] points
                 gl.DrawArrays(OpenGL.GL_POINTS, 0, l_sizes[k]);
             gl.PopMatrix();
         }
         gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
         gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
         gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
     }
 }