2D in 3D

xiaoxiao2021-03-06  43

Learn notes, haven't seen it yet, temporarily store you if you want to express 2D in 3D, just use what I said

If you are pure 2D

You can see DDRAW information in D7, also support in D9.

If you have to use D3D

There is IDirect3dsurface9 in D9, you can check it to see the usage

Give a small example, very simple to change, and DDRAW is almost

#include

#include

LPDIRECT3D9 PD3D = NULL; // D3D9 Object Interface

LPDIRECT3DDEVICE9 PD3DDEVICE = NULL; // D3D9 device object interface

IDirect3dsurface9 * srcsurface = null; // Off-screen page

IDirect3dsurface9 * backbuffer = null; // Background page

/ ************************************************** *******************

* InitDirect3D

*********************************************************** ****************** /

Bool InitDirect3D (HWND HWND, INT W, INT H, BOOL FULLSCREEN)

{

// Create a D3D object

IF (NULL == (PD3D = Direct3Dcreate9 (D3D_SDK_Version)))))))))

{

Return False;

}

// Fill the D3DPresent_Parameters structure

D3DPresent_Parameters D3DPP;

ZeromeMory (& D3DPP, SIZEOF (D3DPP));

D3DPP.Windowed =! fullscreen; // window mode

D3dpp.swapeffect = D3DSWAPEFFECT_DISCARD; / / change page mode

D3DPP.BACKBUFFERCOUNT = 1; // Number of Background Page

D3dpp.backbufferHeight = h; // high background page

D3dpp.backbufferWidth = W; // Background page wide

D3DP.HDEVICEWINDOW = hWnd; // window handle

If (! fullscreen) / / Set the background format according to the window mode

D3dpp.backbufferformat = D3DFMT_UNKNOWN;

Else

D3DPP.BACKBUFFORMAT = D3DFMT_X8R8G8B8;

// Create a D3D device object

IF (Failed (PD3D-> CreateDevice (D3DADADAPTER_DEFAULT, / / ​​county card type, default is the main video

D3DDEVTYPE_REF, // Device Type HAL Hard Accelerated REF Microsoft Recommended SW Soft Acceleration

HWnd, // window handle

D3DCREATE_SOFTWARE_VERTEXPROCESSING,

& D3DPP, // D3DPRest_Parameters

& pd3ddevice)) // Device pointer

{

Return False;

}

// Create an off-screen page

IF (Pd3DDevice-> CreateOffscreenPlainsurface

W, // wide

h, // high

D3dpp.backbufferformat, // d3dfmt_x8r8g8b8, // page format

D3DPOOL_DEFAULT, / / ​​Page Storage Location SystemMem Memory Default Save or Memory

& srcsurface, // page pointer

NULL)))) // Reserved {

Return False;

}

/ / Load the picture to the remote screen

IF (Failed (d3dxloadsurfacefromfile (srcsurface, // destination page

Null, // Destination Page Pattern

Null, // Destination Page Area

"D: / program /dx/d3d9/pic/zl.bmp", / source file path

NULL, / / ​​Source file area

D3DX_DEFAULT, // File filter type

0, // colorKey

NULL))) // Picture Information

{

Return False;

}

Return True;

}

/ ************************************************** *******************

* Render

*********************************************************** ****************** /

Void renderd3d ()

{

IF (null == pd3ddevice)

Return;

// Qingping screen

PD3DDEVICE-> CLEAR (0, // Rectangle

NULL, // The first parameter is not 0 when the number of rectangles is 0.

D3DCLEAR_TARGET, / / ​​Clear Sign

D3DCOLOR_XRGB (0, 0, 0), // Color

1.0f, // zbuffer

0); // Stencil buffer.

// Get the background page

PD3DDEVICE-> getBackBuffer (0, //)

0, // buffer chain index

D3DBACKBUFFER_TYPE_MONO, / / ​​Uniquely valid value

& backbuffer; // Background page pointer

// Page copy

PD3DDEVICE-> StretChRect (srcsurface, // Source page

Null, // Source page area

BACKBUFFER, // destination page

Null, // Destination Page Area

D3DTEXF_NONE); // Filter type

// turn the page

PD3DDEVICE-> Present (null, / source area null is the entire background page

NULL, // destination area

NULL,

NULL); // buffer null is all buffer

}

/ ************************************************** *******************

* Cleanupd3d

*********************************************************** ****************** /

Void cleanupd3d ()

{

// Release the object

IF (srcsurface! = NULL)

Srcsurface-> Release;

IF (BackBuffer! = NULL)

Backbuffer-> Release;

IF (PD3DDEVICE! = NULL)

PD3DDEVICE-> Release ();

IF (PD3D! = NULL)

PD3D-> Release ();

}

转载请注明原文地址:https://www.9cbs.com/read-57786.html

New Post(0)