예제 #1
0
        public void Render(Entity entity, StaticShader shader)
        {
            TexturedModel texturedModel = entity.TexturedModel;
            RawModel      model         = texturedModel.RawModel;

            GL.BindVertexArray(model.vaoID);
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            Matrix4 transformationMatrix = Maths.CreateTransformationMatrix(
                entity.Position,
                entity.RotationX,
                entity.RotationY,
                entity.RotationZ,
                entity.Scale);

            shader.LoadTransformationMatrix(ref transformationMatrix);

            ModelTexture modelTexture = entity.TexturedModel.Texture;

            shader.LoadShineVariables(modelTexture.ShineDamper, modelTexture.Reflectivity);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, texturedModel.Texture.TextureID);
            GL.DrawElements(PrimitiveType.Triangles, model.vertexCount, DrawElementsType.UnsignedInt, 0);
            GL.DisableVertexAttribArray(0);
            GL.DisableVertexAttribArray(1);
            GL.DisableVertexAttribArray(2);
            GL.BindVertexArray(0);
        }
예제 #2
0
 public EntityRenderer(StaticShader shader, Matrix4 projectionMatrix)
 {
     this.shader = shader;
     shader.Start();
     shader.LoadProjectionMatrix(projectionMatrix);
     shader.Stop();
 }
        public Renderer(int w, int h, StaticShader shader)
        {
            Width  = w;
            Height = h;

            CreateProjectionMatrix();
            shader.Start();
            shader.LoadProjectionMatrix(projectionMatrix);
            shader.Stop();
        }
예제 #4
0
 public Renderer(StaticShader shader)
 {
     projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(
         (float)((Math.PI / 180) * 70f),
         1280f / 720f,
         0.1f,
         1000f);
     shader.Use();
     shader.LoadProjectionMatrix(ref projectionMatrix);
     shader.UnUse();
 }
        public void Start()
        {
            loader   = new Loader();
            shader   = new StaticShader();
            cam      = new Camera();
            renderer = new Renderer(WIDTH, HEIGHT, shader);

            model = OBJLoader.LoadObjFile("Resources\\stall.obj", loader);
            //model = loader.LoadToVAO(vertices, textureCoords, indicies);
            modelTexture  = new ModelTexture(loader.LoadTexture("Resources\\stallimage.jpg"));
            texturedModel = new TexturedModel(model, modelTexture);

            entity = new Entity(texturedModel, new Vector3(0, 0, -25), 0, 0, 0, 1);

            Run(FPS_CAP);
        }
예제 #6
0
        public Game()
        {
            this.Display      = new DisplayManager(1280, 720);
            this.Loader       = new Loader();
            this.StaticShader = new StaticShader();
            this.Renderer     = new Renderer(this.StaticShader);

            //this.TestModel = this.Loader.LoadToVAO(vertices, textureCoords, indices);
            this.TestModel = OBJLoader.LoadModelOBJ("dragon", this.Loader);
            this.texture   = new ModelTexture(this.Loader.LoadTexture("white"));
            //this.texture.Reflectivity = 1;
            //this.texture.ShineDamper = 10;
            this.texturedModel = new TexturedModel(this.TestModel, this.texture);
            this.entity        = new Entity(this.texturedModel, new Vector3(0, 0f, -25f), 0, 0, 0, 0.1f);
            this.light         = new Light(new Vector3(0, 0, -30f), new Vector3(1f, 1f, 1f));
            this.camera        = new Camera();

            this.Init();
        }
        public void RenderEntity(Entity ent, StaticShader shader)
        {
            TexturedModel texturedModel = ent.Model;
            RawModel      model         = texturedModel.Model;

            GL.BindVertexArray(model.vaoID);
            GL.EnableVertexArrayAttrib(model.vaoID, 0);
            GL.EnableVertexArrayAttrib(model.vaoID, 1);

            Matrix4 transformationMatrix = Maths.CreateTransformationMatrix(ent.Position, ent.RotationX, ent.RotationY, ent.RotationZ, ent.Scale);

            shader.LoadTransformationMatrix(transformationMatrix);

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, texturedModel.ModelTexture.TextureID);
            GL.DrawElements(BeginMode.Triangles, model.vertexCount, DrawElementsType.UnsignedInt, 0);
            GL.DisableVertexArrayAttrib(model.vaoID, 0);
            GL.DisableVertexArrayAttrib(model.vaoID, 1);
            GL.BindVertexArray(0);
        }
예제 #8
0
 public DisplayManager(int width, int height) : base(width, height, GraphicsMode.Default, "OpenTK Guide", GameWindowFlags.Default, DisplayDevice.Default,
                                                     3, 0, GraphicsContextFlags.ForwardCompatible)
 {
     VSync   = VSyncMode.On;
     _shader = new StaticShader();
 }
예제 #9
0
 public Renderer(int width, int height, Camera camera, StaticShader shader)
 {
     this.camera = camera;
     this.shader = shader;
     this.shader.LoadProjectionMatrix(width, height);
 }