Device.BeginScene() Method (Microsoft.DirectX.Direct3D)

How Do I...?

  • Generate a Scene

Begins a scene.


Visual Basic Public Sub BeginScene()
C# public void BeginScene();
C++ public:
void BeginScene();
JScript public function BeginScene();


Every call to BeginScene should eventually be followed by a call to EndScene before the display is updated with Device.Present.

If the method fails, the device was unable to begin the scene, and there is no need to call EndScene. In fact, calls to EndScene fail if the previous call to BeginScene fails.



The method call is invalid. This occurs when BeginScene is called while already in a BeginScene ... EndScene pair. Never call BeginScene twice without first calling EndScene.

How Do I...?

Generate a Scene

This example shows how to begin scene generation and draw primitives.

The SetStreamSource method binds a vertex buffer to a device data stream to create an association between the vertex data and one of several data stream ports that feed the primitive processing functions. The parameters for this method are the number of the data stream, the name of the VertexBuffer object, and the stream vertex stride.

In the following C# code example, it is assumed that the device is the rendering Device, and vBuffer is a vertex buffer filled with CustomVertex.PositionNormal data.



device.SetStreamSource(0, vBuffer, 0);
device.VertexFormat = CustomVertex.PositionNormal.Format;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);