Beispiel #1
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.FrontFace(OpenGL.GL_CCW);

            gl.PushMatrix();
            gl.LookAt(0, 0, m_sceneDistance + 150, 0, 0, 0, 0, 1, 0);
            gl.Translate(TranslateX, TranslateY, -m_sceneDistance);
            gl.Rotate(m_xRotation, 1.0f, 0.0f, 0.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);


            //gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_DECAL);


            /*
             * gl.PushMatrix();
             * gl.PointSize(50.0f);
             * gl.Translate(0, 0, 0);
             * gl.Begin(OpenGL.GL_POINTS);
             * gl.Color(0.0f, 1.0f, 0.0f);
             * gl.Vertex(0.0f, 0.0f, 0.0f);
             * gl.End();
             * gl.PopMatrix();
             */


            //tackasto
            gl.PushMatrix();
            Cube cube = new Cube();

            float[] poz = new float[] { -300.0f, 180.0f, 0.0f, 1.0f };
            gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, poz);
            gl.Translate(poz[0], poz[1], poz[2]);
            gl.Scale(10.0f, 10.0f, 10.0f);
            gl.Color(0.0f, 0.0f, 1.0f);
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            /*
             * //reflektor
             * gl.PushMatrix();
             * Cube reflekt = new Cube();
             * float[] light1pos = new float[] {0f, 180f, -215f, 1.0f };
             * float[] light1diffuse = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
             * float[] light1ambient = new float[] { 0f, 1f, 0f, 1.0f };
             * gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_POSITION, light1pos);
             * gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_AMBIENT, light1ambient);
             * gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_DIFFUSE, light1diffuse);
             * gl.Translate(0.0f, 120.0f, -225f);
             * gl.Scale(10.0f, 10.0f, 10.0f);
             * gl.Color(1.0f, 0.0f, 0.0f);
             * reflekt.Render(gl, RenderMode.Render);
             * gl.PopMatrix();
             */


            gl.PushMatrix();
            Cube reflekt = new Cube();

            SetReflektor(gl);
            gl.Translate(0.0f, 180.0f, -225f);
            gl.Scale(10.0f, 10.0f, 10.0f);
            gl.Color(1.0f, 0.0f, 0.0f);
            reflekt.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            #region Floor + Walls
            gl.PushMatrix(); //Pod
            gl.Enable(OpenGL.GL_TEXTURE_2D);

            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Floor]);
            gl.LoadIdentity();
            gl.Scale(3, 7, 7);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);


            gl.Translate(0, -50, 0);
            gl.Scale(300, 180, 250);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Normal(0f, 1f, 0f);  //Pod
            gl.Color(0.30f, 0.15f, 0.0f);
            gl.TexCoord(1f, 1f);
            gl.Vertex(-1.0f, -1.0f, -1.0f);
            gl.TexCoord(0f, 1f);
            gl.Vertex(-1.0f, -1.0f, 1.0f);
            gl.TexCoord(0f, 0f);
            gl.Vertex(1.0f, -1.0f, 1.0f);
            gl.TexCoord(1f, 0f);
            gl.Vertex(1.0f, -1.0f, -1.0f);
            gl.End();

            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.LoadIdentity();
            gl.Scale(1, 1, 1);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.PopMatrix();

            //Zidovi
            gl.PushMatrix();
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Brick]);
            gl.Translate(0, -50, 0);
            gl.Scale(300, 180, 250);

            gl.Begin(OpenGL.GL_QUADS);
            gl.Color(0.556863f, 0.419608f, 0.137255f); //Nazad zid
            gl.Normal(0f, 0f, 1f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(-1, -1, -1); //leva dole daleko
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(1, -1, -1);  //desna dole daleko
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(1, 1, -1);   //desna gore daleko
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(-1, 1, -1);  //leva gore daleko
            gl.End();

            gl.Begin(OpenGL.GL_QUADS);
            gl.Color(0.556863f, 0.419608f, 0.137255f); //Desni zid
            gl.Normal(-1f, 0f, 0f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(1.0f, 1.0f, -1.0f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(1.0f, -1.0f, -1.0f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(1.0f, -1.0f, 1.0f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(1.0f, 1.0f, 1.0f);
            gl.End();

            gl.Begin(OpenGL.GL_QUADS);
            gl.Color(0.556863f, 0.419608f, 0.137255f); //Levi zid
            gl.Normal(1f, 0f, 0f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(-1, 1, 1);   //levo gore blizu
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(-1, -1, 1);  //levo dole blizu
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(-1, -1, -1); //levo dole lako
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(-1, 1, -1);  //levo gore daleko
            gl.End();

            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.PopMatrix();

            #endregion

            #region postolje

            gl.PushMatrix();
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Wood]);
            Cube postolje = new Cube();
            gl.Normal(0f, 0f, 1f);
            gl.Translate(0.0f, 0.0f, -235.0f);
            gl.Scale(100.0f, 80.0f, 10f);
            gl.Color(0.4f, 0.4f, 0.4f);
            //gl.Color(1f, 1f, 1f);
            gl.Rotate(0f, 0f, -90f);
            postolje.Render(gl, RenderMode.Render);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.PopMatrix();

            #endregion

            #region pikado
            gl.PushMatrix();
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);

            //gl.Translate(0.0f, 0.0f, -225.0f);
            gl.Translate(translateBoard, 0.0f + this.m_BoardFall_y, -225.0f);
            //gl.Scale(2.0f, 2.0f, 2.0f);
            gl.Scale(scaleBoard, scaleBoard, scaleBoard);

            m_scene.Draw();
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.PopMatrix();
            #endregion

            #region Strelice
            gl.PushMatrix(); //1
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            //gl.Translate(0.0f, 0.0f, 0.0f);
            gl.Translate(0.0f, 0.0f, 0.0f + this.m_Dart3_z);
            gl.Scale(10.0f, 10f, 5.0f);

            m_scene2.Draw();
            gl.PopMatrix();

            gl.PushMatrix(); //2
            //gl.Translate(-50.0f, 0.0f, 0.0f);
            gl.Translate(-50.0f, 0.0f, 0.0f + this.m_Dart1_z);
            gl.Scale(10.0f, 10f, 5.0f);

            m_scene2.Draw();
            gl.PopMatrix();

            gl.PushMatrix(); //3
                             //  gl.Translate(50.0f, 0.0f, 0.0f);
            gl.Translate(50.0f, 0.0f, 0.0f + this.m_Dart2_z);
            gl.Scale(10.0f, 10f, 5.0f);

            m_scene2.Draw();
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.PopMatrix();

            #endregion


            #region tekst
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.PushMatrix();
            gl.Viewport(m_width / 2, 0, m_width / 2, m_height / 2);
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Ortho2D(-10, 10, -10, 10);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.LoadIdentity();
            gl.Translate(-3.0f, -4.0f, 0.0f);
            gl.Color(10.0f, 10.0f, 0.0f);

            gl.PushMatrix();
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "Predmet: Racunarska grafika");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "_________________________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -1.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "Sk.god: 2020/21");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -1.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "_____________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -2.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "Ime: Stefan");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -2.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "__________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -3.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "Prezime: Aradjanin");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -3.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "________________");
            gl.PopMatrix();
            gl.PushMatrix(); gl.Translate(0.0f, -4.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "Sifra: 9.1");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(0.0f, -4.0f, 0.0f);
            gl.DrawText3D("Arial Bold", 14.0f, 0f, 0f, "_______");

            gl.PopMatrix();

            Resize(gl, m_width, m_height);
            gl.PopMatrix();

            #endregion

            // Oznaci kraj iscrtavanja

            gl.PopMatrix();
            gl.Flush();
        }
Beispiel #2
0
        private void DrawTable(OpenGL gl)
        {
            // gornja ploca
            gl.PushMatrix();
            gl.Scale(220.3f, 5.3f, 100.3f);
            gl.Translate(0, -2.7f, 0.0f);
            gl.Rotate(90f, 0f, 0f);
            gl.Color(1f, 1f, 1f);

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)Textures.Desk]);
            Cube ploca = new Cube();

            ploca.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);

            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.LoadIdentity();
            gl.Scale(4.1f, 4.1f, 4.1f);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PopMatrix();


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

            // nogica -x +z
            gl.PushMatrix();
            gl.Scale(3.54f, 67.3f, 3.6f);
            gl.Translate(-60.0f, -1.2f, 25.3f);
            gl.Rotate(90f, 0f, 0f);

            Cube nogica1 = new Cube();

            nogica1.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            // nogica -x -z
            gl.PushMatrix();
            gl.Scale(3.54f, 67.3f, 3.6f);
            gl.Translate(-60.0f, -1.2f, -25.3f);
            gl.Rotate(90f, 0f, 0f);
            Cube nogica2 = new Cube();

            nogica2.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            // nogica +x +z
            gl.PushMatrix();
            gl.Scale(3.54f, 67.3f, 3.6f);
            gl.Translate(60.0f, -1.2f, 25.3);
            gl.Rotate(90f, 0f, 0f);
            Cube nogica3 = new Cube();

            nogica3.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();


            // nogica +x -z
            gl.PushMatrix();
            gl.Scale(3.54f, 67.3f, 3.6f);
            gl.Translate(60.0f, -1.2f, -25.3f);
            gl.Rotate(90f, 0f, 0f);
            Cube nogica4 = new Cube();

            nogica4.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();
        }
Beispiel #3
0
        /// <summary>
        ///  Rekurzivna metoda zaduzena za iscrtavanje objekata u sceni koji su reprezentovani cvorovima.
        ///  U zavisnosti od karakteristika objekata podesavaju se odgovarajuce promenjive stanja (GL_LIGHTING, GL_COLOR_MATERIAL, GL_TEXTURE_2D).
        /// </summary>
        /// <param name="node">Cvor koji ce biti iscrtan.</param>
        private void RenderNode(Node node)
        {
            gl.PushMatrix();

            // Primena tranformacija, definisanih za dati cvor.
            float[] matrix = new float[16] {
                node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1, node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2, node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3, node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4
            };
            gl.MultMatrix(matrix);

            // Iscrtavanje objekata u sceni koji su reprezentovani datim cvorom.
            if (node.HasMeshes)
            {
                foreach (int meshIndex in node.MeshIndices)
                {
                    Mesh     mesh     = m_scene.Meshes[meshIndex];
                    Material material = m_scene.Materials[mesh.MaterialIndex];

                    // Primena komponenti materijala datog objekta.
                    ApplyMaterial(material);

                    // Primena teksture u slucaju da je ista definisana za dati materijal.
                    if (material.GetAllTextures().Length > 0)
                    {
                        gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_texMappings[material.GetAllTextures()[0]]);
                    }

                    // Podesavanje proracuna osvetljenja za dati objekat.
                    bool hasNormals = mesh.HasNormals;
                    if (hasNormals)
                    {
                        gl.Enable(OpenGL.GL_LIGHTING);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LIGHTING);
                    }

                    // Podesavanje color tracking mehanizma za dati objekat.
                    bool hasColors = mesh.HasVertexColors(0);
                    if (hasColors)
                    {
                        gl.Enable(OpenGL.GL_COLOR_MATERIAL);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_COLOR_MATERIAL);
                    }

                    // Podesavanje rezima mapiranja na teksture.
                    bool hasTexCoords = material.GetAllTextures().Length > 0 && mesh.HasTextureCoords(0);
                    if (hasTexCoords)
                    {
                        gl.Enable(OpenGL.GL_TEXTURE_2D);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_TEXTURE_2D);
                    }

                    // Iscrtavanje primitiva koji cine dati objekat.
                    // U zavisnosti od broja temena, moguce je iscrtavanje tacaka, linija, trouglova ili poligona.
                    foreach (Assimp.Face face in mesh.Faces)
                    {
                        switch (face.IndexCount)
                        {
                        case 1:
                            gl.Begin(OpenGL.GL_POINTS);
                            break;

                        case 2:
                            gl.Begin(OpenGL.GL_LINES);
                            break;

                        case 3:
                            gl.Begin(OpenGL.GL_TRIANGLES);
                            break;

                        default:
                            gl.Begin(OpenGL.GL_POLYGON);
                            break;
                        }

                        for (int i = 0; i < face.IndexCount; i++)
                        {
                            uint indice = face.Indices[i];

                            // Definisanje boje temena.
                            if (hasColors)
                            {
                                gl.Color(mesh.GetVertexColors(0)[indice].R, mesh.GetVertexColors(0)[indice].G, mesh.GetVertexColors(0)[indice].B, mesh.GetVertexColors(0)[indice].A);
                            }

                            // Definisanje normale temena.
                            if (hasNormals)
                            {
                                gl.Normal(mesh.Normals[indice].X, mesh.Normals[indice].Y, mesh.Normals[indice].Z);
                            }

                            // Definisanje koordinata teksture temena.
                            if (hasTexCoords)
                            {
                                gl.TexCoord(mesh.GetTextureCoords(0)[indice].X, 1 - mesh.GetTextureCoords(0)[indice].Y);
                            }

                            // Definisanje temena primitive.
                            gl.Vertex(mesh.Vertices[indice].X, mesh.Vertices[indice].Y, mesh.Vertices[indice].Z);
                        }
                        gl.End();
                    }
                }
            }

            // Rekurzivno scrtavanje podcvorova datog cvora.
            for (int i = 0; i < node.ChildCount; i++)
            {
                RenderNode(node.Children[i]);
            }
            gl.PopMatrix();
        }
        public void Draw(OpenGL gl, float originX, float originY, float originZ, float audioModifier, bool doOriginTranslation)
        {
            OriginX = originX;
            OriginY = originY;
            OriginZ = OriginZ;

            // Rotate colors
            if (_colorRotateStopwatch.ElapsedMilliseconds >= ColorRotateIntervalMs)
            {
                pickColor();
                _colorRotateStopwatch.Restart();
            }

            for (int index = 0; index < _particles.Count; index++)
            {
                Particle particle = _particles[index];
                float    x        = particle.X;
                float    y        = particle.Y;
                float    z        = particle.Z;
                float    r        = particle.R;
                float    g        = particle.G;
                float    b        = particle.B;
                float    a        = particle.Life;
                float    size     = particle.Size;

                _pointData[_point.DataStride * index + 0] = x;
                _pointData[_point.DataStride * index + 1] = y;
                _pointData[_point.DataStride * index + 2] = z;
                _pointData[_point.DataStride * index + 3] = size;
                _pointData[_point.DataStride * index + 4] = r;
                _pointData[_point.DataStride * index + 5] = g;
                _pointData[_point.DataStride * index + 6] = b;
                _pointData[_point.DataStride * index + 7] = a;

                // Increment particle location and speed
                if (OverrideParticleUpdate != null)
                {
                    OverrideParticleUpdate(particle, audioModifier);
                }
                else
                {
                    particle.Update();
                }

                // Invoke after update delegate if present
                if (AfterParticleUpdate != null)
                {
                    AfterParticleUpdate(particle, audioModifier);
                }

                // Reset dead particles
                if (particle.Life <= 0.0f)
                {
                    if (_isContinuous)
                    {
                        if (OverrideParticleInit != null)
                        {
                            // Call custom init if specified
                            OverrideParticleInit(particle, audioModifier);
                        }
                        else
                        {
                            // Re-init happening, no longer initial
                            particle.IsInitialInit = false;

                            // Default init
                            particle.Init(_random, audioModifier);

                            // Custom init if specified
                            if (AfterParticleInit != null)
                            {
                                AfterParticleInit(particle, audioModifier);
                            }
                        }

                        if (_autoRotateColors)
                        {
                            particle.R = Constants.Colors[_colorIndex, 0];
                            particle.G = Constants.Colors[_colorIndex, 1];
                            particle.B = Constants.Colors[_colorIndex, 2];
                        }
                    }
                    else
                    {
                        if (particle.IsAlive)
                        {
                            _deadParticleCount++;
                            particle.IsAlive = false;

                            if (_deadParticleCount == _particles.Count)
                            {
                                // None are alive. This particle system is no longer active
                                // and the caller should let it get GC'd
                                _isActive = false;
                            }
                        }
                    }
                }
            }

            // Begin Draw
            if (doOriginTranslation)
            {
                GlState.Instance.ModelMatrix = glm.translate(GlState.Instance.ModelMatrix, new vec3(originX, originY, originZ));
            }

            // Update buffers
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, _vertexBufferObject[0]);
            GlBuffer.SetArrayData(gl, null, _pointData.Length * PrimitiveSizes.FloatBytes, OpenGL.GL_STREAM_DRAW);
            GlBuffer.SetArraySubData(gl, _pointData, _pointData.Length * PrimitiveSizes.FloatBytes);

            // Make model matrix available for drawing
            gl.UniformMatrix4(GlState.Instance.ParticleModelMatrixLocation, 1, false, GlState.Instance.ModelMatrix.to_array());

            // Set blending for particle system
            gl.BlendFunc(_blendMode, OpenGL.GL_ONE);
            gl.DepthFunc(OpenGL.GL_ALWAYS);

            // Draw
            gl.ActiveTexture(OpenGL.GL_TEXTURE0);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, _texture);
            gl.Uniform1(GlState.Instance.ParticleTextureLocation, 0);
            gl.BindVertexArray(_vertexArrayObject[0]);
            gl.DrawArrays(OpenGL.GL_POINTS, 0, _pointData.Length);
            gl.BindVertexArray(0);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

            // Reset depth and blend func
            gl.DepthFunc(OpenGL.GL_LESS);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);

            if (doOriginTranslation)
            {
                GlState.Instance.ModelMatrix = mat4.identity();
            }
            // End Draw
        }
        /// <summary>
        /// Render texture with FBO and draw it to memory.
        /// </summary>
        private void RenderTexWithFBOandDraw()
        {
            OpenGL gl = openGLControl.OpenGL;
            // render to texture 
            // adjust viewport and projection matrix to texture dimension
            gl.Viewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Perspective(fovy, (double)Width / (double)Height, 0.01f, 100.0);
            gl.LookAt(
                status.eye.x + status.kinect.x, 
                status.eye.y + status.kinect.y, 
                status.eye.z + status.kinect.z, 
                buildingModelCursor.GetCoordinate().x,
                buildingModelCursor.GetCoordinate().y, 
                buildingModelCursor.GetCoordinate().z, 
                0, 1, 0
                );

            // with FBO
            // set the rendering destination to FBO
            gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, framebuffer_name[0]);

            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();
            // clear buffer
            gl.ClearColor(0, 0, 0, 1);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            // start to draw
            gl.PushMatrix();

            //  Load the identity matrix.
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full);
            if (status != null && buildingModelCursor != null)
            {
                switch (buildingModelCursor.GetBuildingType())
                {
                    case BuildingObjectType.Floor:
                        drawer.DrawBuildingPart(gl, buildingOutsideModel, DrawType.WireFrame);
                        drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full);
                        break;
                    case BuildingObjectType.Object:
                        System.Collections.Hashtable childs = buildingModelCursor.Father.GetChilds();
                        foreach (System.Collections.DictionaryEntry childEntry in buildingModelCursor.Father.GetChilds())
                        {
                            BuildingObjectLib3DS child = childEntry.Value as BuildingObjectLib3DS;
                            if (child != buildingModelCursor)
                            {
                                drawer.DrawBuildingPart(gl,
                                    child,
                                    DrawType.WireFrame);
                            }
                            else
                            {
                                drawer.DrawBuildingPart(gl,
                                    child,
                                    DrawType.Full);
                            }
                        }
                        break;
                    case BuildingObjectType.Room:
                    // TODO
                    case BuildingObjectType.Outside:
                    case BuildingObjectType.Building:
                        drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full);
                        break;
                }
            }
            //drawer.DrawBuildingPart(gl, modelForFun, DrawType.Full);
            gl.PopMatrix();

            // back to normal window-system-provided framebuffer
            gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 0); // unbind

            // trigger mipmaps generation explicitly
            // NOTE: If GL_GENERATE_MIPMAP is set to GL_TRUE, then glCopyTexSubImage2D()
            // triggers mipmap generation automatically. However, the texture attached
            // onto a FBO should generate mipmaps manually via glGenerateMipmapEXT().
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture_name[0]);
            gl.GenerateMipmapEXT(OpenGL.GL_TEXTURE_2D);
            //gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

            // TODO: without FBO, maybe need
        }
Beispiel #6
0
 public void Unbind(OpenGL gl)
 {
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
 }
Beispiel #7
0
        public void Render(OpenGL gl, int targetWidth, int targetHeight, ref int target, uint[] effectFrameBuffer, uint raytracerBuffer, uint[] effectRaytracerBuffer)
        {
            if (_PostProcessFilter == 0)
            {
                // !!!!!!!!!!!!!!! rgb / a
                gl.Viewport(0, 0, targetWidth, targetHeight);
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, effectFrameBuffer[target]);
                var shader = shaderRGBA;
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, raytracerBuffer);
                shader.Bind(gl);
                shader.SetUniform1(gl, "renderedTexture", 0);
                gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                shader.Unbind(gl);
            }
            else if (_PostProcessFilter == 1)
            {
                // !!!!!!!!!!!!!!! rgb / a
                gl.Viewport(0, 0, targetWidth, targetHeight);
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, effectFrameBuffer[target]);
                var shader = shaderRGBA;
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, raytracerBuffer);
                shader.Bind(gl);
                shader.SetUniform1(gl, "renderedTexture", 0);
                gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                shader.Unbind(gl);

                // !!!!!!!!!!!!!!! exponent
                target = target > 0 ? 0 : 1;
                gl.Viewport(0, 0, targetWidth, targetHeight);
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, effectFrameBuffer[target]);
                shader = shaderHighlights;
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, effectRaytracerBuffer[target > 0 ? 0 : 1]);
                shader.Bind(gl);
                shader.SetUniform1(gl, "exponent", (float)_GaussianExposure);
                shader.SetUniform1(gl, "renderedTexture", 0);
                gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                shader.Unbind(gl);

                // !!!!!!!!!!!!!!! gaussianShaderX
                target = target > 0 ? 0 : 1;
                gl.Viewport(0, 0, targetWidth, targetHeight);
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, effectFrameBuffer[target]);
                shader = shaderGaussianX;
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, effectRaytracerBuffer[target > 0 ? 0 : 1]);
                shader.Bind(gl);
                shader.SetUniform1(gl, "screenWidth", targetWidth);
                shader.SetUniform1(gl, "screenHeight", targetHeight);
                shader.SetUniform1(gl, "renderedTexture", 0);
                gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                shader.Unbind(gl);

                // !!!!!!!!!!!!!!! gaussianShaderY
                target = target > 0 ? 0 : 1;
                gl.Viewport(0, 0, targetWidth, targetHeight);
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, effectFrameBuffer[target]);
                shader = shaderGaussianY;
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, effectRaytracerBuffer[target > 0 ? 0 : 1]);
                shader.Bind(gl);
                shader.SetUniform1(gl, "screenWidth", targetWidth);
                shader.SetUniform1(gl, "screenHeight", targetHeight);
                shader.SetUniform1(gl, "renderedTexture", 0);
                gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                shader.Unbind(gl);

                // !!!!!!!!!!!!!!! blend
                target = target > 0 ? 0 : 1;
                gl.Viewport(0, 0, targetWidth, targetHeight);
                gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, effectFrameBuffer[target]);
                shader = shaderBlend;
                gl.ActiveTexture(OpenGL.GL_TEXTURE0);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, raytracerBuffer);
                gl.ActiveTexture(OpenGL.GL_TEXTURE1);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, effectRaytracerBuffer[target > 0 ? 0 : 1]);
                shader.Bind(gl);
                shader.SetUniform1(gl, "factor1", 1);
                shader.SetUniform1(gl, "factor2", (float)_PostProcessAmount);
                int rte1 = shader.GetUniformLocation(gl, "renderedTexture1");
                int rne1 = shader.GetUniformLocation(gl, "renderedTexture2");
                gl.Uniform1(rte1, 0);
                gl.Uniform1(rne1, 1);
                gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                shader.Unbind(gl);
            }
        }
Beispiel #8
0
 public void Unbind(OpenGL gl)
 {
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
 }
Beispiel #9
0
        /// <summary>
        /// This function creates the texture from an image.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="image">The image.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public void SetImage(OpenGL gl, Bitmap image)
        {
            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth  = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                {
                    targetWidth = size;
                }
            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                {
                    targetHeight = size;
                }
            }

            //  If need to scale, do so now.
            bool destroyImage = false;

            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);
                image        = (Bitmap)newImage;
                destroyImage = true;
            }

            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                   ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            //	Set the width and height.
            Width  = (uint)image.Width;
            Height = (uint)image.Height;

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureObject);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                          (int)Width, (int)Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                          bitmapData.Scan0);

            //  Unlock the image.
            image.UnlockBits(bitmapData);

            //  Dispose of the image file if it's an intermediate we created.
            if (destroyImage)
            {
                image.Dispose();
            }
        }
Beispiel #10
0
        /// <summary>
        /// updates pixel data of the desired texture.
        /// </summary>
        public void UpdateTextureBitmap(OpenGL gl, int texIndex, Bitmap image)
        {
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            if (image == null)
            {
                return;
            }

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth  = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            //Console.WriteLine("Updating Tex " + texIndex + "Tex Max Size : " + targetWidth + "x" + targetHeight);

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                {
                    targetWidth = size;
                }
            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                {
                    targetHeight = size;
                }
            }

            //  If need to scale, do so now.
            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);

                //  Destory the old image, and reset.
                image.Dispose();
                image = (Bitmap)newImage;
            }

            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                   ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            //	Set the width and height.
            _width[texIndex]  = image.Width;
            _height[texIndex] = image.Height;

            gl.ActiveTexture(texIndex == 0 ? OpenGL.GL_TEXTURE0 : OpenGL.GL_TEXTURE1);

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, _glTextureArray[texIndex]);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                          _width[texIndex], _height[texIndex], 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                          bitmapData.Scan0);

            //  Unlock the image.
            image.UnlockBits(bitmapData);

            //  Dispose of the image file.
            image.Dispose();

            //  Set linear filtering mode.
            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);
        }
Beispiel #11
0
 public void Bind(OpenGL gl)
 {
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureObject);
 }
Beispiel #12
0
        //ostale metode
        public void drawScene(OpenGL gl)
        {
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            //gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            //gl.Color(1.0f, 1.0f, 1.0f, 1.0f);
            //gl.Color(0.0f, 0.0f, 0.0f, 1.0f);

            //pocetak iscrtavanja
            gl.PushMatrix();

            //kamion
            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Empty]);
            gl.Translate(10.0f + pozicijaKamiona[0], -5.0f + pozicijaKamiona[1], -80.0f + pozicijaKamiona[2]);
            gl.Rotate(0.0f, rotacijaKamiona, 0.0f);
            m_scene.Draw();
            gl.PopMatrix();


            //kontejner
            gl.PushMatrix();
            //gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Empty]);
            //gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL);
            gl.Translate(pozicijaKontejnera[0] - 10.0f, pozicijaKontejnera[1] - 5.0f, -80.0f + pozicijaKontejnera[2]);
            gl.Scale(0.05f, 0.05f, 0.05f);
            gl.Rotate(rotacijaKontejnera[0], rotacijaKontejnera[1], rotacijaKontejnera[2]);
            gl.Rotate(rotacijaKontejnera2[0], rotacijaKontejnera2[1], rotacijaKontejnera2[2]);
            gl.Rotate(rotacijaKontejnera3[0], rotacijaKontejnera3[1], rotacijaKontejnera3[2]);
            m_scene2.Draw();
            gl.PopMatrix();


            //gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);


            //podloga
            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Asphalt]);
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.LoadIdentity();
            gl.Scale(faktorSkaliranjaPodloge, faktorSkaliranjaPodloge, faktorSkaliranjaPodloge);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Translate(-80.0f, -5.0f, 0.0f);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Normal(0, 1, 0);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(0.0f, 0.0f, 0.0f);
            gl.TexCoord(0.0f, brojPonavljanjaTeksturePuta);
            gl.Vertex(200.0f, 0.0f, 0.0f);
            gl.TexCoord(brojPonavljanjaTeksturePuta, brojPonavljanjaTeksturePuta);
            gl.Vertex(200.0f, 0.0f, -200.0f);
            gl.TexCoord(brojPonavljanjaTeksturePuta, 0.0f);
            gl.Vertex(0.0f, 0.0f, -200.0f);
            gl.End();
            gl.PopMatrix();


            //zidovi sa strana kontejnera
            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Empty]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            gl.Translate(0.0f, 0.0f, -80.0f);
            gl.Scale(1f, 8f, 10f);
            cube = new Cube();
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(-25.0f, 0.0f, -80.0f);
            gl.Scale(1f, 8f, 10f);
            cube = new Cube();
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();


            //bandera
            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Metal]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);

            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.LoadIdentity();
            gl.Scale(faktorSkaliranjaBandere, faktorSkaliranjaBandere, faktorSkaliranjaBandere);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);


            gl.Translate(20.0f, -5.0f, -80.0f);
            gl.Rotate(-90.0f, 0.0f, 0.0f);
            gl.Scale(cylinderFactor, cylinderFactor, cylinderFactor);
            cylinder            = new Cylinder();
            cylinder.Height     = lampLightPos[1];
            cylinder.BaseRadius = 0.5f;
            cylinder.TopRadius  = 0.5f;
            cylinder.CreateInContext(gl);
            cylinder.Render(gl, RenderMode.Render);
            cylinder.CreateInContext(gl);

            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(lampLightPos[0], lampLightPos[1] - 5.0f, lampLightPos[2]);
            gl.Scale(cubeFactor, cubeFactor, cubeFactor);
            cube = new Cube();
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();


            //kraj iscrtavanja
            gl.PopMatrix();
        }
Beispiel #13
0
        /// <summary>
        /// This function creates the texture from an image file.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="path">The path to the image file.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public virtual bool Create(OpenGL gl, string path)
        {
            //  Create the underlying OpenGL object.
            Create(gl);

            //  Try and load the bitmap. Return false on failure.
            Bitmap image = new Bitmap(path);
            if (image == null)
                return false;

            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                    targetWidth = size;

            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                    targetHeight = size;
            }

            //  If need to scale, do so now.
            if(image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);

                //  Destory the old image, and reset.
                image.Dispose();
                image = (Bitmap)newImage;
            }

            //  Create an array of pixels the correct size.
            pixelData = new byte[image.Width * image.Height * 4];
            int index = 0;

            //  TODO: The loop below is staggeringly slow and needs speeding up.
            //  Go through the pixels backwards, this seems to be how OpenGL wants the data.
            for (int y = image.Height - 1; y >= 0; y--)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    Color pixel = image.GetPixel(x, y);
                    pixelData[index++] = pixel.R;
                    pixelData[index++] = pixel.G;
                    pixelData[index++] = pixel.B;
                    pixelData[index++] = pixel.A;
                }
            }

            //	Set the width and height.
            width = image.Width;
            height = image.Height;

            //  Dispose of the image file.
            image.Dispose();

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.TEXTURE_2D, TextureName);

            //  Set the image data.
            gl.TexImage2D(OpenGL.TEXTURE_2D, 0, (int)OpenGL.RGBA,
                width, height, 0, OpenGL.RGBA, OpenGL.UNSIGNED_BYTE,
                pixelData);

            //  Set linear filtering mode.
            gl.TexParameter(OpenGL.TEXTURE_2D, OpenGL.TEXTURE_MIN_FILTER, OpenGL.LINEAR);
            gl.TexParameter(OpenGL.TEXTURE_2D, OpenGL.TEXTURE_MAG_FILTER, OpenGL.LINEAR);

            //  We're done!
            return true;
        }
Beispiel #14
0
        /// <summary>
        /// This function creates the texture from an image.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="image">The image.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public void SetImage(OpenGL gl, Bitmap image)
        {
            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                    targetWidth = size;

            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                    targetHeight = size;
            }

            //  If need to scale, do so now.
            bool destroyImage = false;
            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);
                image = (Bitmap)newImage;
                destroyImage = true;
            }

            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            //	Set the width and height.
            Width = (uint)image.Width;
            Height = (uint)image.Height;

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureObject);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                (int)Width, (int)Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                bitmapData.Scan0);

            //  Unlock the image.
            image.UnlockBits(bitmapData);

            //  Dispose of the image file if it's an intermediate we created.
            if(destroyImage)
                image.Dispose();
        }
Beispiel #15
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.Viewport(0, 0, m_width, m_height);
            gl.ClearColor(0.2f, 0.2f, 0.2f, 1.0f);

            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            WriteText2(gl);
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.Enable(OpenGL.GL_LIGHTING);

            gl.PushMatrix();

            gl.LookAt(0.0f, 0f, 100.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            gl.Translate(0.0f, 0.0f, -m_sceneDistance);

            gl.Scale(10f, 10f, 10f);
            gl.Rotate(m_xRotation, 1.0f, 0.0f, 0.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);
            gl.Rotate(m_zRotation, 0.0f, 0.0f, 1.0f);

            gl.Translate(40f, 200f, 0.0f);
            //reflektor
            SetupLighting1(gl);


            //iscrtavanje 1/2jabuke
            //nacin stapanja teksture sa modelom ( sabira teksel sa bojom materijala)
            gl.Color(0.0f, 0.1f, 0.0f, 1.0f);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            gl.PushMatrix();
            gl.Rotate(0.0f + leftFruitRotation, 0.0f, 0.0f);
            gl.PushMatrix();
            gl.Translate(35, -80f, -40f + fruitHeight);
            gl.Rotate(90f - fruitRotation, 0.0f, 0.0f);
            gl.Scale(200f, 200f, 200f);
            m_scene.Draw();
            gl.PopMatrix();


            //iscrtavanje 2/2jabuke
            gl.PushMatrix();
            gl.Rotate(90f, 180f - fruitRotation, 0f);
            gl.Translate(50f, -40f + fruitHeight, -130f);
            gl.Scale(200f, 200f, 200f);
            m_scene.Draw();
            gl.PopMatrix();
            gl.PopMatrix();

            gl.PushMatrix();
            // gl.Rotate(0.0f, 0.0f + leftFruitRotation, 0.0f);
            //iscrtavanje narandza gore
            gl.PushMatrix();

            gl.Rotate(180f, 0f, 0f);
            gl.Translate(-125f, 137f, -50f - fruitHeight);
            gl.Scale(150f, 150f, 150f);
            m_scene2.Draw();
            gl.PopMatrix();
            //iscrtavanje narandza dole
            gl.PushMatrix();
            gl.Rotate(0f, 0f, 0f);
            gl.Translate(-125f, -258f, 12f + fruitHeight);
            gl.Scale(150f, 150f, 150f);
            m_scene2.Draw();
            gl.PopMatrix();
            gl.PopMatrix();
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            //postolja
            gl.PushMatrix();
            gl.Translate(-5.0f, -100.0f, 0.0f);
            gl.Color(0.0f, 0.7f, 0.0f);
            Cylinder cyl = new Cylinder
            {
                TopRadius  = 20f,
                BaseRadius = 20f,
                Height     = 20f + fruitHeight
            };

            cyl.CreateInContext(gl);
            gl.Normal(0.0f, 1.0f, 0.0f);
            cyl.Render(gl, RenderMode.Render);
            Disk disk = new Disk();

            disk.InnerRadius = 0f;
            disk.OuterRadius = 20f;
            disk.CreateInContext(gl);
            gl.Normal(0.0f, 1.0f, 0.0f);
            gl.Translate(0.0f, 0.0f, 20f + fruitHeight);
            disk.Render(gl, RenderMode.Render);
            gl.Normal(0.0f, 1.0f, 0.0f);
            gl.Translate(-150f, -100f, -20f - fruitHeight);
            cyl.Render(gl, RenderMode.Render);
            gl.Translate(0.0f, 0.0f, 20f + fruitHeight);
            gl.Normal(0.0f, 1.0f, 0.0f);
            disk.Render(gl, RenderMode.Render);
            gl.PopMatrix();


            //iscrtavanje podloge

            drawFloor(gl);



            //gl.Color(0.0f, 0.0f, 0.7f);

            //dole zid
            gl.PushMatrix();
            Cube wall = new Cube();

            gl.Translate(-45.0f, 150.0f, 10.0f);
            gl.Scale(200f, 5f, 10f);
            gl.Normal(0f, 1f, 0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[0]);
            wall.Render(gl, RenderMode.Render);
            //skidanje tekstura
            gl.PopMatrix();
            //gore zid
            gl.PushMatrix();
            gl.Translate(-45.0f, 430.0f, 10.0f);
            gl.Scale(200f, 5f, 10f);
            wall.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //levo zid
            gl.PushMatrix();
            gl.Rotate(0.0f, 0.0f, 90.0f);
            gl.Translate(290.0f, 240.0f, 10.0f);
            gl.Scale(135f, 5f, 10f);
            wall.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //desni zid
            gl.PushMatrix();
            gl.Rotate(0.0f, 0.0f, 90.0f);
            gl.Translate(290.0f, -150.0f, 10.0f);
            gl.Scale(135f, 5f, 10f);
            wall.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //crtanje grid mreze
            gl.PushMatrix();
            gl.Translate(-50f, 250f, 0);
            gl.Scale(40f, 30f, 0f);
            Grid grid = new Grid();

            grid.Render(gl, RenderMode.Design);
            gl.PopMatrix();

            gl.PopMatrix();


            // Oznaci kraj iscrtavanja
            gl.Flush();
        }
Beispiel #16
0
        protected void Init(OpenGL gl)
        {
            gl.PushMatrix();
            Animation(gl);
            gl.Translate(LocationX, LocationY, LocationZ);
            gl.Translate(0, 0, SizeZ / 2);
            gl.Rotate(RotateX, 1.0, 0.0, 0.0);
            gl.Rotate(RotateY, 0.0, 1.0, 0.0);
            gl.Rotate(RotateZ, 0.0, 0.0, 1.0);
            gl.Translate(0, 0, -SizeZ / 2);
            gl.Color(ColorR, ColorG, ColorB);

            if (Style != DrawStyle.Fill)
            {
                return;
            }

            ////Lighting
            switch (LightingMode)
            {
            case Lighting.AMBIENT:
                gl.Enable(OpenGL.GL_LIGHTING);
                gl.Enable(OpenGL.GL_LIGHT0);
                float[] light_pos1 = new float[4];
                gl.GetLight(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, light_pos1);
                if (light_pos1[0] == 0 && light_pos1[1] == 0 && light_pos1[2] == 1 && light_pos1[3] == 0)
                {
                }
                else
                {
                    gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, new float[4] {
                        0, 0, 1, 0
                    });
                }
                gl.Material(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_AMBIENT, new float[4] {
                    0, 0, 0, 1
                });
                break;

            case Lighting.POSITION:
                gl.Enable(OpenGL.GL_LIGHTING);
                gl.Enable(OpenGL.GL_LIGHT0);
                float[] light_pos = new float[4];
                light_pos[0] = (float)LightSourceX;
                light_pos[1] = (float)LightSourceY;
                light_pos[2] = (float)LightSourceZ;
                light_pos[3] = (float)0.0;
                gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, light_pos);
                ///Code chiếu sáng
                ///
                break;

            case Lighting.SHADOW:

                break;

            default: break;
            }

            ///
            ///Texture
            ///
            if (Texture != null)
            {
                gl.Enable(OpenGL.GL_TEXTURE_2D);
                uint[] textures = new uint[1];
                gl.GenTextures(1, textures);

                gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);
                bitmapData = Texture.LockBits(new Rectangle(0, 0, Texture.Width, Texture.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, Texture.Width, Texture.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                              bitmapData.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);
            }
        }
Beispiel #17
0
 /// <summary>
 /// Bind to the specified OpenGL instance.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public void Bind(OpenGL gl)
 {
     //	Bind our texture object (make it the current texture).
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);
 }
Beispiel #18
0
        private void DrawBigWheelsOnSide(OpenGL gl, float z)
        {
            //wheel axle
            gl.PushMatrix();
            gl.Translate(-0.21, 0.131, z);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[4]);
            drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.1f / 2, 0.138f, 0.1f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[11]);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.1f / 2, 0.1f);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.138f, 0.1f / 2, 0.1f);
            gl.PopMatrix();

            //first wheel
            gl.PushMatrix();
            gl.Translate(-0.21, 0.131, z + 0.015);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[11]);
            drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.2f / 2, 0.02f, 0.1f);
            gl.PopMatrix();

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[10]);
            gl.PushMatrix();
            gl.Translate(-0.21, 0.131, z + 0.015);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.2f / 2, 0.1f);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.02f, 0.2f / 2, 0.1f);
            gl.PopMatrix();

            //second wheel
            gl.PushMatrix();
            gl.Translate(-0.21, 0.131, z + 0.108);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[11]);
            drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.2f / 2, 0.02f, 0.1f);
            gl.PopMatrix();

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[10]);
            gl.PushMatrix();
            gl.Translate(-0.21, 0.131, z + 0.108);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.2f / 2, 0.1f);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.02f, 0.2f / 2, 0.1f);
            gl.PopMatrix();

            for (int i = 0; i < 4; i++)
            {
                //wheel axle
                gl.PushMatrix();
                gl.Translate(0.04 + i * 0.35, 0.04, z);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[4]);
                drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.05f / 2, 0.138f, 0.1f);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[8]);
                drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.05f / 2, 0.1f);
                drawer.DrawCircle(gl, 0.0f, 0.0f, 0.138f, 0.05f / 2, 0.1f);
                gl.PopMatrix();

                //first wheel
                gl.PushMatrix();
                gl.Translate(0.04 + i * 0.35, 0.04, z + 0.035);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[9]);
                drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.19f / 2, 0.02f, 0.1f);
                gl.PopMatrix();

                gl.PushMatrix();
                gl.Translate(0.04 + i * 0.35, 0.04, z + 0.035);
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[7]);
                drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.19f / 2, 0.1f);
                drawer.DrawCircle(gl, 0.0f, 0.0f, 0.02f, 0.19f / 2, 0.1f);
                gl.PopMatrix();

                //second wheel
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[9]);
                gl.PushMatrix();
                gl.Translate(0.04 + i * 0.35, 0.04, z + 0.068);
                drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.19f / 2, 0.02f, 0.1f);
                gl.PopMatrix();

                gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[7]);
                gl.PushMatrix();
                gl.Translate(0.04 + i * 0.35, 0.04, z + 0.068);
                drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.19f / 2, 0.1f);
                drawer.DrawCircle(gl, 0.0f, 0.0f, 0.02f, 0.19f / 2, 0.1f);
                gl.PopMatrix();
            }


            //wheel axle
            gl.PushMatrix();
            gl.Translate(-0.04 + 0.35 * 4, 0.1, z);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[4]);
            drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.04f / 2, 0.138f, 0.1f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[8]);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.04f / 2, 0.1f);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.138f, 0.04f / 2, 0.1f);
            gl.PopMatrix();

            //first wheel
            gl.PushMatrix();
            gl.Translate(-0.04 + 0.35 * 4, 0.1, z + 0.025);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[9]);
            drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.2f / 2, 0.03f, 0.1f);
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(-0.04 + 0.35 * 4, 0.1, z + 0.025);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[12]);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.2f / 2, 0.1f);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.03f, 0.2f / 2, 0.1f);
            gl.PopMatrix();

            //second wheel
            gl.PushMatrix();
            gl.Translate(-0.04 + 0.35 * 4, 0.1, z + 0.098);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[9]);
            drawer.DrawCylinder(gl, 0.0f, 0.0f, 0.2f / 2, 0.03f, 0.1f);
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(-0.04 + 0.35 * 4, 0.1, z + 0.098);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TankGL_Form.textures[12]);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.0f, 0.2f / 2, 0.1f);
            drawer.DrawCircle(gl, 0.0f, 0.0f, 0.03f, 0.2f / 2, 0.1f);
            gl.PopMatrix();
        }
Beispiel #19
0
        public void loadTarget(OpenGL gl)
        {
            gl.PushMatrix();
            gl.Translate(targetX, targetY, 600f);
            gl.Scale(30f + skaliranjeMeta, 100f + skaliranjeMeta, 30f + skaliranjeMeta);
            gl.Rotate(-90f, 1, 0, 0);

            Glu.gluQuadricTexture(gluObject, 1);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.METAL]);

            gl.Color(0.184f, 0.310f, 0.310);
            Cylinder target = new Cylinder();

            target.NormalOrientation = Orientation.Outside;
            target.TopRadius         = 1;
            target.CreateInContext(gl);
            target.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();


            gl.PushMatrix();
            gl.Translate(1300f, 150f, 350f);
            gl.Scale(30f + skaliranjeMeta, 100f + skaliranjeMeta, 30f + skaliranjeMeta);
            gl.Rotate(-90f, 1, 0, 0);
            gl.Color(0.184f, 0.310f, 0.310);
            Cylinder target1 = new Cylinder();

            target1.NormalOrientation = Orientation.Outside;
            target1.TopRadius         = 1;
            target1.CreateInContext(gl);
            target1.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(1300f, 150f, 100f);
            gl.Scale(30f + skaliranjeMeta, 100f + skaliranjeMeta, 30f + skaliranjeMeta);
            gl.Rotate(-90f, 1, 0, 0);
            gl.Color(0.184f, 0.310f, 0.310);
            Cylinder target2 = new Cylinder();

            target2.NormalOrientation = Orientation.Outside;
            target2.TopRadius         = 1;
            target2.CreateInContext(gl);
            target2.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(targetX1, targetY1, 950f);
            gl.Scale(30f + skaliranjeMeta, 100f + skaliranjeMeta, 30f + skaliranjeMeta);
            gl.Rotate(-90f, 1, 0, 0);
            gl.Color(0.184f, 0.310f, 0.310);
            Cylinder target3 = new Cylinder();

            target3.NormalOrientation = Orientation.Outside;
            target3.TopRadius         = 1;
            target3.CreateInContext(gl);
            target3.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();


            gl.PushMatrix();
            gl.Translate(targetX2, targetY2, 1200f);
            gl.Scale(30f + skaliranjeMeta, 100f + skaliranjeMeta, 30f + skaliranjeMeta);
            gl.Rotate(-90f, 1, 0, 0);
            gl.Color(0.184f, 0.310f, 0.310);
            Cylinder target4 = new Cylinder();

            target4.NormalOrientation = Orientation.Outside;
            target4.TopRadius         = 1;
            target4.CreateInContext(gl);
            target4.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();
        }
Beispiel #20
0
        public void OpenGLDraw(int glWidth, int glHeight)
        {
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.PushMatrix();
            // Roll with the camera
            gl.Translate(PADDING, -Game.CameraYPosition + PADDING, 0);

            // Show the bubble counter
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.BUBBLE_TEXTURE_ID);
            gl.PushMatrix();
            gl.Translate(this.bubbleSize.X / 2f, (this.foodSize.Y - this.bubbleSize.Y) / 2f + this.bubbleSize.Y / 2f, 0);
            Animator.DrawTexture(this.bubbleSize, this.bubble, 0, 4);
            gl.DrawText((int)(this.bubbleSize.X / 2f), (int)SceneManager.ScreenSize.Y - PADDING - FONT_SIZE - (int)(this.bubbleSize.Y / 2), 1, 1, 1, "Arial", FONT_SIZE, SceneManager.Player.BubblesScore.ToString());
            gl.PopMatrix();

            // Show the player's points
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.FISH_TEXTURE_ID);
            gl.PushMatrix();
            gl.Translate(SceneManager.ScreenSize.X / 2f - this.fishSize.X / 2f, (this.foodSize.Y - this.fishSize.Y) / 2f + this.fishSize.Y / 2f, 0);
            Animator.DrawTexture(this.fishSize, this.fish, 0, 4);
            gl.DrawText((int)(SceneManager.ScreenSize.X / 2f) + PADDING * 3, (int)SceneManager.ScreenSize.Y - PADDING - (int)((this.fishSize.Y + FONT_SIZE) / 2), 1, 1, 1, "Arial", FONT_SIZE, SceneManager.Player.FishScore.ToString() + (Game.Goal > 0 ? "/" + Game.Goal : ""));
            gl.PopMatrix();

            // Show the player's lifes
            for (int i = 0; i < this.food.Length; i++)
            {
                if (SceneManager.Player.Lives <= i)
                {
                    continue;
                }

                gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.FISH_FOOD_TEXTURE_IDS[i]);
                gl.PushMatrix();
                gl.Translate(SceneManager.ScreenSize.X - (PADDING * (i + 2)) - (this.foodSize.X * i) - this.foodSize.X / 2f, this.foodSize.Y / 2f, 0);
                Animator.DrawTexture(this.foodSize, this.food[i], 0, 4);
                gl.PopMatrix();
            }

            if (Game.GameEnded && Game.Goal <= 0)
            {
                // Show the highscores
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.HIGHSCORE_TEXTURES_IDS[0]);
                gl.PushMatrix();
                gl.Translate(SceneManager.ScreenSize.X / 2f, SceneManager.ScreenSize.Y / 2f, 0);
                Animator.DrawTexture(this.highcoreSize, this.highscore[0], 0, 4);
                gl.DrawText((int)((SceneManager.ScreenSize.X - FONT_SIZE * 6) / 2f), (int)((SceneManager.ScreenSize.Y + this.highcoreSize.Y) / 2f - FONT_SIZE * 2), 1, 1, 1, "Arial", FONT_SIZE * 1.25f, "Recordes");

                for (int i = 0; i < this.HIGHSCORE_TEXTURES.Length - 1; i++)
                {
                    gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.HIGHSCORE_TEXTURES_IDS[i + 1]);
                    gl.PushMatrix();
                    gl.Translate(PADDING * 2 + this.trophySize.X / 2f - this.highcoreSize.X / 2f, FONT_SIZE * 3 - this.highcoreSize.Y / 2f + (PADDING * 2 + this.trophySize.Y) * i, 0);
                    Animator.DrawTexture(this.trophySize, this.highscore[i + 1], 0, 4);

                    if (NewScorePosition != i)
                    {
                        gl.DrawText((int)((SceneManager.ScreenSize.X - this.highcoreSize.X) / 2f + this.trophySize.X + PADDING * 6), (int)(SceneManager.ScreenSize.Y / 2f - FONT_SIZE * 4.25 + (PADDING * 2 + this.trophySize.Y) * (this.HIGHSCORE_TEXTURES.Length - 2 - i) - (this.trophySize.Y - FONT_SIZE) / 2f), 1, 1, 1, "Arial", FONT_SIZE, !string.IsNullOrEmpty(Highscores[i]) ? Highscores[i].Replace(";", ": ") : "Vazio");
                    }
                    else
                    {
                        gl.DrawText((int)((SceneManager.ScreenSize.X - this.highcoreSize.X) / 2f + this.trophySize.X + PADDING * 6), (int)(SceneManager.ScreenSize.Y / 2f - FONT_SIZE * 4.25 + (PADDING * 2 + this.trophySize.Y) * (this.HIGHSCORE_TEXTURES.Length - 2 - i) - (this.trophySize.Y - FONT_SIZE) / 2f), 1, 1, 1, "Arial", FONT_SIZE, PlayerName + "_: " + SceneManager.Player.FishScore);
                    }
                    gl.PopMatrix();
                }

                if (IsNewScore)
                {
                    gl.DrawText(PADDING * 4, PADDING * 4, 1, 1, 1, "Arial", FONT_SIZE * 0.75f, "Pressione ENTER para confirmar o nome.");
                }
                else
                {
                    gl.DrawText(PADDING * 4, PADDING * 4, 1, 1, 1, "Arial", FONT_SIZE * 0.75f, "Pressione R para reiniciar ou ESC para voltar ao menu.");
                }
                gl.PopMatrix();
            }
            else if (Game.GameEnded)
            {
                gl.DrawText((int)((SceneManager.ScreenSize.X - FONT_SIZE * 6) / 2f), (int)((SceneManager.ScreenSize.Y - FONT_SIZE * 1.5) / 2f), 1, 1, 1, "Arial", FONT_SIZE * 1.25f, "Você falhou!");
                gl.DrawText(PADDING * 4, PADDING * 4, 1, 1, 1, "Arial", FONT_SIZE * 0.75f, "Pressione R para reiniciar ou ESC para voltar ao menu.");
            }
            else if (SceneManager.IsPaused)
            {
                gl.DrawText((int)((SceneManager.ScreenSize.X - FONT_SIZE * 4) / 2f), (int)((SceneManager.ScreenSize.Y - FONT_SIZE * 1.5) / 2f), 1, 1, 1, "Arial", FONT_SIZE * 1.25f, "PAUSE");
                gl.DrawText(PADDING * 4, PADDING * 4, 1, 1, 1, "Arial", FONT_SIZE * 0.75f, "Pressione P para continuar.");
            }
            gl.PopMatrix();
            gl.Disable(OpenGL.GL_TEXTURE_2D);
        }
Beispiel #21
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.Viewport(0, 0, m_width, m_height);

            gl.PushMatrix();
            gl.LookAt(-m_sceneDistance, 0f, 0f, 0f, 0f, 0, 0f, 1f, 0f);//sa leve strane je - deo X-ose
            // gl.Translate(0.0f, 0.0f, -m_sceneDistance);
            gl.Rotate(m_xRotation, 0.0f, 0.0f, 1.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);

            ///REFLEKTOR
            float[] rc = new float[] { r, g, b, 1.0f };

            //BOJA REGLEKTORA
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_AMBIENT, rc);
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_DIFFUSE, rc);
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_SPECULAR, rc);

            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_POSITION, new float[] { 0, 100, 195, 1.0f });       //svetlo iznad mola
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_SPOT_DIRECTION, new float[] { 0.0f, -1.0f, 0.0f }); //sija na dole

            //podloga vode
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.WATER]); //VODA ZA PODLOGU
            //bindujemo teksturu
            gl.MatrixMode(OpenGL.GL_TEXTURE);                                            // UINUTAR TEXT MATRICE SE SKALIRA ,mora da bi mogle transformacije sa teksturama
            gl.PushMatrix();                                                             //unutar texture space se sad sve ovo radi
            gl.Scale(10, 10, 1);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);                                          //vracamo na model view

            gl.PushMatrix();
            //gl.Translate(0.0f, 0.0f, -120f);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Normal(0f, 1f, 0f); //normala za podlogu
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.TexCoord(0f, 0f);   //koordinate teksture za podlogu
            gl.Vertex(200f, -0.5f, -200f);
            gl.TexCoord(0f, 1f);
            gl.Vertex(-200f, -0.5f, -200f);
            gl.TexCoord(1f, 1f);
            gl.Vertex(-200f, -0.5f, 200f);
            gl.TexCoord(1f, 0f);
            gl.Vertex(200f, -0.5f, 200f);
            gl.End();
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.WOOD]); //drvo za mol i stubove

            if (Modulate)
            {
                gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            }


            gl.Translate(0.0f, 0.0f, 120f);
            //cube
            Cube cube = new Cube();

            gl.PushMatrix();
            gl.Color(0.5f, 0.5f, 0.5f);
            gl.Translate(0.0f, 20.0f, 70.0f);
            gl.Scale(30.0f, 5.0f, 30.0f); //dimenzije
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //gl.Scale(size, size, size); //dimenzije

            //cilindar1
            gl.PushMatrix();
            gl.Translate(-20.0f, -2.0f, 90.0f);
            gl.Translate(0, 25, 0);     //I VRATI ZA 25 NA GORE DA GORNNJA IVICA BUDE ISPOD KOCKE (3)
            gl.Scale(size, size, size); //SKLIARA SE ZA ONO SA SLEJDERA (2)
            gl.Translate(0, -25, 0);    //VISINA IM JE 25, ZATO -25 DA BUDE GORANJA IVICA NA 0 JER TADA SKALIRANJE SIRI STUB SAMO DOLE (1)

            gl.Rotate(-90f, 0f, 0f);

            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            Cylinder cil = new Cylinder();

            cil.TextureCoords = true;//KOORDIANTE TEKSTURA ZA CILINDRE
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //cilindar2
            gl.PushMatrix();
            gl.Translate(20.0f, -2.0f, 90.0f);
            gl.Translate(0, 25, 0);
            gl.Scale(size, size, size);//SKALIRANJE
            gl.Translate(0, -25, 0);
            gl.Rotate(-90f, 0f, 0f);
            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //cilindar3
            gl.PushMatrix();
            gl.Translate(20.0f, -2.0f, 50.0f);
            gl.Translate(0, 25, 0);
            gl.Scale(size, size, size);//SKALIRANJE
            gl.Translate(0, -25, 0);
            gl.Rotate(-90f, 0f, 0f);
            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //cilindar4
            gl.PushMatrix();
            gl.Translate(-20.0f, -2.0f, 50.0f);
            gl.Translate(0, 25, 0);
            gl.Scale(size, size, size);//SKALIRANJE
            gl.Translate(0, -25, 0);
            gl.Rotate(-90f, 0f, 0f);
            gl.Scale(5.0f, 5.0f, 5.0f); //dimenzije
            cil.CreateInContext(gl);
            cil.BaseRadius = 0.5;
            cil.Height     = 5;
            cil.TopRadius  = 0.5;
            cil.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();


            //cube stepenice(vrata)
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.METAL]); //metal za stepenice
            gl.PushMatrix();
            gl.Translate(0.0f + shipOffsetX, 0.0f, 50.0f + shipOffsetZ);                 //pomera brod
            gl.Rotate(0, shipRotation, 0);
            Cube cubeStairs = new Cube();

            gl.PushMatrix();
            gl.Color(0.5f, 0.50f, 0.50f);
            gl.Translate(0.0f, stairsY, -53.0f); //poemri da se ivica poklopi sa brodom, stairsY KAD NEMA ANIMACIJE JE 40, TOKOM ANIMACIJE JE NA POCETKU -20 KASNIJE SE PODIZE
            gl.Rotate(-stairs, 1f, 0.0f, 0.0f);  //ROTIRA ZA ONO SA SLAJDERA, TOKOM ANIMACIJE SE ISTO OVO MENJA
            gl.Scale(30.0f, 1.0f, 30.0f);        //dimenzije
            gl.Translate(0, 1, 1);               //pomeri se da bi se skalirao samo na gore u prema molu
            cube.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD); //za brod je stapanje ADD
            gl.Translate(-20.0f, 0f, 0.0f);                                              //priblizi se brod molu
            gl.Color(0.5f, 0.50f, 0.50f);

            gl.Scale(0.2f, 0.32f, 0.32f);
            m_scene.Draw();

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_DECAL); //ZA OSTALO OPET VRATIMO NA DECAL
            gl.PopMatrix();



            gl.PopMatrix();
            // Oznaci kraj iscrtavanja
            //Tekst
            gl.PushMatrix();
            gl.DrawText(m_width - 200, 90, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Predmet:Racunarska grafika");
            gl.DrawText(m_width - 200, 90, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "_______________________");
            gl.DrawText(m_width - 200, 70, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Sk.god: 2020/21.");
            gl.DrawText(m_width - 200, 70, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "______________");
            gl.DrawText(m_width - 200, 50, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Ime: Maja ");
            gl.DrawText(m_width - 200, 50, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "________");
            gl.DrawText(m_width - 200, 30, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Prezime: Dragojlovic");
            gl.DrawText(m_width - 200, 30, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "________________");
            gl.DrawText(m_width - 200, 10, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "Sifra zad: 10.1");
            gl.DrawText(m_width - 200, 10, 1.0f, 1.0f, 0.0f, "Helvetica", 14, "____________");
            gl.PopMatrix();
            gl.Flush();
        }
Beispiel #22
0
        private void drawShooting(OpenGL gl)
        {
            if (step == 15)
            {
                step     = 1;
                shooting = false;
                gore     = true;
                dole     = false;
                count    = 0;
                main.animationDone();
                main = null;
            }
            if (zoom >= 600)
            {
                zoom = 600;
            }
            if (zoom <= -300)
            {
                zoom = -300;
            }
            if (m_xRotation <= -20)
            {
                m_xRotation = -17;
            }
            else if (m_xRotation >= 50)
            {
                m_xRotation = 50;
            }

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.MatrixMode(OpenGL.GL_PROJECTION);      // selektuj Projection Matrix

            gl.LoadIdentity();
            gl.Perspective(50.0, (double)m_width / (double)m_height, 0.5, 1500.0);
            gl.LookAt(0f, 0f, 200f, 0f, 0f, -600, 0f, 1f, 0f);

            // Sacuvaj stanje modelview matrice i primeni transformacije
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();

            gl.PushMatrix();


            gl.Translate(0, 0, zoom);
            gl.Rotate(m_xRotation, 1.0f, 0.0f, 0.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);
            gl.PushMatrix();

            SetupLighting(gl);

            gl.Viewport(0, 0, m_width, m_height);
            gl.PushMatrix();


            //kamera

            #region PODLOGA
            gl.PushMatrix();
            gl.Translate(0.0f, 0f, 0f);
            gl.Color(0.42f, 0.81f, 0.67f);
            //da li treba ovde da se postavi za normalizaciju, ili u inicijalizaciji
            gl.Enable(OpenGL.GL_NORMALIZE);

            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Grass]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);

            gl.LoadIdentity();
            gl.Scale(10, 10, 10);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Begin(OpenGL.GL_QUADS);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex4f(600f, -200f, 1000, 1);
            gl.TexCoord(0.0f, 1.0f); gl.Vertex4f(-600f, -200f, 1000, 1);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex4f(-600f, -200f, -1200, 1);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex4f(600f, -200f, -1200, 1);
            gl.End();
            gl.PopMatrix();
            #endregion
            #region MODEL
            gl.PushMatrix();
            gl.Translate(10.0f, (-191 + scaleBall / 2) + count, -300);
            gl.Translate(-180f / 15 * step, (-20 - ((-191 + scaleBall / 2) + count)) / 15 * step, -430 / 15 * step);
            step++;
            if (gore)
            {
                count += 3;
            }
            if (dole)
            {
                count -= 3;
            }
            rotateBall += rotateBall0;
            gl.Rotate(rotateBall, 0, 1, 0);
            gl.Color(1f, 1f, 1f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Ball]);
            gl.Scale(scaleBall, scaleBall, scaleBall);
            m_scene.Draw();
            gl.PopMatrix();
            #endregion
            #region GOL
            //levo

            gl.PushMatrix();
            gl.Translate(-180f, -200f, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Rotate(-90, 1.0f, 0.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil1 = new Cylinder();
            cil1.Slices        = 50;
            cil1.Height        = 40;
            cil1.BaseRadius    = 2;
            cil1.TopRadius     = 2;
            cil1.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil1.CreateInContext(gl);
            cil1.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //desno
            gl.PushMatrix();
            gl.Translate(180f, -200, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Rotate(-90, 1.0f, 0.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil2 = new Cylinder();
            cil2.Slices        = 50;
            cil2.Height        = 40;
            cil2.BaseRadius    = 2;
            cil2.TopRadius     = 2;
            cil2.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil2.CreateInContext(gl);
            cil2.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //gore
            gl.PushMatrix();
            gl.Translate(-192f, 0f, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil3 = new Cylinder();
            cil3.Height        = 76.8;
            cil3.Slices        = 50;
            cil3.BaseRadius    = 2;
            cil3.TopRadius     = 2;
            cil3.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil3.CreateInContext(gl);
            cil3.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //iza levo dole
            gl.PushMatrix();
            gl.Translate(-180f, -190f, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(180, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil4 = new Cylinder();
            cil4.Height        = 20;
            cil4.Slices        = 50;
            cil4.BaseRadius    = 2;
            cil4.TopRadius     = 2;
            cil4.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil4.CreateInContext(gl);
            cil4.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //iza desno dole
            gl.PushMatrix();
            gl.Translate(180f, -190f, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(180, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil5 = new Cylinder();
            cil5.Height        = 20;
            cil5.Slices        = 50;
            cil5.BaseRadius    = 2;
            cil5.TopRadius     = 2;
            cil5.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil5.CreateInContext(gl);
            cil5.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //iza dole
            gl.PushMatrix();
            gl.Translate(-190f, -195f, -700);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil6 = new Cylinder();
            cil6.Height        = 74.5;
            cil6.Slices        = 50;
            cil6.BaseRadius    = 1;
            cil6.TopRadius     = 1;
            cil6.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil6.CreateInContext(gl);
            cil6.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //iza gore
            gl.PushMatrix();
            gl.Translate(-190f, -25f, -700);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil11 = new Cylinder();
            cil11.Height        = 74.5;
            cil11.Slices        = 50;
            cil11.BaseRadius    = 1;
            cil11.TopRadius     = 1;
            cil11.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil11.CreateInContext(gl);
            cil11.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //levo iza dole
            gl.PushMatrix();
            gl.Translate(-180f, -200f, -690);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Rotate(-90, 1.0f, 0.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil7 = new Cylinder();
            cil7.Slices        = 50;
            cil7.Height        = 35;
            cil7.BaseRadius    = 1;
            cil7.TopRadius     = 1;
            cil7.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil7.CreateInContext(gl);
            cil7.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            //desno iza dole
            gl.PushMatrix();
            gl.Translate(180f, -200f, -690);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Rotate(-90, 1.0f, 0.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil8 = new Cylinder();
            cil8.Slices        = 50;
            cil8.Height        = 35;
            cil8.BaseRadius    = 1;
            cil8.TopRadius     = 1;
            cil8.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil8.CreateInContext(gl);
            cil8.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //desno iza gore
            gl.PushMatrix();
            gl.Translate(180f, 0, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Rotate(90, 1.0f, 0.0f, 0.0f);
            gl.Rotate(75, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil9 = new Cylinder();
            cil9.Slices        = 50;
            cil9.Height        = 22;
            cil9.BaseRadius    = 1;
            cil9.TopRadius     = 1;
            cil9.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil9.CreateInContext(gl);
            cil9.Render(gl, RenderMode.Render);
            gl.PopMatrix();

            //desno iza gore
            gl.PushMatrix();
            gl.Translate(-180f, 0, -600);
            gl.Scale(5, 5, 5);
            gl.Rotate(90, 0.0f, 1.0f, 0.0f);
            gl.Rotate(90, 1.0f, 0.0f, 0.0f);
            gl.Rotate(75, 0.0f, 1.0f, 0.0f);
            gl.Color(0.5f, 0.5f, 0.5f);

            Cylinder cil10 = new Cylinder();
            cil10.Slices        = 50;
            cil10.Height        = 22;
            cil10.BaseRadius    = 1;
            cil10.TopRadius     = 1;
            cil10.TextureCoords = true;
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Plastic]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            cil10.CreateInContext(gl);
            cil10.Render(gl, RenderMode.Render);
            gl.PopMatrix();
            gl.PopMatrix();
            #endregion
            #region TEKST
            gl.PushMatrix();
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            gl.Color(0, 0, 0);
            gl.Viewport(m_width - 200, m_height - 150, 200, 150);
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Ortho2D(-5.0, 10.0, 0, 6.0);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();
            gl.PushMatrix();
            gl.Color(0, 0, 0);
            String[] tekst = { "Predmet: Racunarska grafika", "Sk.god: 2017/18", "Ime: Nina", "Prezime: Miladinovic", "Sifra zad: 9.2" };
            for (int i = 0; i < tekst.Length; i++)
            {
                gl.PushMatrix();
                gl.Translate(-5.0f, 5.0f - i, 0f);
                gl.DrawText3D("Arial Bold", 10f, 1f, 0.1f, tekst[i]);
                gl.PopMatrix();
            }
            gl.PopMatrix();
            gl.PopMatrix();

            #endregion
            gl.PopMatrix();
            gl.PopMatrix();
            gl.PopMatrix();
            gl.Flush();
        }
 protected override void DoInitialize()
 {
     {
         var computeProgram = new ShaderProgram();
         var shaderCode     = new ShaderCode(File.ReadAllText(
                                                 @"06ImageProcessing\ImageProcessing.comp"), ShaderType.ComputeShader);
         var shader = shaderCode.CreateShader();
         computeProgram.Create(shader);
         shader.Delete();
         this.computeProgram = computeProgram;
     }
     {
         Bitmap bitmap = new System.Drawing.Bitmap(this.textureFilename);
         if (bitmap.Width != 512 || bitmap.Height != 512)
         {
             bitmap = (Bitmap)bitmap.GetThumbnailImage(512, 512, null, IntPtr.Zero);
         }
         OpenGL.GenTextures(1, this.input_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.input_image[0]);
         //  Lock the image bits (so that we can pass them to OGL).
         BitmapData bitmapData = bitmap.LockBits(
             new Rectangle(0, 0, bitmap.Width, bitmap.Height),
             ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA32F,
                           bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                           bitmapData.Scan0);
         //  Unlock the image.
         bitmap.UnlockBits(bitmapData);
         /* We require 1 byte alignment when uploading texture data */
         //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
         /* Clamping to edges is important to prevent artifacts when scaling */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
         /* Linear filtering usually looks best for text */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
         bitmap.Dispose();
     }
     {
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.intermediate_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.intermediate_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         // This is the texture that the compute program will write into
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.output_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.output_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         var          bufferable   = new ImageProcessingModel();
         ShaderCode[] simpleShader = new ShaderCode[2];
         simpleShader[0] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.vert"), ShaderType.VertexShader);
         simpleShader[1] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("vert", "position");
         propertyNameMap.Add("uv", "uv");
         var pickableRenderer = new PickableRenderer(
             bufferable, simpleShader, propertyNameMap, "position");
         pickableRenderer.Name = string.Format("Pickable: [ImageProcessingRenderer]");
         pickableRenderer.Initialize();
         pickableRenderer.SetUniform("output_image",
                                     new samplerValue(
                                         BindTextureTarget.Texture2D, this.output_image[0], OpenGL.GL_TEXTURE0));
         this.renderer = pickableRenderer;
     }
 }
Beispiel #24
0
 public void Bind()
 {
     _gl.BindTexture(OpenGL.GL_TEXTURE_2D, Handle);
 }
Beispiel #25
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.Enable(OpenGL.GL_CULL_FACE);
            gl.LoadIdentity();

            gl.LookAt(0f, eyey, m_sceneDistance,
                      0f, centery, -10f,
                      0f, 1f, 0f);

            SetupLighting(gl); //mora ovim redoslijedom da bi bio izvor svjetlosti stacionaran!!!

            gl.PushMatrix();
            //gl.Translate(0.0f, 0.0f, -m_sceneDistance);   //0.0f za z osu
            gl.Rotate(m_xRotation, 1.0f, 0.0f, 0.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);

            gl.Viewport(0, 0, m_width, m_height);

            //zamak
            gl.PushMatrix();
            //gl.Color(0f, 0f, 1f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Castle]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);   //nacin spajanja teksture sa materijalom na modulate
            gl.Scale(0.1f, 0.1f, 0.1f);
            castle_scene.Draw();
            gl.PopMatrix();

            //strijela
            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Castle]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            gl.Translate(arrow_translateX, arrow_translateY, arrow_translateZ);
            gl.Rotate(arrow_rotateX, arrow_rotateY, arrow_rotateZ);
            gl.Scale(arrow_scale, arrow_scale, arrow_scale);
            //gl.Scale(30f, 30f, 30f);
            arrow_scene.Draw();
            gl.PopMatrix();

            //podloga
            gl.PushMatrix();
            //gl.Color(0.3f, 50.4f, 0.3f);
            gl.Translate(0f, -0.1f, -20f);
            gl.Disable(OpenGL.GL_CULL_FACE);    //iskljucio da bi mi se vidjela podloga
            gl.Enable(OpenGL.GL_NORMALIZE);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Grass]);

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.LoadIdentity();
            //gl.Scale(5, 5, 5);      //skaliranje teksture
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Begin(OpenGL.GL_QUADS);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(-90f, 0f, 100f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(-90f, 0f, -30f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(90f, 0f, -30f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(90f, 0f, 100f);
            gl.End();
            gl.PopMatrix();

            //staza
            gl.PushMatrix();
            //gl.Color(0.36f, 0.25f, 0.20f);
            gl.Translate(0f, 0f, 0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Mud]);
            gl.Enable(OpenGL.GL_NORMALIZE);
            gl.Begin(OpenGL.GL_QUADS);      //crtano u x i z ravni
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(-5f, 0f, 80f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(-5f, 0f, 0f);
            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(5f, 0f, 0f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(5f, 0f, 80f);
            gl.End();
            gl.PopMatrix();

            //lijevi zid
            gl.PushMatrix();
            //gl.Color(0.85f, 0.53f, 0.10f);
            gl.Translate(-wall_translateX, 15.0f, 0f);
            //gl.Translate(-65.0f, 15.0f, 0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Fence]);
            gl.Scale(3.0f, 15.0f, 40.0f);   //kolika je visina zida, toliko sam stavio da bude i translacija
            zid.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //desni zid
            gl.PushMatrix();
            //gl.Color(0.85f, 0.53f, 0.10f);
            gl.Translate(65.0f, 15.0f, 0f);
            gl.Rotate(0.0f, wall_rotateY, 0.0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.Fence]);
            gl.Scale(3.0f, 15.0f, 40.0f);   //kolika je visina zida, toliko sam stavio da bude i translacija
            zid.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            //text
            DrawText1(gl);

            gl.PopMatrix();

            // Oznaci kraj iscrtavanja
            gl.Flush();
        }
Beispiel #26
0
        /// <summary>
        ///  Iscrtavanje OpenGL kontrole.
        /// </summary>
        public void Draw(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Viewport(0, 0, m_width, m_height);
            gl.PushMatrix();
            gl.LookAt(0, 0, m_sceneDistance, 0, 0, 0, 0, 1, 0);
            gl.Rotate(m_xRotation, 1.0f, 0.0f, 0.0f);
            gl.Rotate(m_yRotation, 0.0f, 1.0f, 0.0f);

            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_SPOT_DIRECTION, new float[] { 0.0f, -1.0f, 0.0f });
            float[] pos = { 0f, 300F, 105f, 1.0f };
            gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_POSITION, pos);


            gl.PushMatrix();
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.TRAVA]);
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.PushMatrix();
            gl.Scale(3, 3, 3);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Normal(0, 1f, 0);
            gl.Color(0.1f, 0.1f, 0.1f);
            gl.TexCoord(0f, 0f);
            gl.Vertex(300f, 0.0f, -300f);
            gl.TexCoord(0f, 1f);

            gl.Vertex(-300f, 0.0f, -300f);
            gl.TexCoord(1f, 1f);

            gl.Vertex(-300f, 0.0f, 300f);
            gl.TexCoord(1f, 0f);
            gl.Vertex(300f, 0.0f, 300f);
            gl.End();
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(-100.0f, 0.0f, -100.0f - distance);
            gl.Scale(3f, 250f, 3f);
            gl.Rotate(-90f, 1, 0, 0);
            gl.Color(1.0f, 1.0f, 1.0f);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.PLASTIKA]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_MODULATE);
            Cylinder target = new Cylinder();

            target.TextureCoords = true;
            target.TopRadius     = 1;
            target.CreateInContext(gl);
            target.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(100.0f, 0.0f, -100.0f - distance);
            gl.Scale(3f, 250f, 3f);
            gl.Rotate(-90f, 1, 0, 0);
            Cylinder target1 = new Cylinder();

            //target1.NormalGeneration = Normals.Smooth;
            target1.TextureCoords = true;
            target1.TopRadius     = 1;
            target1.CreateInContext(gl);
            target1.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();

            gl.PushMatrix();
            gl.Translate(0f, 100.0f, -100f - distance);
            gl.Scale(100f, 3f, 3f);
            gl.Rotate(90f, 1, 0, 0);
            Cylinder target2 = new Cylinder();

            target2.TextureCoords = true;
            target2.TopRadius     = 1;
            target2.CreateInContext(gl);
            target2.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);

            gl.PushMatrix();
            gl.Translate(0, jumpH + 10 * size, 100 - ballDistance);

            gl.Rotate(jumpR, 0, 0);
            gl.Translate(0, -10 * size, 0);
            gl.Scale(size, size, size);
            gl.Color(0.3f, 0.3f, 0.3f);
            gl.Rotate(-90, 0, 0);
            m_scene.Draw();
            gl.PopMatrix();

            gl.PopMatrix();



            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.Viewport(m_width / 2, 0, m_width / 2, m_height / 2);
            gl.LoadIdentity();

            gl.Ortho2D(-20.0f, 20.0f, -20.0f, 20.0f);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();
            gl.Color(0.5f, 0.1f, 0.1f);
            gl.PushMatrix();
            gl.Translate(5f, -15f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "Predmet:Racunarska grafika");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -15f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "_______________________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -16f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "Sk.god:2020/21");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -16f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "_____________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -17f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "Ime:Nastasja");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -17f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "___________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -18f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "Prezime:Damjanac");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -18f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "_______________");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -19f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "Sifra zad:7.2");
            gl.PopMatrix();
            gl.PushMatrix();
            gl.Translate(5f, -19f, 0f);
            gl.DrawText3D("Tahoma", 10, 1.0f, 0, "__________");
            gl.PopMatrix();

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.Viewport(0, 0, m_width, m_height);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Flush();
        }
        protected override void DoInitialize()
        {
            {
                var computeProgram = new ShaderProgram();
                var shaderCode     = new ShaderCode(File.ReadAllText(@"05ParticleSimulator\particleSimulator.comp"), ShaderType.ComputeShader);
                var shader         = shaderCode.CreateShader();
                computeProgram.Create(shader);
                shader.Delete();
                this.computeProgram = computeProgram;
            }
            {
                //var bufferable = new ParticleSimulatorCompute();
                OpenGL.GetDelegateFor <OpenGL.glGenVertexArrays>()(1, render_vao);
                OpenGL.GetDelegateFor <OpenGL.glBindVertexArray>()(render_vao[0]);
                // position
                OpenGL.GetDelegateFor <OpenGL.glGenBuffers>()(1, position_buffer);
                OpenGL.BindBuffer(BufferTarget.ArrayBuffer, position_buffer[0]);
                var positions = new UnmanagedArray <vec4>(ParticleSimulatorCompute.particleCount);
                unsafe
                {
                    var array = (vec4 *)positions.Header.ToPointer();
                    for (int i = 0; i < ParticleSimulatorCompute.particleCount; i++)
                    {
                        array[i] = new vec4(
                            (float)(random.NextDouble() - 0.5) * 20,
                            (float)(random.NextDouble() - 0.5) * 20,
                            (float)(random.NextDouble() - 0.5) * 20,
                            (float)(random.NextDouble())
                            );
                    }
                }
                OpenGL.BufferData(BufferTarget.ArrayBuffer, positions, BufferUsage.DynamicCopy);
                positions.Dispose();
                OpenGL.GetDelegateFor <OpenGL.glVertexAttribPointer>()(0, 4, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
                OpenGL.GetDelegateFor <OpenGL.glEnableVertexAttribArray>()(0);
                // velocity
                OpenGL.GetDelegateFor <OpenGL.glGenBuffers>()(1, velocity_buffer);
                OpenGL.BindBuffer(BufferTarget.ArrayBuffer, velocity_buffer[0]);
                var velocities = new UnmanagedArray <vec4>(ParticleSimulatorCompute.particleCount);
                unsafe
                {
                    var array = (vec4 *)velocities.Header.ToPointer();
                    for (int i = 0; i < ParticleSimulatorCompute.particleCount; i++)
                    {
                        array[i] = new vec4(
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            (float)(random.NextDouble() - 0.5) * 0.2f,
                            0);
                    }
                }
                OpenGL.BufferData(BufferTarget.ArrayBuffer, velocities, BufferUsage.DynamicCopy);
                velocities.Dispose();
                //GL.GetDelegateFor<GL.glVertexAttribPointer>()(0, 4, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                //GL.GetDelegateFor<GL.glEnableVertexAttribArray>()(0);
                //
                OpenGL.GenTextures(1, textureBufferPosition);
                OpenGL.BindTexture(OpenGL.GL_TEXTURE_BUFFER, textureBufferPosition[0]);
                OpenGL.GetDelegateFor <OpenGL.glTexBuffer>()(OpenGL.GL_TEXTURE_BUFFER, OpenGL.GL_RGBA32F, position_buffer[0]);
                OpenGL.GenTextures(1, textureBufferVelocity);
                OpenGL.BindTexture(OpenGL.GL_TEXTURE_BUFFER, textureBufferVelocity[0]);
                OpenGL.GetDelegateFor <OpenGL.glTexBuffer>()(OpenGL.GL_TEXTURE_BUFFER, OpenGL.GL_RGBA32F, velocity_buffer[0]);

                OpenGL.GetDelegateFor <OpenGL.glGenBuffers>()(1, attractor_buffer);
                OpenGL.BindBuffer(BufferTarget.UniformBuffer, attractor_buffer[0]);
                OpenGL.GetDelegateFor <OpenGL.glBufferData>()(OpenGL.GL_UNIFORM_BUFFER, 64 * Marshal.SizeOf(typeof(vec4)), IntPtr.Zero, OpenGL.GL_DYNAMIC_COPY);
                OpenGL.GetDelegateFor <OpenGL.glBindBufferBase>()(OpenGL.GL_UNIFORM_BUFFER, 0, attractor_buffer[0]);
            }
            {
                var visualProgram = new ShaderProgram();
                var shaderCodes   = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"05ParticleSimulator\particleSimulator.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"05ParticleSimulator\particleSimulator.frag"), ShaderType.FragmentShader);
                var shaders = (from item in shaderCodes select item.CreateShader()).ToArray();
                visualProgram.Create(shaders);
                foreach (var item in shaders)
                {
                    item.Delete();
                }
                this.visualProgram = visualProgram;
            }
        }
        /// Handles the OpenGLDraw event of the openGLControl control.
        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            if (isGPSPositionInitialized)
            {
                //  Get the OpenGL object.
                OpenGL gl = openGLControl.OpenGL;
                //System.Threading.Thread.Sleep(500);

                //  Clear the color and depth buffer.
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                gl.LoadIdentity();

                //camera does translations and rotations
                camera.SetWorldCam(gl, pivotAxleEasting, fixPosY, pivotAxleNorthing, fixHeadingCam);

                //calculate the frustum planes for culling
                CalcFrustum(gl);

                //draw the field ground images
                worldGrid.DrawFieldSurface();

                //Draw the world grid based on camera position
                gl.Disable(OpenGL.GL_DEPTH_TEST);
                gl.Disable(OpenGL.GL_TEXTURE_2D);

                //if grid is on draw it
                if (isGridOn)
                {
                    worldGrid.DrawWorldGrid(gridZoom);
                }


                //turn on blend for paths
                gl.Enable(OpenGL.GL_BLEND);

                //section patch color
                gl.Color(redSections, grnSections, bluSections, (byte)160);
                if (isDrawPolygons)
                {
                    gl.PolygonMode(OpenGL.GL_FRONT, OpenGL.GL_LINE);
                }

                //draw patches of sections
                for (int j = 0; j < vehicle.numSuperSection; j++)
                {
                    //every time the section turns off and on is a new patch
                    int patchCount = section[j].patchList.Count;

                    //check if in frustum or not
                    bool isDraw;

                    if (patchCount > 0)
                    {
                        //initialize the steps for mipmap of triangles (skipping detail while zooming out)
                        int mipmap = 0;
                        if (camera.camSetDistance < -800)
                        {
                            mipmap = 2;
                        }
                        if (camera.camSetDistance < -1500)
                        {
                            mipmap = 4;
                        }
                        if (camera.camSetDistance < -2400)
                        {
                            mipmap = 8;
                        }
                        if (camera.camSetDistance < -4800)
                        {
                            mipmap = 16;
                        }

                        //for every new chunk of patch
                        foreach (var triList in section[j].patchList)
                        {
                            isDraw = false;
                            int count2 = triList.Count;
                            for (int i = 0; i < count2; i += 3)
                            {
                                //determine if point is in frustum or not, if < 0, its outside so abort
                                if (frustum[0] * triList[i].x + frustum[2] * triList[i].z + frustum[3] <= 0)
                                {
                                    continue;//right
                                }
                                if (frustum[4] * triList[i].x + frustum[6] * triList[i].z + frustum[7] <= 0)
                                {
                                    continue;//left
                                }
                                if (frustum[16] * triList[i].x + frustum[18] * triList[i].z + frustum[19] <= 0)
                                {
                                    continue;//bottom
                                }
                                if (frustum[20] * triList[i].x + frustum[22] * triList[i].z + frustum[23] <= 0)
                                {
                                    continue;//top
                                }
                                if (frustum[8] * triList[i].x + frustum[10] * triList[i].z + frustum[11] <= 0)
                                {
                                    continue;//far
                                }
                                if (frustum[12] * triList[i].x + frustum[14] * triList[i].z + frustum[15] <= 0)
                                {
                                    continue;//near
                                }
                                //point is in frustum so draw the entire patch. The downside of triangle strips.
                                isDraw = true;
                                break;
                            }

                            if (isDraw)
                            {
                                //draw the triangle in each triangle strip
                                gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
                                count2 = triList.Count;

                                //if large enough patch and camera zoomed out, fake mipmap the patches, skip triangles
                                if (count2 >= (mipmap + 2))
                                {
                                    int step = mipmap;
                                    for (int i = 0; i < count2; i += step)
                                    {
                                        gl.Vertex(triList[i].x, 0, triList[i].z); i++;
                                        gl.Vertex(triList[i].x, 0, triList[i].z); i++;

                                        //too small to mipmap it
                                        if (count2 - i <= (mipmap + 2))
                                        {
                                            step = 0;
                                        }
                                    }
                                }

                                else
                                {
                                    for (int i = 0; i < count2; i++)
                                    {
                                        gl.Vertex(triList[i].x, 0, triList[i].z);
                                    }
                                }
                                gl.End();
                            }
                        }
                    }
                }


                gl.PolygonMode(OpenGL.GL_FRONT, OpenGL.GL_FILL);
                gl.Color(1, 1, 1);

                //draw contour line if button on
                if (ct.isContourBtnOn)
                {
                    ct.DrawContourLine();
                }

                // draw the current and reference AB Lines
                else
                {
                    if (ABLine.isABLineSet | ABLine.isABLineBeingSet)
                    {
                        ABLine.DrawABLines();
                    }
                }

                //draw the flags if there are some
                int flagCnt = flagPts.Count;
                if (flagCnt > 0)
                {
                    for (int f = 0; f < flagCnt; f++)
                    {
                        gl.PointSize(8.0f);
                        gl.Begin(OpenGL.GL_POINTS);
                        if (flagPts[f].color == 0)
                        {
                            gl.Color((byte)255, (byte)0, (byte)flagPts[f].ID);
                        }
                        if (flagPts[f].color == 1)
                        {
                            gl.Color((byte)0, (byte)255, (byte)flagPts[f].ID);
                        }
                        if (flagPts[f].color == 2)
                        {
                            gl.Color((byte)255, (byte)255, (byte)flagPts[f].ID);
                        }
                        gl.Vertex(flagPts[f].easting, 0, flagPts[f].northing);
                        gl.End();
                    }

                    if (flagNumberPicked != 0)
                    {
                        ////draw the box around flag
                        gl.LineWidth(4);
                        gl.Color(0.980f, 0.0f, 0.980f);
                        gl.Begin(OpenGL.GL_LINE_STRIP);

                        double offSet = (zoomValue * zoomValue * 0.01);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, 0, flagPts[flagNumberPicked - 1].northing + offSet);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting - offSet, 0, flagPts[flagNumberPicked - 1].northing);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, 0, flagPts[flagNumberPicked - 1].northing - offSet);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting + offSet, 0, flagPts[flagNumberPicked - 1].northing);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, 0, flagPts[flagNumberPicked - 1].northing + offSet);

                        gl.End();

                        //draw the flag with a black dot inside
                        gl.PointSize(4.0f);
                        gl.Color(0, 0, 0);
                        gl.Begin(OpenGL.GL_POINTS);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, 0, flagPts[flagNumberPicked - 1].northing);
                        gl.End();
                    }
                }

                //draw the perimter line, returns if no line to draw
                periArea.DrawPerimeterLine();

                //screen text for debug
                //gl.DrawText(10, 15, 1, 1, 1, "Courier", 14, " Dist " + ABLine.distanceFromCurrentLine);
                //gl.DrawText(10, 30, 1, 1, 1, "Courier", 14, "delta " + Convert.ToString((double)(guidanceLineHeadingDelta)/10000));
                //gl.DrawText(10, 45, 1, 1, 1, "Courier", 14, "  Tank " + Convert.ToString(fixHeadingTank ));
                //gl.DrawText(10, 60, 1, 1, 1, "Courier", 14, "  Sect " + Convert.ToString(fixHeadingSection));
                //gl.DrawText(10, 75, 1, 1, 1, "Courier", 16, "  overS " + Convert.ToString(overSect));
                //gl.DrawText(10, 90, 1, 1, 1, "Courier", 12, "   t " + Convert.ToString(t));
                //gl.DrawText(10, 105, 1, 0.5f, 1, "Courier", 12, " TrigSetDist(m) " + Convert.ToString(Math.Round(sectionTriggerStepDistance, 2)));
                //gl.DrawText(10, 120, 1, 0.5, 1, "Courier", 12, " frame msec " + Convert.ToString((int)(frameTime)));

                //draw the vehicle/implement
                vehicle.DrawVehicle();

                //Back to normal
                gl.Color(0.98f, 0.98f, 0.98f);
                gl.Disable(OpenGL.GL_BLEND);
                gl.Enable(OpenGL.GL_DEPTH_TEST);

                //// 2D Ortho --------------------------
                gl.MatrixMode(OpenGL.GL_PROJECTION);
                gl.PushMatrix();
                gl.LoadIdentity();

                //negative and positive on width, 0 at top to bottom ortho view
                gl.Ortho2D(-(double)Width / 2, (double)Width / 2, (double)Height, 0);

                //  Create the appropriate modelview matrix.
                gl.MatrixMode(OpenGL.GL_MODELVIEW);
                gl.PushMatrix();
                gl.LoadIdentity();

                if (skyToolStripMenu.Checked)
                {
                    ////draw the background when in 3D
                    if (camera.camPitch > -31)
                    {
                        //-10 to -32 (top) is camera pitch range. Set skybox to line up with horizon
                        double hite = (camera.camPitch + 32) / 22 * 0.38;

                        //the background
                        double winLeftPos  = -(double)Width / 2;
                        double winRightPos = -winLeftPos;

                        gl.Enable(OpenGL.GL_TEXTURE_2D);
                        gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture[0]);                 // Select Our Texture
                        gl.Begin(OpenGL.GL_TRIANGLE_STRIP);                               // Build Quad From A Triangle Strip
                        gl.TexCoord(0, 0); gl.Vertex(winRightPos, 0.0);                   // Top Right
                        gl.TexCoord(1, 0); gl.Vertex(winLeftPos, 0.0);                    // Top Left
                        gl.TexCoord(0, 1); gl.Vertex(winRightPos, hite * (double)Height); // Bottom Right
                        gl.TexCoord(1, 1); gl.Vertex(winLeftPos, hite * (double)Height);  // Bottom Left
                        gl.End();                                                         // Done Building Triangle Strip

                        //disable, straight color
                        gl.Disable(OpenGL.GL_TEXTURE_2D);
                    }
                }

                //LightBar if AB Line is set and turned on
                if (isLightbarOn)
                {
                    if (ct.isContourBtnOn)
                    {
                        txtDistanceOffABLine.Visible = true;
                        DrawLightBar(openGLControl.Width, openGLControl.Height, ct.distanceFromCurrentLine * 0.1);
                        txtDistanceOffABLine.Text = " " + Convert.ToString((int)Math.Abs(ct.distanceFromCurrentLine * 0.1)) + " ";
                        if (Math.Abs(ABLine.distanceFromCurrentLine) > 15.0)
                        {
                            txtDistanceOffABLine.ForeColor = Color.Yellow;
                        }
                        else
                        {
                            txtDistanceOffABLine.ForeColor = Color.LightGreen;
                        }
                    }

                    else
                    {
                        if (ABLine.isABLineSet | ABLine.isABLineBeingSet)
                        {
                            txtDistanceOffABLine.Visible = true;
                            DrawLightBar(openGLControl.Width, openGLControl.Height, ABLine.distanceFromCurrentLine * 0.1);
                            txtDistanceOffABLine.Text = " " + Convert.ToString((int)Math.Abs(ABLine.distanceFromCurrentLine * 0.1)) + " ";
                            if (Math.Abs(ABLine.distanceFromCurrentLine) > 15.0)
                            {
                                txtDistanceOffABLine.ForeColor = Color.Yellow;
                            }
                            else
                            {
                                txtDistanceOffABLine.ForeColor = Color.LightGreen;
                            }
                        }
                    }

                    //AB line is not set so turn off numbers
                    if (!ABLine.isABLineSet & !ABLine.isABLineBeingSet & !ct.isContourBtnOn)
                    {
                        txtDistanceOffABLine.Visible = false;
                    }
                }

                else
                {
                    txtDistanceOffABLine.Visible = false;
                }
                gl.Flush();     //finish openGL commands

                gl.PopMatrix(); //  Pop the modelview.

                //  back to the projection and pop it, then back to the model view.
                gl.MatrixMode(OpenGL.GL_PROJECTION);
                gl.PopMatrix();
                gl.MatrixMode(OpenGL.GL_MODELVIEW);

                //reset point size
                gl.PointSize(1.0f);
                gl.Flush();


                if (leftMouseDownOnOpenGL)
                {
                    leftMouseDownOnOpenGL = false;
                    byte[] data1 = new byte[192];

                    //scan the center of click and a set of square points around
                    gl.ReadPixels(mouseX - 4, mouseY - 4, 8, 8, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, data1);

                    //made it here so no flag found
                    flagNumberPicked = 0;

                    for (int ctr = 0; ctr < 192; ctr += 3)
                    {
                        if (data1[ctr] == 255 | data1[ctr + 1] == 255)
                        {
                            flagNumberPicked = data1[ctr + 2];
                            break;
                        }
                    }
                }

                //draw the section control window off screen buffer
                openGLControlBack.DoRender();
            }
        }
Beispiel #29
0
        private void LoadTextures()
        {
            int texCount = 0;

            foreach (Material material in m_scene.Materials)
            {
                foreach (TextureSlot texSlot in material.GetAllTextures())
                {
                    texCount++;
                }
            }

            m_texIds = new uint[texCount];
            gl.GenTextures(texCount, m_texIds);

            int index = 0;

            foreach (Material material in m_scene.Materials)
            {
                foreach (TextureSlot texSlot in material.GetAllTextures())
                {
                    m_texMappings[texSlot] = m_texIds[index];

                    // Pridruzi teksturu odgovarajucem identifikatoru.
                    gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_texIds[index]);

                    // Formiranje putanje do fajla koji predstavlja teksturu.
                    String fileName = Path.Combine(m_scenePath, texSlot.FilePath.StartsWith("/") ? texSlot.FilePath.Substring(1) : texSlot.FilePath);
                    if (!File.Exists(fileName))
                    {
                        throw new ArgumentException();
                    }

                    // Ucitavanje teksture iz datog fajla.
                    Bitmap     textureBitmap = new Bitmap(fileName);
                    BitmapData textureData   = textureBitmap.LockBits(new Rectangle(0, 0, textureBitmap.Width, textureBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA8, textureData.Width, textureData.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, textureData.Scan0);

                    // Podesavanje filtriranja teksture.
                    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);

                    // Podesavanje ponavljanja teksture za dati materijal.
                    if (texSlot.WrapModeU == TextureWrapMode.Clamp)
                    {
                        gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP);
                    }
                    if (texSlot.WrapModeV == TextureWrapMode.Clamp)
                    {
                        gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP);
                    }
                    if (texSlot.WrapModeU == TextureWrapMode.Wrap)
                    {
                        gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT);
                    }
                    if (texSlot.WrapModeV == TextureWrapMode.Wrap)
                    {
                        gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT);
                    }

                    // Oslobadjanje resursa teksture.
                    textureBitmap.UnlockBits(textureData);
                    textureBitmap.Dispose();

                    index++;
                }
            }
        }
Beispiel #30
0
 /// <summary>
 /// Bind to the specified OpenGL instance.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public void Bind(OpenGL gl)
 {
     //	Bind our texture object (make it the current texture).
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);
 }
Beispiel #31
0
        //{------------------------------------------------------------------}
        //{  Function to draw the actual scene                               }
        //{------------------------------------------------------------------}
        internal void glDraw(OpenGL gl)
        {
            //int x = 0, y = 0, z = 0;
            int   cx, cy, cz;
            float c           = 0;
            int   ElapsedTime = elapsedMillisecs;

            gl.Color(1.0f, 1.0f, 1.0f);
            // Clear The Screen And The Depth Buffer
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            // Reset The View
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -2.5f);

            gl.Disable(OpenGL.GL_TEXTURE_GEN_S);
            gl.Disable(OpenGL.GL_TEXTURE_GEN_T);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 2);
            gl.Begin(OpenGL.GL_QUADS);
            gl.TexCoord(0, 0); gl.Vertex(-1.5, -1.1, 0);
            gl.TexCoord(1, 0); gl.Vertex(1.5, -1.1, 0);
            gl.TexCoord(1, 1); gl.Vertex(1.5, 1.1, 0);
            gl.TexCoord(0, 1); gl.Vertex(-1.5, 1.1, 0);
            gl.End();
            gl.Enable(OpenGL.GL_TEXTURE_GEN_S);
            gl.Enable(OpenGL.GL_TEXTURE_GEN_T);

            gl.Rotate(ElapsedTime / 30, 0, 0, 1);

            c             = (float)(0.15f * Math.Cos(ElapsedTime / 600.0f));
            MetaBall[1].X = (float)(-0.3f * Math.Cos(ElapsedTime / 700.0f) - c);
            MetaBall[1].Y = (float)(0.3f * Math.Sin(ElapsedTime / 600.0f) - c);

            MetaBall[2].X = (float)(0.4f * Math.Sin(ElapsedTime / 400.0f) + c);
            MetaBall[2].Y = (float)(0.4f * Math.Cos(ElapsedTime / 400.0f) - c);

            MetaBall[3].X = (float)(-0.4f * Math.Cos(ElapsedTime / 400.0f) - 0.2f * Math.Sin(ElapsedTime / 600.0f));
            MetaBall[3].Y = (float)(0.4f * Math.Sin(ElapsedTime / 500.0f) - 0.2f * Math.Sin(ElapsedTime / 400.0f));

            TessTriangles = 0;
            for (cx = 0; cx < GridSize + 1; cx++)
            {
                for (cy = 0; cy < GridSize + 1; cy++)
                {
                    for (cz = 0; cz < GridSize + 1; cz++)
                    {
                        Grid[cx, cy, cz].Value = 0;

                        // go through all meta balls
                        for (int I = 1; I < 4; I++)
                        {
                            Grid[cx, cy, cz].Value = Grid[cx, cy, cz].Value + MetaBall[I].Radius * MetaBall[I].Radius / ((Grid[cx, cy, cz].Pos.X - MetaBall[I].X) * (Grid[cx, cy, cz].Pos.X - MetaBall[I].X) + (Grid[cx, cy, cz].Pos.Y - MetaBall[I].Y) * (Grid[cx, cy, cz].Pos.Y - MetaBall[I].Y) + (Grid[cx, cy, cz].Pos.Z - MetaBall[I].Z) * (Grid[cx, cy, cz].Pos.Z - MetaBall[I].Z));
                        }
                    }
                }
            }

            //Copy Values from Grid to the Cubes
            for (cx = 0; cx < GridSize - 1; cx++)
            {
                for (cy = 0; cy < GridSize - 1; cy++)
                {
                    for (cz = 0; cz < GridSize - 1; cz++)
                    {
                        Cubes[cx, cy, cz].GridPoint[0] = Grid[cx, cy, cz];
                        Cubes[cx, cy, cz].GridPoint[1] = Grid[cx + 1, cy, cz];
                        Cubes[cx, cy, cz].GridPoint[2] = Grid[cx + 1, cy, cz + 1];
                        Cubes[cx, cy, cz].GridPoint[3] = Grid[cx, cy, cz + 1];
                        Cubes[cx, cy, cz].GridPoint[4] = Grid[cx, cy + 1, cz];
                        Cubes[cx, cy, cz].GridPoint[5] = Grid[cx + 1, cy + 1, cz];
                        Cubes[cx, cy, cz].GridPoint[6] = Grid[cx + 1, cy + 1, cz + 1];
                        Cubes[cx, cy, cz].GridPoint[7] = Grid[cx, cy + 1, cz + 1];
                    }
                }
            }

            // Calculate normals at the grid vertices
            for (cx = 1; cx < GridSize - 1; cx++)
            {
                for (cy = 1; cy < GridSize - 1; cy++)
                {
                    for (cz = 1; cz < GridSize - 1; cz++)
                    {
                        Grid[cx, cy, cz].Normal.X = Grid[cx - 1, cy, cz].Value - Grid[cx + 1, cy, cz].Value;
                        Grid[cx, cy, cz].Normal.Y = Grid[cx, cy - 1, cz].Value - Grid[cx, cy + 1, cz].Value;
                        Grid[cx, cy, cz].Normal.Z = Grid[cx, cy, cz - 1].Value - Grid[cx, cy, cz + 1].Value;
                    }
                }
            }

            // Draw the metaballs by drawing the triangle in each cube in the grid
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 1);
            gl.Begin(OpenGL.GL_TRIANGLES);
            for (cx = 0; cx < GridSize; cx++)
            {
                for (cy = 0; cy < GridSize; cy++)
                {
                    for (cz = 0; cz < GridSize; cz++)
                    {
                        CreateCubeTriangles(gl, Cubes[cx, cy, cz]);
                    }
                }
            }
            gl.End();
        }
Beispiel #32
0
        /// <summary>
        /// This function creates the texture from an image.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="image">The image.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public virtual bool Create(OpenGL gl, Bitmap image, uint textureParameter = OpenGL.GL_LINEAR)
        {
            //  Create the underlying OpenGL object.
            Create(gl);

            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth  = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                {
                    targetWidth = size;
                }
            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                {
                    targetHeight = size;
                }
            }

            //  If need to scale, do so now.
            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);

                //  Destory the old image, and reset.
                image.Dispose();
                image = (Bitmap)newImage;
            }

            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                   ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            //	Set the width and height.
            width  = image.Width;
            height = image.Height;

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                          width, height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                          bitmapData.Scan0);

            //  Unlock the image.
            image.UnlockBits(bitmapData);

            //  Dispose of the image file.
            image.Dispose();

            //  Set linear filtering mode.
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, textureParameter);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, textureParameter);

            //  We're done!
            return(true);
        }
Beispiel #33
0
        /// Handles the OpenGLDraw event of the openGLControl control.
        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            if (isGPSPositionInitialized)
            {
                //  Get the OpenGL object.
                OpenGL gl = openGLControl.OpenGL;
                //System.Threading.Thread.Sleep(500);

                //  Clear the color and depth buffer.
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                gl.LoadIdentity();

                //camera does translations and rotations
                camera.SetWorldCam(gl, pn.easting, pn.northing, camHeading);

                //draw the field ground images
                worldGrid.DrawFieldSurface();

                ////Draw the world grid based on camera position
                gl.Disable(OpenGL.GL_DEPTH_TEST);
                gl.Disable(OpenGL.GL_TEXTURE_2D);


                gl.Enable(OpenGL.GL_LINE_SMOOTH);
                gl.Enable(OpenGL.GL_BLEND);

                gl.Hint(OpenGL.GL_LINE_SMOOTH_HINT, OpenGL.GL_FASTEST);
                gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_FASTEST);
                gl.Hint(OpenGL.GL_POLYGON_SMOOTH_HINT, OpenGL.GL_FASTEST);

                ////if grid is on draw it
                if (isGridOn)
                {
                    worldGrid.DrawWorldGrid(gridZoom);
                }

                //turn on blend for paths
                gl.Enable(OpenGL.GL_BLEND);

                //section patch color
                gl.Color(redSections, grnSections, bluSections, (byte)160);
                if (isDrawPolygons)
                {
                    gl.PolygonMode(OpenGL.GL_FRONT, OpenGL.GL_LINE);
                }

                gl.PolygonMode(OpenGL.GL_FRONT, OpenGL.GL_FILL);
                gl.Color(1, 1, 1);

                //draw contour line if button on
                //if (ct.isContourBtnOn)


                // draw the current and reference AB Lines
                if (ABLine.isABLineSet | ABLine.isABLineBeingSet)
                {
                    ABLine.DrawABLines();
                }
                else
                {
                    ct.DrawContourLine();
                }

                //draw the flags if there are some
                int flagCnt = flagPts.Count;
                if (flagCnt > 0)
                {
                    for (int f = 0; f < flagCnt; f++)
                    {
                        gl.PointSize(8.0f);
                        gl.Begin(OpenGL.GL_POINTS);
                        if (flagPts[f].color == 0)
                        {
                            gl.Color((byte)255, (byte)0, (byte)flagPts[f].ID);
                        }
                        if (flagPts[f].color == 1)
                        {
                            gl.Color((byte)0, (byte)255, (byte)flagPts[f].ID);
                        }
                        if (flagPts[f].color == 2)
                        {
                            gl.Color((byte)255, (byte)255, (byte)flagPts[f].ID);
                        }
                        gl.Vertex(flagPts[f].easting, flagPts[f].northing, 0);
                        gl.End();
                    }

                    if (flagNumberPicked != 0)
                    {
                        ////draw the box around flag
                        gl.LineWidth(4);
                        gl.Color(0.980f, 0.0f, 0.980f);
                        gl.Begin(OpenGL.GL_LINE_STRIP);

                        double offSet = (zoomValue * zoomValue * 0.01);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, flagPts[flagNumberPicked - 1].northing + offSet, 0);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting - offSet, flagPts[flagNumberPicked - 1].northing, 0);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, flagPts[flagNumberPicked - 1].northing - offSet, 0);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting + offSet, flagPts[flagNumberPicked - 1].northing, 0);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, flagPts[flagNumberPicked - 1].northing + offSet, 0);

                        gl.End();

                        //draw the flag with a black dot inside
                        gl.PointSize(4.0f);
                        gl.Color(0, 0, 0);
                        gl.Begin(OpenGL.GL_POINTS);
                        gl.Vertex(flagPts[flagNumberPicked - 1].easting, flagPts[flagNumberPicked - 1].northing, 0);
                        gl.End();
                    }
                }

                //screen text for debug
                //gl.DrawText(120, 10, 1, 1, 1, "Courier Bold", 18, "Head: " + saveCounter.ToString("N1"));
                //gl.DrawText(120, 40, 1, 1, 1, "Courier Bold", 18, "Tool: " + distTool.ToString("N1"));
                //gl.DrawText(120, 70, 1, 1, 1, "Courier Bold", 18, "Where: " + yt.whereAmI.ToString());
                //gl.DrawText(120, 100, 1, 1, 1, "Courier Bold", 18, "Seq: " + yt.isSequenceTriggered.ToString());
                //gl.DrawText(120, 40, 1, 1, 1, "Courier Bold", 18, "  GPS: " + Convert.ToString(Math.Round(glm.toDegrees(gpsHeading), 2)));
                //gl.DrawText(120, 70, 1, 1, 1, "Courier Bold", 18, "Fixed: " + Convert.ToString(Math.Round(glm.toDegrees(gyroCorrected), 2)));
                //gl.DrawText(120, 100, 1, 1, 1, "Courier Bold", 18, "L/Min: " + Convert.ToString(rc.CalculateRateLitersPerMinute()));
                //gl.DrawText(120, 130, 1, 1, 1, "Courier", 18, "       Roll: " + Convert.ToString(glm.toDegrees(rollDistance)));
                //gl.DrawText(120, 160, 1, 1, 1, "Courier", 18, "       Turn: " + Convert.ToString(Math.Round(turnDelta, 4)));
                //gl.DrawText(40, 120, 1, 0.5, 1, "Courier", 12, " frame msec " + Convert.ToString((int)(frameTime)));

                //draw the vehicle/implement
                vehicle.DrawVehicle();

                //Back to normal
                gl.Color(0.98f, 0.98f, 0.98f);
                gl.Disable(OpenGL.GL_BLEND);
                gl.Enable(OpenGL.GL_DEPTH_TEST);

                //// 2D Ortho --------------------------
                gl.MatrixMode(OpenGL.GL_PROJECTION);
                gl.PushMatrix();
                gl.LoadIdentity();

                //negative and positive on width, 0 at top to bottom ortho view
                gl.Ortho2D(-(double)Width / 2, (double)Width / 2, (double)Height, 0);

                //  Create the appropriate modelview matrix.
                gl.MatrixMode(OpenGL.GL_MODELVIEW);
                gl.PushMatrix();
                gl.LoadIdentity();

                if (isSkyOn)
                {
                    ////draw the background when in 3D
                    if (camera.camPitch < -60)
                    {
                        //-10 to -32 (top) is camera pitch range. Set skybox to line up with horizon
                        double hite = (camera.camPitch + 60) / -20 * 0.34;
                        //hite = 0.001;

                        //the background
                        double winLeftPos  = -(double)Width / 2;
                        double winRightPos = -winLeftPos;
                        gl.Enable(OpenGL.GL_TEXTURE_2D);
                        gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture[0]);                 // Select Our Texture

                        gl.Begin(OpenGL.GL_TRIANGLE_STRIP);                               // Build Quad From A Triangle Strip
                        gl.TexCoord(0, 0); gl.Vertex(winRightPos, 0.0);                   // Top Right
                        gl.TexCoord(1, 0); gl.Vertex(winLeftPos, 0.0);                    // Top Left
                        gl.TexCoord(0, 1); gl.Vertex(winRightPos, hite * (double)Height); // Bottom Right
                        gl.TexCoord(1, 1); gl.Vertex(winLeftPos, hite * (double)Height);  // Bottom Left
                        gl.End();                                                         // Done Building Triangle Strip

                        //disable, straight color
                        gl.Disable(OpenGL.GL_TEXTURE_2D);
                    }
                }

                //LightBar if AB Line is set and turned on or contour
                if (isLightbarOn)
                {
                    if (ct.isContourBtnOn)
                    {
                        string dist;
                        txtDistanceOffABLine.Visible = true;
                        //lblDelta.Visible = true;
                        if (ct.distanceFromCurrentLine == 32000)
                        {
                            ct.distanceFromCurrentLine = 0;
                        }

                        DrawLightBar(openGLControl.Width, openGLControl.Height, ct.distanceFromCurrentLine * 0.1);
                        if ((ct.distanceFromCurrentLine) < 0.0)
                        {
                            txtDistanceOffABLine.ForeColor = Color.Green;
                            if (isMetric)
                            {
                                dist = ((int)Math.Abs(ct.distanceFromCurrentLine * 0.1)) + " ->";
                            }
                            else
                            {
                                dist = ((int)Math.Abs(ct.distanceFromCurrentLine / 2.54 * 0.1)) + " ->";
                            }
                            txtDistanceOffABLine.Text = dist;
                        }

                        else
                        {
                            txtDistanceOffABLine.ForeColor = Color.Red;
                            if (isMetric)
                            {
                                dist = "<- " + ((int)Math.Abs(ct.distanceFromCurrentLine * 0.1));
                            }
                            else
                            {
                                dist = "<- " + ((int)Math.Abs(ct.distanceFromCurrentLine / 2.54 * 0.1));
                            }
                            txtDistanceOffABLine.Text = dist;
                        }

                        //if (guidanceLineHeadingDelta < 0) lblDelta.ForeColor = Color.Red;
                        //else lblDelta.ForeColor = Color.Green;

                        if (guidanceLineDistanceOff == 32020 | guidanceLineDistanceOff == 32000)
                        {
                            btnAutoSteer.Text = "-";
                        }
                        else
                        {
                            btnAutoSteer.Text = "Y";
                        }
                    }

                    else
                    {
                        if (ABLine.isABLineSet | ABLine.isABLineBeingSet)
                        {
                            string dist;

                            txtDistanceOffABLine.Visible = true;
                            //lblDelta.Visible = true;
                            DrawLightBar(openGLControl.Width, openGLControl.Height, ABLine.distanceFromCurrentLine * 0.1);
                            if ((ABLine.distanceFromCurrentLine) < 0.0)
                            {
                                // --->
                                txtDistanceOffABLine.ForeColor = Color.Green;
                                if (isMetric)
                                {
                                    dist = ((int)Math.Abs(ABLine.distanceFromCurrentLine * 0.1)) + " ->";
                                }
                                else
                                {
                                    dist = ((int)Math.Abs(ABLine.distanceFromCurrentLine / 2.54 * 0.1)) + " ->";
                                }
                                txtDistanceOffABLine.Text = dist;
                            }

                            else
                            {
                                // <----
                                txtDistanceOffABLine.ForeColor = Color.Red;
                                if (isMetric)
                                {
                                    dist = "<- " + ((int)Math.Abs(ABLine.distanceFromCurrentLine * 0.1));
                                }
                                else
                                {
                                    dist = "<- " + ((int)Math.Abs(ABLine.distanceFromCurrentLine / 2.54 * 0.1));
                                }
                                txtDistanceOffABLine.Text = dist;
                            }

                            //if (guidanceLineHeadingDelta < 0) lblDelta.ForeColor = Color.Red;
                            //else lblDelta.ForeColor = Color.Green;
                            if (guidanceLineDistanceOff == 32020 | guidanceLineDistanceOff == 32000)
                            {
                                btnAutoSteer.Text = "-";
                            }
                            else
                            {
                                btnAutoSteer.Text = "Y";
                            }
                        }
                    }

                    //AB line is not set so turn off numbers
                    if (!ABLine.isABLineSet & !ABLine.isABLineBeingSet & !ct.isContourBtnOn)
                    {
                        txtDistanceOffABLine.Visible = false;
                        btnAutoSteer.Text            = "-";
                    }
                }
                else
                {
                    txtDistanceOffABLine.Visible = false;
                    btnAutoSteer.Text            = "-";
                }

                gl.Flush();     //finish openGL commands
                gl.PopMatrix(); //  Pop the modelview.

                //  back to the projection and pop it, then back to the model view.
                gl.MatrixMode(OpenGL.GL_PROJECTION);
                gl.PopMatrix();
                gl.MatrixMode(OpenGL.GL_MODELVIEW);

                //reset point size
                gl.PointSize(1.0f);
                gl.Flush();

                if (leftMouseDownOnOpenGL)
                {
                    leftMouseDownOnOpenGL = false;
                    byte[] data1 = new byte[192];

                    //scan the center of click and a set of square points around
                    gl.ReadPixels(mouseX - 4, mouseY - 4, 8, 8, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, data1);

                    //made it here so no flag found
                    flagNumberPicked = 0;

                    for (int ctr = 0; ctr < 192; ctr += 3)
                    {
                        if (data1[ctr] == 255 | data1[ctr + 1] == 255)
                        {
                            flagNumberPicked = data1[ctr + 2];
                            break;
                        }
                    }
                }


                //digital input Master control (WorkSwitch)
                if (isJobStarted && mc.isWorkSwitchEnabled)
                {
                    //check condition of work switch
                    if (mc.isWorkSwitchActiveLow)
                    {
                        //if (mc.workSwitchValue == 0)
                    }
                    else
                    {
                        //if (mc.workSwitchValue == 1)
                    }
                }

                //stop the timer and calc how long it took to do calcs and draw
                frameTime = (double)swFrame.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency * 1000;

                //if a couple minute has elapsed save the field in case of crash and to be able to resume
                if (saveCounter > 60)       //2 counts per second X 60 seconds = 120 counts per minute.
                {
                    if (isJobStarted && stripOnlineGPS.Value != 1)
                    {
                        //auto save the field patches, contours accumulated so far
                        FileSaveField();
                        //FileSaveContour();

                        //NMEA log file
                        if (isLogNMEA)
                        {
                            FileSaveNMEA();
                        }
                    }
                    saveCounter = 0;
                }

                openGLControlBack.DoRender();
            }
        }
Beispiel #34
0
        public void loadFloor(OpenGL gl)
        {
            gl.PushMatrix();
            gl.Translate(-100f, -300f, 550f);
            gl.Scale(80, 20, 90);

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, m_textures[(int)TextureObjects.BETON]);
            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_DECAL);
            gl.MatrixMode(OpenGL.GL_TEXTURE);
            //gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.Begin(OpenGL.GL_QUADS);

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

            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(30, 1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(30, 1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(-30, 1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(-30, 1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(30, 1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(-30, 1, 15);
            gl.TexCoord(0, 0);
            gl.Vertex(-30, -1, 15);
            gl.TexCoord(0, 1);
            gl.Vertex(30, -1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(30, -1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(30, -1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(30, 1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(30, 1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(-30, -1, 15);
            gl.TexCoord(1, 0);
            gl.Vertex(-30, -1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(30, -1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(30, -1, 15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(-30, -1, -15);
            gl.TexCoord(1, 0);
            gl.Vertex(-30, -1, 15);
            gl.TexCoord(0, 0);
            gl.Vertex(-30, 1, 15);
            gl.TexCoord(0, 1);
            gl.Vertex(-30, 1, -15);

            gl.Color(0f, 0f, 0f);
            gl.Normal(0f, 1f, 0f);
            gl.TexCoord(1, 1);
            gl.Vertex(-30, 1, -15);
            gl.TexCoord(1, 0);
            gl.Vertex(30, 1, -15);
            gl.TexCoord(0, 0);
            gl.Vertex(30, -1, -15);
            gl.TexCoord(0, 1);
            gl.Vertex(-30, -1, -15);

            gl.End();

            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);

            gl.PopMatrix();
        }
Beispiel #35
0
        /// <summary>
        /// This function creates the texture from an image.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="image">The image.</param>
        /// <returns>True if the texture was successfully loaded.</returns>
        public virtual bool Create(OpenGL gl, Bitmap image)
        {
            //  Create the underlying OpenGL object.
            Create(gl);

            //	Get the maximum texture size supported by OpenGL.
            int[] textureMaxSize = { 0 };
            gl.GetInteger(OpenGL.GL_MAX_TEXTURE_SIZE, textureMaxSize);

            //	Find the target width and height sizes, which is just the highest
            //	posible power of two that'll fit into the image.
            int targetWidth = textureMaxSize[0];
            int targetHeight = textureMaxSize[0];

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Width < size)
                {
                    targetWidth = size / 2;
                    break;
                }
                if (image.Width == size)
                    targetWidth = size;

            }

            for (int size = 1; size <= textureMaxSize[0]; size *= 2)
            {
                if (image.Height < size)
                {
                    targetHeight = size / 2;
                    break;
                }
                if (image.Height == size)
                    targetHeight = size;
            }

            //  If need to scale, do so now.
            if (image.Width != targetWidth || image.Height != targetHeight)
            {
                //  Resize the image.
                Image newImage = image.GetThumbnailImage(targetWidth, targetHeight, null, IntPtr.Zero);

                //  Destory the old image, and reset.
                image.Dispose();
                image = (Bitmap)newImage;
            }

            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            //	Set the width and height.
            width = image.Width;
            height = image.Height;

            //	Bind our texture object (make it the current texture).
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, TextureName);

            //  Set the image data.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                width, height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                bitmapData.Scan0);

            //  Unlock the image.
            image.UnlockBits(bitmapData);

            //  Dispose of the image file.
            image.Dispose();

            //  Set linear filtering mode.
            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);

            //  We're done!
            return true;
        }
Beispiel #36
0
 public void Bind(OpenGL gl)
 {
     gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureObject);
 }