public override void SetModelAndView(GLModel model, GLView view) { base.SetModelAndView(model, view); OnSetContext(view.GLContext); }
public ModelPackDrawable(ModelPack model) { ModelPack = model; Model = new GLModel(model, (material, textureName) => new GLTexture(model.Textures[textureName])); }
public ModelPackDrawable(ModelPack model, MaterialTextureCreator textureCreator) { Model = new GLModel(model, textureCreator); }
static void Main(string[] args) { var Options = WindowOptions.Default; Options.Size = new Silk.NET.Maths.Vector2D <int>(800, 600); Options.Title = "LearnOpenGL with Silk.NET"; var window = Window.Create(Options); window.Render += (obj) => { GL.GetApi(window).Enable(EnableCap.DepthTest); GL.GetApi(window).ClearColor(Color.Black); GL.GetApi(window).Clear((uint)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); model.Draw(cam.GetProjectionMatrix(), cam.GetViewMatrix(), Matrix4x4.Identity, new string[] { "proj", "view", "model" }); }; window.Load += () => { IInputContext input = window.CreateInput(); primaryKeyboard = input.Keyboards.FirstOrDefault(); for (int i = 0; i < input.Mice.Count; i++) { input.Mice[i].Cursor.CursorMode = CursorMode.Raw; input.Mice[i].MouseMove += (mouse, position) => { const float lookSensitivity = 0.1f; if (LastMousePosition == default) { LastMousePosition = position; } else { var xOffset = (position.X - LastMousePosition.X) * lookSensitivity; var yOffset = (position.Y - LastMousePosition.Y) * lookSensitivity; LastMousePosition = position; cam.ModifyDirection(xOffset, yOffset); } }; } model = new GLModel(GL.GetApi(window), "gun.obj", "Shader.vert", "Shader.frag", false, new[] { Assimp.TextureType.Diffuse }); cam = new Camera(new Vector3(0, 0, -10), new Vector3(0, 0, 1), new Vector3(0, 1, 0), 800 / 600); }; window.Closing += () => { model.Dispose(); }; window.Update += (deltaTime) => { var moveSpeed = 2.5f * (float)deltaTime; if (primaryKeyboard.IsKeyPressed(Key.W)) { //Move forwards cam.Position += moveSpeed * cam.Front; } if (primaryKeyboard.IsKeyPressed(Key.S)) { //Move backwards cam.Position -= moveSpeed * cam.Front; } if (primaryKeyboard.IsKeyPressed(Key.A)) { //Move left cam.Position -= Vector3.Normalize(Vector3.Cross(cam.Front, cam.Up)) * moveSpeed; } if (primaryKeyboard.IsKeyPressed(Key.D)) { //Move right cam.Position += Vector3.Normalize(Vector3.Cross(cam.Front, cam.Up)) * moveSpeed; } }; window.Run(); }