draw_begin()
Opens a scene for rendering on the screen by user-defined DirectX
functions. Calls the DirectX BeginScene function if the scene is not
already open.
Returns:
Pointer to the Direct3D device.
Remarks:
- Not necessary
for draw_ functions or
when rendering through user-defined render or material events.
- Closing the scene is automatically handled by the engine.
Speed:
fast
Example:
#include <acknex.h>
#include <default.c>
#include <d3d9.h>
// define a suited vertex struct
typedef struct VERTEX_FLAT {
float x,y,z;
float rhw;
D3DCOLOR color;
} VERTEX_FLAT;
#define D3DFVF_FLAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
// draw a red/blue/green triangle
function main()
{
wait(1); //wait until the D3D Device is opened
// define the three corner vertices
VERTEX_FLAT v[3];
v[0].x = 10.0; v[0].y = 10.0; v[0].color = 0xFFFF0000; // the red corner
v[1].x = 310.0; v[1].y = 10.0; v[1].color = 0xFF0000FF; // the blue corner
v[2].x = 10.0; v[2].y = 310.0; v[2].color = 0xFF00FF00; // the green corner
v[0].z = v[1].z = v[2].z = 0.0; // z buffer - paint over everything
v[0].rhw = v[1].rhw = v[2].rhw = 1.0; // no perspective
while(1)
{
// open the scene and get the active D3D device
LPDIRECT3DDEVICE9 pd3dDev;
pd3dDev = (LPDIRECT3DDEVICE9)draw_begin();
if (!pd3dDev) return;
// set some render and stage states
pd3dDev->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
pd3dDev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
pd3dDev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2);
// now draw the triangle
pd3dDev->SetFVF(D3DFVF_FLAT);
pd3dDev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,1,(LPVOID)v,sizeof(VERTEX_FLAT));
// no need to close the scene - this is handled by the engine
wait(1);
}
}
See Also:
draw_text, draw_point3d, draw_line, draw_quad► latest version online