コード例 #1
0
ファイル: Window.cs プロジェクト: jr5000/TDD-Game-Dev
 public virtual void Render(object sender, FrameEventArgs e)
 {
     _glClear.WithClearColor(Color4.MidnightBlue, () =>
                             _glClear.WithCleared(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit, () =>
                                                  _renderer.Render(e)
                                                  )
                             );
     _gameWindow.SwapBuffers();
 }
コード例 #2
0
        /// <summary>
        /// Called when it is time to render the next frame. Add your rendering code here.
        /// </summary>
        /// <param name="sender">the subject of RenderFrame Event </param>
        /// <param name="e">Contains timing information.</param>
        private void OnRenderFrame(Object sender, FrameEventArgs e)
        {
            GL.Viewport(0, 0, mainWindow.Width, mainWindow.Height);
            Rotate(1.0f, 1.0f);

            GL.ClearColor(Color4.CornflowerBlue);
            GL.Enable(EnableCap.DepthTest);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.UseProgram(mProgramHandle);
            positionLoc = GL.GetAttribLocation(mProgramHandle, "a_position");
            texCoordLoc = GL.GetAttribLocation(mProgramHandle, "a_texCoord");

            textureLoc = GL.GetUniformLocation(mProgramHandle, "s_texture");
            GL.Uniform1(textureLoc, 0);

            unsafe
            {
                fixed(float *pvertices = vertices)
                {
                    // Prepare the vertex coordinate data
                    GL.VertexAttribPointer(positionLoc, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), new IntPtr(pvertices));
                    GL.EnableVertexAttribArray(positionLoc);
                }

                fixed(float *texCoord = textCoord)
                {
                    // Prepare the texture coordinate data
                    GL.VertexAttribPointer(texCoordLoc, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), new IntPtr(texCoord));
                    GL.EnableVertexAttribArray(texCoordLoc);
                }
            }

            mvpLoc = GL.GetUniformLocation(mProgramHandle, "u_mvpMatrix");

            // Apply the projection and view transformation
            GL.UniformMatrix4(mvpLoc, false, ref mvpMatrix);

            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            GL.Finish();

            // Disable vertex array
            GL.DisableVertexAttribArray(positionLoc);
            mainWindow.SwapBuffers();
        }