/// <summary> /// 描画処理 /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { //以下、時間計測処理 TimeSpan stDiff = DateTime.Now - this.mTimeOld; this.mTimeOld = DateTime.Now; double doTimeDiff = stDiff.TotalMilliseconds; double doFPS = 1000.0 / doTimeDiff; //以下、モーション描画処理 int inFrameNoNow = 0; int inMaxFrameNum = ClsSystem.DEFAULT_FRAME_NUM; ClsDatMotion clMotion = ClsSystem.GetSelectMotion(); if (clMotion != null) { inFrameNoNow = ClsSystem.GetSelectFrameNo(); inMaxFrameNum = clMotion.GetMaxFrameNum(); clMotion.DrawPreview(this, inFrameNoNow, inMaxFrameNum); } //以下、キャンバスサイズ設定処理 this.mCanvasWidth = this.Width; this.mCanvasHeight = this.Height; int inWidth = this.Width; int inHeight = this.Height; //以下、一番引きのスクリーンでのグリッド表示処理を決める //(一番引きのスクリーンでは、グリッド間隔を最大にしても密度が濃くてラインで描く必要がないのと、ラインを大量に描画する必要があり重いため) bool isDammyGrid = false; if (this.mGridVisible) { if (this.mScale <= 0.125f) { isDammyGrid = true; } } //以下、OpenGL初期化処理 Wgl.wglMakeCurrent(this.hDC, this.hRC); //レンダリングコンテキストをカレントにする Gl.glLineWidth(1); //ラインの太さを1dotにする //以下、背景色設定処理 if (isDammyGrid) { Gl.glClearColor(this.mGridColor.R / 255.0f, this.mGridColor.G / 255.0f, this.mGridColor.B / 255.0f, 1.0f); } else { Gl.glClearColor(this.mBackColor.R / 255.0f, this.mBackColor.G / 255.0f, this.mBackColor.B / 255.0f, 1.0f); } //以下、バッファをクリアする処理 Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); //以下、ビューポートの設定処理 Gl.glViewport(0, 0, inWidth, inHeight); /* * if (this.Width > this.Height) * { * int inY = -(this.Width - this.Height) / 2; * Gl.glViewport(0, inY, this.Width, this.Width); * } * else * { * int inX = -(this.Height - this.Width) / 2; * Gl.glViewport(inX, 0, this.Height, this.Height); * } */ //以下、射影行列の設定処理 Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(-inWidth / 2, inWidth / 2, -inHeight / 2, inHeight / 2, 0.0, 4.0); //以下、カメラの位置を設定する処理 Glu.gluLookAt(0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //視点の設定 //以下、モデルビュー行列の設定 Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); //以下、グリッドライン描画処理 if (this.mGridVisible) { if (!isDammyGrid) { this.DrawGridLine(this.mGridColor, this.mGridSpan * this.mScale); } } //以下、中心ライン描画処理 if (this.mCrossBarVisible) { this.DrawCrossBarLine(this.mCrossColor); } //以下、モーション描画処理 if (clMotion != null) { clMotion.DrawPreview(this, inFrameNoNow, inMaxFrameNum); } //以下、FPSのライン表示 { Gl.glLoadIdentity(); //マトリクス設定 Gl.glLineWidth(5); float flX1 = -(inWidth / 2.0f) + 0; float flY = (inHeight / 2.0f) - 5; float flX2 = (float)(flX1 + (doFPS / 60.0f) * inWidth); Color stColor = Color.Red; if (doFPS > 30.0) { stColor = Color.LimeGreen; } else if (doFPS > 15.0) { stColor = Color.Yellow; } this.DrawLine(stColor, flX1, flY, flX2, flY); } //以下、FPS描画処理 if (this.mImageFont != null) { string clFPS = doFPS.ToString("F1"); this.DrawFont(0, 0, "FPS " + clFPS, inWidth, inHeight); } //ダブルバッファ Wgl.wglSwapBuffers(this.hDC); }