private void game_RenderFrame(object sender, FrameEventArgs e) { demo.UpdateBuffer(0, 0, 0, bufferWidth, bufferHeight); demo.Draw(gameWindow.Width, gameWindow.Height); demo.SaveBuffer(saveDirectory + fileNumber.ToString("00000") + ".png"); gameWindow.SwapBuffers(); ++fileNumber; demo.TimeSource.Position += 1.0f / frameRate; //step 1/25 of a second }
private void game_RenderFrame(object sender, FrameEventArgs e) { demo.UpdateBuffer(0, 0, 0, bufferWidth, bufferHeight); demo.Draw(gameWindow.Width, gameWindow.Height); gameWindow.SwapBuffers(); }
private void GlControl_Paint(object sender, PaintEventArgs e) { //todo: paint in other thread? //if (1 == painting) return; //System.Threading.Interlocked.Exchange(ref painting, 1); //normalized mouse pos float mouseX = this.mousePos.X / (float)glControl.Width; float mouseY = (glControl.Height - this.mousePos.Y) / (float)glControl.Height; float factor = 1.0f; try { factor = float.Parse(menuSizeSetting.Text.Substring(1), CultureInfo.InvariantCulture); } catch (Exception) { }; int width = glControl.Width; int height = glControl.Height; if ('x' == menuSizeSetting.Text[0]) { width = (int)Math.Round(glControl.Width * factor); height = (int)Math.Round(glControl.Height * factor); } else { width = (int)factor; height = (int)factor; } //todo: update not in main thread -> make async; //glControl.Context.MakeCurrent(null); //await Task.Run(() => //{ // glControl.MakeCurrent(); camera.Update(mouseX * width, mouseY * height, 1 == mouseButton); try { if (!demo.UpdateBuffer((int)Math.Round(mouseX * width), (int)Math.Round(mouseY * height), mouseButton, width, height)) { textBoxLastMessage.Text = lastMessage; textBoxLastMessage.Visible = true; } else { textBoxLastMessage.Visible = false; } } catch { /* We do not care about errors at this level */ } // glControl.Context.MakeCurrent(null); //}); //glControl.MakeCurrent(); demo.Draw(glControl.Width, glControl.Height); glControl.SwapBuffers(); menuFps.Text = menuFps.Checked ? string.Format("{0:0.00}FPS ", 1 / demo.UpdateTime) : string.Format("{0:0.0}MSec ", demo.UpdateTime * 1e3f); //System.Threading.Interlocked.Exchange(ref painting, 0); if (camera.IsActive) { glControl.Invalidate(); } }