Справочник Пользователя для Conitec 3d gamestudio-source development

Скачать
Страница из 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       6
for (int j=0; j<a5fb->height; j++) {
byte *buffer = a5fb->bytes + j*a5fb->pitch;
for (int i=0; i<a5fb->width*a5fb->bpp; i++)
*buffer++ = 255;
}
// unlock it so that A5 can use it again
(*a5fb->Unlock)();
return 0;
}
Using Direct3D functions
The following example shows how easy it is to use Direct3D functions for creating some effects
on the screen. As all initialization is done by the engine, it is sufficient just to call the draw
functions. All Direct3D functions are accessed through a
IDirect3DDevice7
pointer that is
available through the DLL. For details refer to the DirectX documentation that is available,
along with the DirectX 7 SDK, from the Microsoft site. 
The example paints a multicolored triangle onto the screen. You'll see the triangle briefly
flashing in the upper left corner when you call this function once. If you call it in a
wait(1)
-
loop, the triangle will be permanently on the screen. This code only works in 16- or 32-bit mode
when Direct3D is activated.
#include <d3d.h> // from the DIRECTX7 sdk
DLLFUNC fixed PaintD3DTriangle (long unused)
{
// get the active D3D device
FRAME_INTERFACE *a5fb = a5->fb;
IDirect3DDevice7 *pd3ddev = (IDirect3DDevice7 *) a5fb->pd3ddev;
if (!pd3ddev) return 0; // no D3D device in 8 bit mode
// define three corner vertices
D3DTLVERTEX v[3];
v[0].sx = 10.0; v[0].sy = 10.0; v[0].color = 0xFFFF0000;  // the red corner
v[1].sx = 310.0; v[1].sy = 10.0; v[1].color = 0xFF0000FF; // the blue corner
v[2].sx = 10.0; v[2].sy = 310.0; v[2].color = 0xFF00FF00; // the green corner
v[0].sz = v[1].sz = v[2].sz = 0.0;
// z buffer - paint over everything
v[0].rhw = v[1].rhw = v[2].rhw = 1.0; // no perspective
// begin a scene - needed before any D3D draw operations
pd3ddev->BeginScene();
// set some render and stage states (you have to set some more for more complicated operations)
pd3ddev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,FALSE);
pd3ddev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
pd3ddev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2);
// now draw the triangle
pd3ddev->DrawPrimitive(D3DPT_TRIANGLEFAN,D3DFVF_TLVERTEX,(LPVOID)v,3,0);
// Normally we had to store the old render and texture states before, and
// set them back here... but the simple states above do no harm
// do not forget to do a clean close of the scene
pd3ddev->EndScene();
return 0;
}