/// <summary> /// Allocate GL resources or GL states. /// </summary> /// <param name="sender"> /// The <see cref="object"/> that has rasied the event. /// </param> /// <param name="e"> /// The <see cref="GlControlEventArgs"/> that specifies the event arguments. /// </param> private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; // GL Debugging if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB) { Gl.DebugMessageCallback(GLDebugProc, IntPtr.Zero); Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, null, true); } _renderer = _rendererFactory.Create(Gl.CurrentVersion); _renderer.Create(); ContextCreated?.Invoke(sender, e); Gl.ClearColor(0.0f, 0.4f, 0.6f, 1.0f); // Uses multisampling, if available if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0) { Gl.Enable(EnableCap.Multisample); } }
private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; if (Gl.CurrentVersion.Api == KhronosVersion.ApiGles2) { RenderControl_ContextCreated_ES(sender, e); } else { // Here you can allocate resources or initialize state Gl.MatrixMode(MatrixMode.Projection); Gl.LoadIdentity(); Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0); Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadIdentity(); // Uses multisampling, if available if (glControl.MultisampleBits > 0) { Gl.Enable(EnableCap.Multisample); } } }
public bool InitializeComponent(Control parent, int width, int stride, int height) { viewWidth = width; viewStride = stride; viewHeight = height; try { yuv = new Mat(viewHeight + viewHeight / 2, viewWidth, MatType.CV_8UC1); bgra = new Mat(viewHeight, viewWidth, MatType.CV_8UC4); glControl = new GlControl { Animation = true, ColorBits = ((uint)(24u)), DepthBits = ((uint)(0u)), Dock = DockStyle.Fill, Location = new System.Drawing.Point(0, 0), MultisampleBits = ((uint)(0u)), Name = "glControl", StencilBits = ((uint)(0u)), TabIndex = 0, ContextSharingGroup = "" }; glControl.ContextCreated += new EventHandler <GlControlEventArgs>(glControl_ContextCreated); glControl.Render += new EventHandler <GlControlEventArgs>(glControl_Render); parent.Controls.Add(glControl); return(true); } catch { return(false); } }
/// <summary> /// Allocate GL resources or GL states. /// </summary> /// <param name="sender"> /// The <see cref="object"/> that has rasied the event. /// </param> /// <param name="e"> /// The <see cref="GlControlEventArgs"/> that specifies the event arguments. /// </param> private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; // Allocate resources and/or setup GL states switch (Gl.CurrentVersion.Api) { case KhronosVersion.ApiGl: if (Gl.CurrentVersion >= Gl.Version_320) { RenderControl_CreateGL320(); } else { RenderControl_CreateGL100(); } break; case KhronosVersion.ApiGles2: RenderControl_CreateGLES2(); break; } // Uses multisampling, if available if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0) { Gl.Enable(EnableCap.Multisample); } }
private void glControl_ContextCreated(object sender, OpenGL.GlControlEventArgs e) { GlControl glControl = (GlControl)sender; if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB) { Gl.DebugMessageCallback(_debugProc, IntPtr.Zero); Gl.DebugMessageControl(Gl.DebugSource.DontCare, Gl.DebugType.DontCare, Gl.DebugSeverity.DontCare, 0, null, true); } _displayManager.createDisplay(Gl.CurrentVersion); if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0) { Gl.Enable(EnableCap.Multisample); } bool result = Soil.NET.WrapSOIL.Initialize(); if (result == false) { MessageBox.Show("SOIL: Not initialized: " + Soil.NET.WrapSOIL.GetSoilLastError()); return; } _model = _loader.loadToVAO(_vertices, _textureCoords, _indices); _texture = new ModelTexture(_loader.loadTexture("image")); _textureModel = new TextureModel(_model, _texture); _shader = new StaticShader(); }
private void OnRender(object sender, OpenGL.GlControlEventArgs e) { GlControl gl_control = (GlControl)sender; if ((LastMotion == null) || (LastMotion.Finished == true)) { // モーションをランダムに再生する // 名前なしのモーショングループから0~9番のモーションを乱数で選ぶ var motion_group = Asset.MotionGroups[""]; int number = new Random().Next() % motion_group.Length; var motion = (CubismMotion)motion_group[number]; LastMotion = Asset.StartMotion(CubismAsset.MotionType.Base, motion, false); } // モデルを更新する var elapsed = Timer.Elapsed; Timer.Restart(); Asset.Update(elapsed.TotalSeconds); // モデルを描画する Gl.ClearColor(0.0f, 0.5f, 0.5f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit); Gl.Viewport(0, 0, gl_control.Width, gl_control.Height); Matrix mvp_matrix = DenseMatrix.CreateIdentity(4); mvp_matrix[0, 0] = 2.0f; mvp_matrix[1, 1] = 2.0f * gl_control.Width / gl_control.Height; RenderingManager.Draw(mvp_matrix); }
public OpenGLScene(MeshLoader meshLoader, MeshViewSettingsViewModel settingsViewModel) { _meshLoader = meshLoader; _settingsViewModel = settingsViewModel; var glControl = new GlControl { Animation = true, DepthBits = 24, MultisampleBits = 32, }; glControl.ContextCreated += GlControlOnContextCreated; glControl.Render += GlControlOnRender; var grid = new Grid { Background = Brushes.Aqua }; var windowsFormsHost = new WindowsFormsHost { Child = glControl }; MouseInput = new WinFormsMouseInput(glControl); grid.Children.Add(windowsFormsHost); Visual = grid; CameraLight = new OpenGLLight(); _openGLCamera = new OpenGLRendererCamera(-Vector3.UnitZ, Vector3.UnitZ, Vector3.UnitY); glControl.CreateControl(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlControl_Load(object sender, EventArgs e) { if (DesignMode) { return; } //HACK: this method is called twice... Strange... if (SpriteBatch != null) { MessageBox.Show("[MonsterControl] : Double call to GlControlLoad(), Oops !"); } GlControl.MakeCurrent(); Display.ViewPort = new Rectangle(new Point(), GlControl.Size); Display.Init(); Display.ClearBuffers(); // Preload background texture resource CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png")); CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat; CheckerBoard.VerticalWrap = TextureWrapFilter.Repeat; SpriteBatch = new SpriteBatch(); Draw(); }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.ClearColor(1.0f, 0.0f, 0.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.ProjectionMatrix = Matrix4x4f.Perspective(45.0f, senderAspectRatio, 0.1f, 100.0f); // _CubeScene.CurrentView.LocalModelView = Matrix4x4f.Translated(0.0f, 0.0f, 10.0f); //_CubeScene.CurrentView.LocalModelView = // Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f) * // Matrix4x4f.RotatedY(_ViewAzimuth) * // Matrix4x4f.RotatedX(_ViewElevation) * // Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever); //_CubeScene.CurrentView.LocalModelView = // Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever) * // Matrix4x4f.RotatedX(_ViewElevation) * // Matrix4x4f.RotatedY(_ViewAzimuth) * // Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.UpdateViewMatrix(); _CubeScene.Draw(_Context); }
private void RegenerateGlControl() { this.SuspendLayout(); this.RenderControl.Animation = false; this.Controls.Remove(this.RenderControl); this.RenderControl = BuildGLControl(); this.Controls.Add(this.RenderControl); this.ResumeLayout(); }
private void OnCreated_GlControl(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; this.displayManager.CreateDisplay(glControl); bool result = WrapSOIL.Initialize(); if (result == false) { MessageBox.Show("SOIL: Failed initialize : " + WrapSOIL.GetSoilLastError()); return; } this.loader = new Loader(); //Camera this.camera = new Camera(new Vertex3f(0, 10, 0), 20f); //Light - Sun this.lgihtList = new List <Light>(); this.sun = new DirectionalLight(new Vertex3f(-0.5f, -1.5f, 0.5f), new Vertex3f(150, 250, -150), new Vertex3f(0.4f, 0.4f, 0.4f), new Vertex3f(1, 0, 0)); this.lgihtList.Add(sun); //Renderer this.renderer = new MasterRenderer(this.camera, this.loader, this.sun, glControl.ClientSize.Width, glControl.ClientSize.Height); this.guiRenderer = new GUIRenderer(this.loader); this.inputManager.OnEventMouseWheel += this.camera.OnEventWheel; //Water this.waterTileList = new List <WaterTile>(); this.waterTileList.Add(new WaterTile(75, -75, WATER_HEIGHT)); //Water this.waterFrameBuffers = new WaterFrameBuffers(); this.waterShader = new WaterShader(); this.waterRenderer = new WaterRenderer(loader, waterShader, this.renderer.ProjectionMatrix, this.waterFrameBuffers); //Load Resources this.entities = new List <Entity>(); this.terrain = LoadTerrain(this.loader); LoadEntities(this.terrain, this.entities, this.loader); LoadPlayer(this.loader, this.entities); //Light - Point this.lgihtList.Add(new Light(GetHeightPosition(this.terrain, 185, 12.7f, -293), new Vertex3f(2, 0, 0), new Vertex3f(1, 0.01f, 0.002f))); this.lgihtList.Add(new Light(GetHeightPosition(this.terrain, 370, 12.7f, -300), new Vertex3f(0, 2, 2), new Vertex3f(1, 0.01f, 0.002f))); this.lgihtList.Add(new Light(GetHeightPosition(this.terrain, 293, 12.7f, -305), new Vertex3f(2, 2, 0), new Vertex3f(1, 0.01f, 0.002f))); //LoadGUI(this.loader); //LoadGUI_Texture(this.loader, this.waterFrameBuffers.RefractionTexture); LoadGUI_Texture(this.loader, renderer.DepthMap); //MousePicker this.mousePicker = new MousePicker(this.camera, this.renderer.ProjectionMatrix, this.terrain); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Font2dForm_Load(object sender, EventArgs e) { GlControl.MakeCurrent(); Display.Init(); Batch = new SpriteBatch(); CheckerBoard = new Texture2D(ResourceManager.GetInternalResource("ArcEngine.Resources.checkerboard.png")); CheckerBoard.VerticalWrap = TextureWrapFilter.Repeat; CheckerBoard.HorizontalWrap = TextureWrapFilter.Repeat; }
public void CreateDisplay(GlControl glControl) { _debugProc = GLDebugMessageCallbackProc; if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB) { Gl.DebugMessageCallback(_debugProc, IntPtr.Zero); Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, null, true); } if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0) { Gl.Enable(EnableCap.Multisample); } this.lastFrameTime = GetCurrentTime(); }
private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; // Here you can allocate resources or initialize state Gl.MatrixMode(MatrixMode.Projection); Gl.LoadIdentity(); Gl.Ortho(OrthoLeft, OrthoRight, OrthoBottom, OrthoTop, -0.1, 10.0); Gl.Enable(EnableCap.Texture2d); Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.DepthTest); //Set up Z Depth tests for drawing pixels Gl.DepthFunc(DepthFunction.Lequal); //Only draw something new if its z value is closer to the 'camera' Gl.DepthMask(true); Gl.ClearDepth(10f); Gl.ClearColor(36 / 255f, 71 / 255f, 143 / 255f, 1f); Gl.Enable(EnableCap.AlphaTest); //Set up Alpha tests for drawing pixels Gl.AlphaFunc(AlphaFunction.Greater, .05f); //Don't draw transparent pixels on polygons Gl.Enable(EnableCap.ScissorTest); Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.EnableClientState(EnableCap.VertexArray); Gl.EnableClientState(EnableCap.TextureCoordArray); contextCreated = true; Console.Console.ConsoleSetup(); WorldData.WorldStartup(); Screen.ScreenStartup(); MaximizeBox = false; if (Save.SaveData.GameSettings.fullScreen) { FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; } if (Save.SaveData.GameSettings.VSync) { Wgl.SwapIntervalEXT(-1); //Swap Interval (V-Sync Enabled at 1 or -1) } else { Wgl.SwapIntervalEXT(0); } ResizeWindow(Save.SaveData.GameSettings.windowx, Save.SaveData.GameSettings.windowy); ResizeE(sender, e); LogicUtils.Logic.LogicStart(); }
public Form1() { InitializeComponent(); var g = new GlControl(); this.Controls.Add(g); g.Render += GOnRender; g.ContextCreated += GOnContextCreated; g.ContextDestroying += GOnContextDestroying; g.ContextUpdate += GOnContextUpdate; g.Dock = DockStyle.Fill; g.AnimationTimer = true; g.AnimationTime = 1000; g.DoubleBuffer = true; g.Animation = true; }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { float deltaTime = (float)_Crono.Elapsed.TotalSeconds * _TimeSpeed; _Crono.Restart(); // Update force _ComputeEnergy.SetStorageBuffer(_Context, "MassBuffer", _MassBuffer); _ComputeEnergy.SetUniform(_Context, "glo_MassCount", (int)_MassBuffer.ItemsCount); _ComputeEnergy.SetUniform(_Context, "glo_Gravity", _Gravity); _ComputeEnergy.SetUniform(_Context, "glo_MinDistanceForGravity", 0.1f); _ComputeEnergy.SetUniform(_Context, "glo_DeltaTime", deltaTime); _ComputeEnergy.Compute(_Context, 1024); _ComputeEnergy.MemoryBarrier(MemoryBarrierMask.ShaderStorageBarrierBit); // Update positions _ComputePosition.SetStorageBuffer(_Context, "MassBuffer", _MassBuffer); _ComputePosition.SetUniform(_Context, "glo_MassCount", (int)_MassBuffer.ItemsCount); _ComputePosition.SetUniform(_Context, "glo_Gravity", _Gravity); _ComputePosition.SetUniform(_Context, "glo_MinDistanceForGravity", 0.1f); _ComputePosition.SetUniform(_Context, "glo_DeltaTime", deltaTime); _ComputePosition.Compute(_Context, 1024); _ComputePosition.MemoryBarrier(MemoryBarrierMask.VertexAttribArrayBarrierBit); // Draw scene GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.ClearColor(1.0f, 0.0f, 0.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Matrix4x4f mvp = Matrix4x4f.Perspective(60.0f, senderAspectRatio, 0.1f, 16535.0f) * Matrix4x4f.Translated(-128.0f, -128.0f, -256.0f); _DrawMass.SetUniform(_Context, "glo_ModelViewProjection", mvp); _MassArrays.Draw(_Context, _DrawMass); }
public void InitializeComponent() { this.SuspendLayout(); this.glControl = new GlControl(); this.displayManager = new DisplayManager(); this.inputManager = new InputManager(); //glControl this.glControl.Animation = true; this.glControl.AnimationTimer = false; this.glControl.BackColor = Color.FromArgb(64, 64, 64); this.glControl.ColorBits = 24u; //Gl.COLOR_BUFFER_BIT; this.glControl.DepthBits = 24u; //Gl.DEPTH_BUFFER_BIT; this.glControl.Dock = DockStyle.Fill; this.glControl.Location = new Point(DisplayManager.WIDTH, DisplayManager.HEIGHT); this.glControl.MultisampleBits = 0u; this.glControl.Name = "glControl"; this.glControl.Size = new Size(DisplayManager.WIDTH, DisplayManager.HEIGHT); this.glControl.StencilBits = 0u;//Gl.MULTISAMPLE_BIT; this.glControl.TabIndex = 0; this.glControl.ContextCreated += OnCreated_GlControl; this.glControl.ContextDestroying += OnDestroying_GlControl; this.glControl.Render += OnRender_GlControl; this.glControl.ContextUpdate += OnUpdate_GlControl; //input event this.glControl.MouseMove += this.inputManager.OnMouseMove; this.glControl.MouseWheel += this.inputManager.OnMoueWheel; this.glControl.KeyDown += this.inputManager.OnKeyDown; this.glControl.KeyUp += this.inputManager.OnKeyUp; this.glControl.MouseDown += this.inputManager.OnMouseDown; this.glControl.MouseUp += this.inputManager.OnMouseUp; //winform this.ClientSize = new Size(DisplayManager.WIDTH, DisplayManager.HEIGHT); this.Controls.Add(this.glControl); this.Name = "CogiEngine"; this.ResumeLayout(false); this.KeyPreview = true; }
public void Startup() { Form = new Form(); Form.Activated += (sender, e) => Activated?.Invoke(sender, e); Form.Deactivate += (sender, e) => Deactivate?.Invoke(sender, e); Form.FormClosed += (sender, e) => Closed?.Invoke(sender, e); RenderControl = new GlControl(); Form.SuspendLayout(); // // RenderControl // RenderControl.Animation = true; RenderControl.AnimationTimer = false; RenderControl.BackColor = System.Drawing.Color.DimGray; RenderControl.ColorBits = 24u; RenderControl.DepthBits = 0u; RenderControl.Dock = DockStyle.Fill; RenderControl.Location = new System.Drawing.Point(0, 0); RenderControl.MultisampleBits = 0u; RenderControl.Name = "RenderControl"; RenderControl.Size = new System.Drawing.Size(731, 428); RenderControl.StencilBits = 0u; RenderControl.TabIndex = 0; RenderControl.ContextCreated += RenderControl_ContextCreated; RenderControl.ContextDestroying += (sender, e) => ContextDestroying?.Invoke(sender, e); RenderControl.Render += (sender, e) => Render?.Invoke(sender, e); RenderControl.ContextUpdate += (sender, e) => Update?.Invoke(sender, e); RenderControl.SizeChanged += RenderControl_SizeChanged; Form.Controls.Add(RenderControl); Form.ResumeLayout(false); Form.Show(); WorldMatrix = Matrix.OrthoRH(-1000.0f, 1000.0f, -1000.0f, 1000.0f, -1000.0f, 1000.0f); //WorldMatrix = Matrix.Translation(0, 0, 0); }
/// <summary> /// Allocate GL resources or GL states. /// </summary> /// <param name="sender"> /// The <see cref="object"/> that has rasied the event. /// </param> /// <param name="e"> /// The <see cref="GlControlEventArgs"/> that specifies the event arguments. /// </param> private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; _debugProc = GLDebugProc; // GL Debugging if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB) { Gl.DebugMessageCallback(_debugProc, IntPtr.Zero); Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, null, true); } // Allocate resources and/or setup GL states switch (Gl.CurrentVersion.Api) { case KhronosVersion.ApiGl: if (Gl.CurrentVersion >= Gl.Version_320) { RenderControl_CreateGL320(); } else { RenderControl_CreateGL100(); } break; case KhronosVersion.ApiGles2: RenderControl_CreateGLES2(); break; } // Uses multisampling, if available if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0) { Gl.Enable(EnableCap.Multisample); } }
/// <summary> /// OnPaint /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlControl_Paint(object sender, PaintEventArgs e) { DrawTimer.Stop(); GlControl.MakeCurrent(); Display.ClearBuffers(); Batch.Begin(); // Background texture Rectangle dst = new Rectangle(Point.Empty, GlControl.Size); Batch.Draw(CheckerBoard, dst, dst, Color.White);; Batch.DrawString(CurrentFont, Point.Empty, Color.White, PreviewTextBox.Text); Batch.End(); DrawTimer.Start(); GlControl.SwapBuffers(); }
/// <summary> /// Render the monster visual /// </summary> void Draw() { try { GlControl.MakeCurrent(); Display.ClearBuffers(); if (SpriteBatch != null) { SpriteBatch.Begin(); // Background texture Rectangle dst = new Rectangle(Point.Empty, GlControl.Size); SpriteBatch.Draw(CheckerBoard, dst, dst, Color.White); if (Monster != null && TileSet != null) { Tile tile = TileSet.GetTile(Monster.Tile); if (tile != null) { Point pos = new Point((GlControl.Width - tile.Size.Width) / 2, (GlControl.Height - tile.Size.Height) / 2); pos.Offset(tile.Pivot); SpriteBatch.DrawTile(TileSet, Monster.Tile, pos); } } SpriteBatch.End(); } GlControl.SwapBuffers(); } catch (Exception e) { } }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; KhronosApi.LogEnabled = false; KhronosApi.LogComment("--------------------------------------------------"); KhronosApi.LogComment("*** Draw"); // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.1f, 100.0f); _CubeScene.CurrentView.LocalModel.SetIdentity(); _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation); _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever); _CubeScene.UpdateViewMatrix(); _CubeScene.Draw(_Context); KhronosApi.LogEnabled = false; return; // Overlay ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height); ModelMatrix overlayModel = new ModelMatrix(); overlayModel.Translate(0.375f, 0.375f); Gl.Clear(ClearBufferMask.DepthBufferBit); ColorRGBAF fpsColor = ColorRGBAF.ColorGreen; int fps = (int)Math.Floor(1000.0 / senderControl.FrameSwapTime.TotalMilliseconds); if (fps >= 59) { fpsColor = ColorRGBAF.ColorGreen; } else if (fps >= 29) { fpsColor = ColorRGBAF.ColorBlue; } else if (fps >= 24) { fpsColor = ColorRGBAF.ColorYellow; } else { fpsColor = ColorRGBAF.ColorRed; } fontPatch.DrawString( _Context, overlayProjection * overlayModel, fpsColor, String.Format("FPS: {0}", fps) ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f); fontTitle.DrawString( _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f); fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); // Release resources _Context.DisposeResources(); }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.LocalModel.SetIdentity(); _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation); _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever); _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.5f, 10000.0f); _CubeScene.Draw(_Context); // Overlay ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height); ModelMatrix overlayModel = new ModelMatrix(); overlayModel.Translate(0.375f, 0.375f); Gl.Clear(ClearBufferMask.DepthBufferBit); ColorRGBAF fpsColor = ColorRGBAF.ColorGreen; int fps = senderControl.Fps; if (fps >= 59) { fpsColor = ColorRGBAF.ColorGreen; } else if (fps >= 29) { fpsColor = ColorRGBAF.ColorBlue; } else if (fps >= 24) { fpsColor = ColorRGBAF.ColorYellow; } else { fpsColor = ColorRGBAF.ColorRed; } fontPatch.DrawString( _Context, overlayProjection * overlayModel, fpsColor, String.Format("FPS: {0}", senderControl.Fps) ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f); fontTitle.DrawString( _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f); fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); }
/// <summary> /// Control resize /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GlControl_Resize(object sender, EventArgs e) { GlControl.MakeCurrent(); Display.ViewPort = new Rectangle(new Point(), GlControl.Size); }
private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; ContextCreated(glControl.MultisampleBits); }
private void InitializeComponent() { this.SuspendLayout(); // // RenderControl // this.RenderControl = BuildGLControl(); this.Controls.Add(this.RenderControl); if (this.configuration.WorkflowMode == UrielWorkflowMode.EditorMode) { // Add keypress listeners to the RenderControl for Keystate Monitoring RenderControl.KeyDown += listener.KeyDown; RenderControl.KeyUp += listener.KeyUp; // StatusStrip this.StatusStrip = new StatusStrip(); StatusStrip.BackColor = System.Drawing.Color.LightGray; StatusStrip.Dock = System.Windows.Forms.DockStyle.Bottom; StatusStrip.Name = "StatusStrip"; StatusStrip.SizingGrip = false; FpsLabel = new System.Windows.Forms.ToolStripStatusLabel(); U_timeLabel = new System.Windows.Forms.ToolStripStatusLabel(); KeyState = new System.Windows.Forms.ToolStripStatusLabel(); StatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { FpsLabel, new ToolStripSeparator(), U_timeLabel, new ToolStripSeparator(), KeyState }); FpsLabel.Name = "fpsLabel"; FpsLabel.Size = new System.Drawing.Size(StatusStripLabelWidth, StatusStripLabelHeight); FpsLabel.Text = "---"; U_timeLabel.Name = "u_timeLabel"; U_timeLabel.Size = new System.Drawing.Size(StatusStripLabelWidth, StatusStripLabelHeight); U_timeLabel.Text = "---"; KeyState.Name = "KeyState"; KeyState.Size = new System.Drawing.Size(StatusStripLabelWidth, StatusStripLabelHeight); KeyState.Text = "---"; this.Controls.Add(this.StatusStrip); // LeftPanel LeftPanel = new Panel(); LeftPanel.Dock = DockStyle.Left; LeftPanel.Width = LEFT_PANEL_WIDTH; ShaderSelector = new ListBox(); LeftPanel.Controls.Add(ShaderSelector); ShaderSelector.Width = LEFT_PANEL_WIDTH; ShaderSelector.Height = LEFT_SUBPANEL_HEIGHT; ShaderSelector.DataSource = this.ShaderBlobs; ShaderSelector.DisplayMember = "DisplayName"; ErrorBox = new TextBox(); ErrorBox.Multiline = true; ErrorBox.ReadOnly = true; ErrorBox.Dock = DockStyle.Bottom; ErrorBox.Width = LEFT_PANEL_WIDTH; ErrorBox.Height = LEFT_SUBPANEL_HEIGHT; LeftPanel.Controls.Add(ErrorBox); this.Controls.Add(this.LeftPanel); } this.FormBorderStyle = FormBorderStyle.FixedDialog; // Set the MaximizeBox to false to remove the maximize box. this.MaximizeBox = true; this.Resize += new EventHandler(UrielForm_Resize); // Set the MinimizeBox to false to remove the minimize box. this.MinimizeBox = true; // Set the start position of the form to the center of the screen. this.StartPosition = FormStartPosition.CenterScreen; // // The Uriel Form // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = AutoScaleMode.None; if (this.configuration.WorkflowMode == UrielWorkflowMode.EditorMode) { this.ClientSize = new System.Drawing.Size(this.configuration.ViewPortLength + LEFT_PANEL_WIDTH, this.configuration.ViewPortHeight); } else { this.ClientSize = new System.Drawing.Size(this.configuration.ViewPortLength, this.configuration.ViewPortHeight); } this.Name = "Uriel"; this.Text = String.Format("Uriel - {0}", this.configuration.WorkflowMode); this.ResumeLayout(false); // ? }
private void DrawTimer_Tick(object sender, EventArgs e) { GlControl.Invalidate(); }
private void RenderControl_ContextCreated(object sender, GlControlEventArgs e) { GlControl glControl = (GlControl)sender; RenderControl_ContextCreated_ES(sender, e); }