Lumiroot

Managed Direct3D Tutorial 03 본문

Programming/DirectX

Managed Direct3D Tutorial 03

루미루트 2007. 7. 20. 20:00

Rendering Basics


이제는 그림을 그려주는 방법에 대해서 알아보자.
다음과 같은 과정이 거치게 된다.

1. 백 버퍼를 지운다.
2. Direct3D로 그릴 준비를 한다.
3. 장면을 그린다.
4. Direct3D에 그리기가 끝났음을 알려준다.
5. 백 버퍼의 이미지를 디스플레이로 복사한다.

이것을 코드로 만들어 보면 다음과 같다.

protected void Render()
{
    // Clear the back buffer
    device.Clear(ClearFlags.Target, Color.Black, 1.0F, 0);
    // Ready Direct3D to begin drawing
    device.BeginScene();
    // Draw the scene - 3D Rendering calls go here
    // Indicate to Direct3D that we’re done drawing
    device.EndScene();
    // Copy the back buffer to the display
    device.Present();
}


지금까지 완성된 코드
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace ManagedDXTutorial01
{
    class Game : Form
    {
        private Device device;
        protected bool InitializeGraphics()
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;
            device = new Device(0, DeviceType.Hardware, this,
               CreateFlags.SoftwareVertexProcessing, presentParams);
            return true;
        }
        protected void Render()
        {
            // Clear the back buffer
            device.Clear(ClearFlags.Target, Color.Black, 1.0F, 0);
            // Ready Direct3D to begin drawing
            device.BeginScene();
            // Draw the scene - 3D Rendering calls go here
            // Indicate to Direct3D that we’re done drawing
            device.EndScene();
            // Copy the back buffer to the display
            device.Present();
        }

        static void Main()
        {
            Game app = new Game();
            app.InitializeGraphics();
            app.Show();
            while (app.Created)
            {
                app.Render();
                Application.DoEvent();
            }
            app.DisposeGraphics();
        }
    }
}


Comments