Exemplo n.º 1
0
 public void drawHealth(float health)
 {
     healthtTex.Bind();
     if (myType == HealthType.Player)
     {
         Gl.glBegin(Gl.GL_QUADS);
         Gl.glVertex3f(9f, position.y, 52.5f);
         Gl.glVertex3f(9f - (health * 7), position.y, 52.5f);
         Gl.glVertex3f(9f - (health * 7), position.y, 54);
         Gl.glVertex3f(9f, position.y, 54);
         Gl.glEnd();
     }
     else if (myType == HealthType.Enemy)
     {
         Gl.glBegin(Gl.GL_QUADS);
         Gl.glVertex3f(-15, 0, 50);
         Gl.glVertex3f(-15 + (health * 30), 0, 50);
         Gl.glVertex3f(-15 + (health * 30), 0, 55);
         Gl.glVertex3f(-15, 0, 55);
         Gl.glEnd();
     }
 }
Exemplo n.º 2
0
        public void Draw_Health(Shader shader2D)
        {
            //Gl.glDisable(Gl.GL_DEPTH_TEST);
            //use 2D shader
            shader2D.UseShader();
            //draw 2D square
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, hpID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)0);

            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            //background of healthbar
            Gl.glUniformMatrix4fv(mloc, 1, Gl.GL_FALSE, backhealthbar.to_array());
            //bhp.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            //decrease the health bar by scaling down the 2D front square
            //scalef -= 0.0001f;
            //if (scalef < 0)
            //    scalef = 0;
            healthbar = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.scale(new mat4(1), new vec3(0.5f * 1, 0.1f, 1)), glm.translate(new mat4(1), new vec3(-0.5f - ((1 - 1) * 0.48f), 0.9f, 0))
            });
            Gl.glUniformMatrix4fv(mloc, 1, Gl.GL_FALSE, healthbar.to_array());
            hp.Bind();
            //draw front health bar
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            //re-enable the depthtest to draw the other 3D objects in the scene
            // Gl.glEnable(Gl.GL_DEPTH_TEST);

            ////Gl.glDisableVertexAttribArray(0);
            ////Gl.glDisableVertexAttribArray(1);

            ////Gl.glDisableVertexAttribArray(0);
            ////Gl.glDisableVertexAttribArray(1);
        }
Exemplo n.º 3
0
        public void Draw()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            Shader3D.UseShader();

            /*WaterShader.UseShader();*/

            //water motion

            /*if (reverse)
             *  t -= 0.0002f;
             * else
             *  t += 0.0002f;
             * if (t > 0.2f)
             *  reverse = true;
             * if (t < 0)
             *  reverse = false;
             * Gl.glUniform1f(WaterTimeID, t);*/

            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, camera.GetProjectionMatrix().to_array());
            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, camera.GetViewMatrix().to_array());
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, scaleMatrix.to_array());

            //SKYBOX START
            GPU.BindBuffer(SkyboxBufferID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), IntPtr.Zero);
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(3 * sizeof(float)));

            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(6 * sizeof(float)));

            FrontTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            BottomTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 18, 6);

            BackTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 6, 6);

            LeftTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 30, 6);

            RightTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 24, 6);

            TopTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 12, 6);
            //SKYBOX END

            //WATER START
            mat4 WaterModel = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.translate(new mat4(1), new vec3(-30, -65, -100)),
                glm.scale(new mat4(1), new vec3(2.5f, 0.6f, 0.6f))
            });

            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, WaterModel.to_array());

            GPU.BindBuffer(WaterBufferID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), IntPtr.Zero);

            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            WaterTexture.Bind();
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);

            Gl.glDrawArrays(Gl.GL_TRIANGLE_STRIP, 0, TerrainImage.Height / 4 * TerrainImage.Width / 4);

            Gl.glDisable(Gl.GL_BLEND);

            /*WaterTexture.Bind();
             * Gl.glEnable(Gl.GL_BLEND);
             * Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
             * ground.Draw(transID);
             * Gl.glDisable(Gl.GL_BLEND);*/

            //WATER END

            //TREE START
            for (int i = 0; i < 4500 - 3; i += 100)
            {
                //tree.scalematrix = glm.scale(new mat4(1), new vec3(2f, 2.5f, 2f));
                tree.transmatrix = glm.translate(new mat4(1), new vec3(TreeVertices[i], -1 * TreeVertices[i + 1], TreeVertices[i + 2]));
                tree.Draw(transID);
            }
            //TREE END

            //GRASS START
            mat4 GrassModel = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.translate(new mat4(1), new vec3(-30, -65, -100)),
                glm.scale(new mat4(1), new vec3(1.5f, .3f, .3f))
            });

            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, GrassModel.to_array());

            GPU.BindBuffer(GrassBufferID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), IntPtr.Zero);

            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            GrassTexture.Bind();

            for (int i = 0; i < GrassVertices.Count;)
            {
                Gl.glDrawArrays(Gl.GL_TRIANGLES, i, 5);
                i += 5;
            }
            //GRASS END

            //TERRAIN START
            mat4 model = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.translate(new mat4(1), new vec3(-30, -65, -100)), glm.scale(new mat4(1), new vec3(0.9f, 0.6f, 0.6f))
            });                                                                                                                                                                      //b3ml tranformations 3l terrain

            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, model.to_array());

            GPU.BindBuffer(TerrainBufferID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), IntPtr.Zero);

            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            BottomTexture.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLE_STRIP, 0, TerrainImage.Height * TerrainImage.Width);

            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SOURCE0_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            //TERRAIN END

            Gl.glDisableVertexAttribArray(0);
            Gl.glDisableVertexAttribArray(1);
        }
Exemplo n.º 4
0
        public void Draw()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            sh.UseShader();

            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());

            //send the value of camera position (eye position)

            // m.TranslationMatrix = glm.translate(new mat4(1), new vec3(100, 0, 0)); //zombie
            m.Draw(transID);

            // enemy2.TranslationMatrix = glm.translate(new mat4(1), new vec3(50, 0, 0)); //zombie
            enemy2.Draw(transID);

            //ground draw
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vertexBufferID);
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, modelmatrix.to_array());
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), IntPtr.Zero);
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(6 * sizeof(float)));
            //enable another vertex attribute for normals
            //describe the attribute and recompute the stride for all attributes
            Gl.glEnableVertexAttribArray(3);
            Gl.glVertexAttribPointer(3, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(8 * sizeof(float)));
            tex1.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            ///////////////////////////////skybox draw & textures/////////////////////////////////////////////
            GPU.BindBuffer(SkyboxBufferID);
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, SkyboxBufferID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 9 * sizeof(float), IntPtr.Zero);
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 9 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 9 * sizeof(float), (IntPtr)(6 * sizeof(float)));
            //cube coord
            GPU.BindBuffer(cubeCoordID);
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 0, (IntPtr)(0));

            Downtex.Bind();
            //Gl.glDrawArrays(Gl.GL_TRIANGLES,0,36);
            Gl.glDrawArrays(Gl.GL_QUADS, 0, 4);

            Uptex.Bind();
            Gl.glDrawArrays(Gl.GL_QUADS, 4, 4);

            Backtex.Bind();
            Gl.glDrawArrays(Gl.GL_QUADS, 8, 4);

            Righttex.Bind();
            Gl.glDrawArrays(Gl.GL_QUADS, 12, 4);

            Fronttex.Bind();
            Gl.glDrawArrays(Gl.GL_QUADS, 16, 4);

            Lefttex.Bind();
            Gl.glDrawArrays(Gl.GL_QUADS, 20, 4);

            building.Draw(transID); // PROBLEM HERE
            tree.Draw(transID);     //passing model id but its called transid
            spider.Draw(transID);
            jeep.Draw(transID);
            house.Draw(transID);

            /*
             * //triangle drawing
             * GPU.BindBuffer(vertexBufferID2);
             * Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, modelmatrix2.to_array());
             * Gl.glEnableVertexAttribArray(0);
             * Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 6 * sizeof(float), IntPtr.Zero);
             * Gl.glEnableVertexAttribArray(1);
             * Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 6 * sizeof(float), (IntPtr)(3 * sizeof(float)));
             * //coord
             * GPU.BindBuffer(TriangleCoordID);
             * Gl.glEnableVertexAttribArray(2);
             * Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 0, (IntPtr)(0));
             * tex.Bind();
             * //  Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, glm.translate(new mat4(1),cam.center).to_array());
             * Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 3);
             *
             * //2nd triangle drawing
             * //triangle drawing
             * GPU.BindBuffer(vertexBuffer2ID2);
             * Gl.glEnableVertexAttribArray(0);
             * Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 6 * sizeof(float), IntPtr.Zero);
             * Gl.glEnableVertexAttribArray(1);
             * Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 6 * sizeof(float), (IntPtr)(3 * sizeof(float)));
             * //coord
             * GPU.BindBuffer(TriangleCoord2ID);
             * Gl.glEnableVertexAttribArray(2);
             * Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 0, (IntPtr)(0));
             * textri2.Bind(); */


            //     Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, glm.translate(new mat4(1), (IntPtr)(0)));

            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 3);
        }
Exemplo n.º 5
0
        public void Draw()
        {
            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());

            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            sh.UseShader();
            // FOR DONW SQUARE
            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, skyboxBuffer_ID);
            //FOR POSITION
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(0 * sizeof(float)));
            //FOR COLOR
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            // FOR TEXTURE
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(6 * sizeof(float)));

            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
            float[] viewmat = cam.GetViewMatrix().to_array();
            viewmat[12] = 0;
            viewmat[13] = 0;
            viewmat[14] = 0;
            viewmat[15] = 1;
            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, viewmat);

            u.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, up.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            d.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, down.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            l.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, left.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            r.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, right.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            f.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, front.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            b.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, back.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            Gl.glUniform3fv(EyePositionID, 1, cam.GetCameraPosition().to_array());
            //ground
            Gl.glEnable(Gl.GL_DEPTH_TEST);

            groundTexture.Bind();
            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, ground.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            playerPos    = cam.GetCameraTarget();
            playerPos.y -= 2.8f;

            HandsWGun.transmatrix = glm.translate(new mat4(1), playerPos);
            HandsWGun.rotmatrix   = MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(-cam.mAngleY, new vec3(1, 0, 0)),
                glm.rotate(3.1412f + cam.mAngleX, new vec3(0, 1, 0))
            });


            spider.Draw(modelID);
            building.Draw(modelID);
            car.Draw(modelID);
            Blade.Draw(modelID);
            zombie.Draw(modelID);
            tree.Draw(modelID);
            HandsWGun.Draw(modelID);

            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, skyboxBuffer_ID);

            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(0 * sizeof(float)));
            //FOR COLOR
            Gl.glEnableVertexAttribArray(1);
            Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            // FOR TEXTURE
            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 8 * sizeof(float), (IntPtr)(6 * sizeof(float)));


            shoot.Bind();
            vec3 shootpos = cam.GetCameraTarget();

            shootpos.y -= 1.5f;
            shootpos   += cam.GetLookDirection() * 8;

            Gl.glUniformMatrix4fv(modelID, 1, Gl.GL_FALSE, MathHelper.MultiplyMatrices(new List <mat4>()
            {
                glm.rotate(cam.mAngleX, new vec3(0, 1, 0)), glm.rotate((float)c / 10, new vec3(0, 0, 1)),
                glm.translate(new mat4(1), shootpos)
            }).to_array());
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            if (draw)
            {
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
                c--;
                if (c < 0)
                {
                    c    = timer;
                    draw = false;
                }
            }
            Gl.glDisable(Gl.GL_BLEND);

            Gl.glDisable(Gl.GL_DEPTH_TEST);


            vec3 zombiePosition;

            zombiePosition.x = zombie.TranslationMatrix[3].x;
            zombiePosition.y = zombie.TranslationMatrix[3].y;
            zombiePosition.z = zombie.TranslationMatrix[3].z;

            vec3 zombieRotation = new vec3(0, -1, 0);

            zombieRotation = zombie.rotationMatrix.to_mat3() * zombieRotation;

            vec3 camposition = cam.GetCameraPosition();

            vec3 zombieDirection = camposition - zombiePosition;

            zombieDirection   = glm.normalize(zombieDirection);
            zombieDirection.y = 0;
            double distance = Math.Sqrt(Math.Pow(camposition.x - zombiePosition.x, 2) +
                                        Math.Pow(camposition.y - zombiePosition.y, 2) +
                                        Math.Pow(camposition.z - zombiePosition.z, 2));

            if (distance < Enemy_range_Run && distance > Enemy_range_Attack)
            {
                if (zombie.animSt.type != animType_LOL.RUN)
                {
                    zombie.StartAnimation(animType_LOL.RUN);
                }
                zombie.TranslationMatrix = glm.translate(zombie.TranslationMatrix, zombieDirection * zombieSpeed);
            }
            else if (distance < Enemy_range_Attack)
            {
                if (zombie.animSt.type != animType_LOL.ATTACK1)
                {
                    zombie.StartAnimation(animType_LOL.ATTACK1);
                }
            }
            else
            {
                if (zombie.animSt.type == animType_LOL.RUN)
                {
                    zombie.StartAnimation(animType_LOL.STAND);
                }
            }
            vec3 crossProduct = glm.cross(zombieRotation, zombieDirection);

            if (crossProduct.y != 0)
            {
                if (crossProduct.y > 0)
                {
                    zombie.rotationMatrix = glm.rotate(zombie.rotationMatrix, (float)(5.0 / 180.0 * Math.PI), new vec3(0, 0, 1));
                }
                else
                {
                    zombie.rotationMatrix = glm.rotate(zombie.rotationMatrix, (float)(-5.0 / 180.0 * Math.PI), new vec3(0, 0, 1));
                }
            }
            for (int i = 0; i < bullets.Count; i++)
            {
                bullets[i].Draw(modelID);
            }
        }
Exemplo n.º 6
0
 public void setTexture()
 {
     texture = new Texture(GraphicsForm.texturePath, 1);
     texture.Bind();
 }
Exemplo n.º 7
0
 public void Draw(int matID)
 {
     bulletTex.Bind();
     model.Draw(matID);
 }
Exemplo n.º 8
0
        public void Draw()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            sh.UseShader();

            if (!started)
            {
                hero.camera.UpdateViewMatrix();
                ProjectionMatrix = hero.camera.GetProjectionMatrix();
                ViewMatrix       = hero.camera.GetViewMatrix();
                Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
                Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
                Gl.glUniform3fv(EyePositionID, 1, hero.camera.GetCameraPosition().to_array());

                Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, screenBufferID);
                Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, modelmatrix.to_array());
                Gl.glEnableVertexAttribArray(0);
                Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), IntPtr.Zero);
                Gl.glEnableVertexAttribArray(1);
                Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(3 * sizeof(float)));
                Gl.glEnableVertexAttribArray(2);
                Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(6 * sizeof(float)));
                Gl.glEnableVertexAttribArray(3);
                Gl.glVertexAttribPointer(3, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(8 * sizeof(float)));
                screenTex.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            }
            else
            {
                Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
                Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
                Gl.glUniform3fv(EyePositionID, 1, hero.camera.GetCameraPosition().to_array());

                hero.Draw(transID);
                foreach (var enemy in enemiesList)
                {
                    enemy.Draw(transID);
                }
                foreach (var bullet in bulletsList)
                {
                    bullet.Draw(transID);
                }

                house.Draw(transID);
                jeep.Draw(transID);
                jeep2.Draw(transID);
                weaponTex.Bind();
                Weapon.Draw(transID);

                Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vertexBufferID);
                Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, modelmatrix.to_array());
                Gl.glEnableVertexAttribArray(0);
                Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), IntPtr.Zero);
                Gl.glEnableVertexAttribArray(1);
                Gl.glVertexAttribPointer(1, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(3 * sizeof(float)));
                Gl.glEnableVertexAttribArray(2);
                Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(6 * sizeof(float)));
                Gl.glEnableVertexAttribArray(3);
                Gl.glVertexAttribPointer(3, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 11 * sizeof(float), (IntPtr)(8 * sizeof(float)));
                up.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
                down.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 6, 6);
                left.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 12, 6);
                right.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 18, 6);
                front.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 24, 6);
                back.Bind();
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 30, 6);
            }
        }
Exemplo n.º 9
0
        public void Draw()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            sh.UseShader();
            mat4 nv = new mat4(ViewMatrix[0], ViewMatrix[1], ViewMatrix[2], ViewMatrix[3]);

            nv[3, 0] = 0;
            nv[3, 1] = 0;
            nv[3, 2] = 0;
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, scaleMat.to_array());
            Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, nv.to_array());


            Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vertexBufferID);
            Gl.glEnableVertexAttribArray(0);
            Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), IntPtr.Zero);

            Gl.glEnableVertexAttribArray(2);
            Gl.glVertexAttribPointer(2, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            //Gl.glDepthMask(0);
            front.Bind();
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            left.Bind();
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, leftmatrix.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            right.Bind();
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, rightmatrix.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            down.Bind();
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, groundmatrix.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            up.Bind();
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, upmatrix.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);
            back.Bind();
            Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, backmatrix.to_array());
            Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 6);

            //sh.UseShader();
            //Update(0);
            //Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, scaleMat.to_array());
            //Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());
            //Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            //Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, vertexBufferID2);
            //Gl.glEnableVertexAttribArray(0);
            //Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), IntPtr.Zero);

            //Gl.glEnableVertexAttribArray(1);
            //Gl.glVertexAttribPointer(1, 2, Gl.GL_FLOAT, Gl.GL_FALSE, 5 * sizeof(float), (IntPtr)(3 * sizeof(float)));
            //tex.Bind();
            //Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 3);
            //send the value of camera position (eye position)
            //Update(0.5f);
            //sh.UseShader();

            // Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());

            Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            m.Draw(transID);
            tree.Draw(transID);
            ////car.Draw(transID);
            cottage.Draw(transID);
            //// tree2.Draw(transID);
            treee3.Draw(transID);
            jeep.Draw(transID);
            //jeep2.Draw(transID);
            m2.Draw(transID);
            // Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            //Gl.glUniformMatrix4fv(projID, 1, Gl.GL_FALSE, ProjectionMatrix.to_array());



            m.AnimationSpeed = 0.01f;

            //  Gl.glUniformMatrix4fv(viewID, 1, Gl.GL_FALSE, ViewMatrix.to_array());
            // Gl.glUniformMatrix4fv(transID, 1, Gl.GL_FALSE, scaleMat.to_array());
            Gl.glDisableVertexAttribArray(0);
            Gl.glDisableVertexAttribArray(1);
            Gl.glDisableVertexAttribArray(2);
        }