下面我们封装一个类,使用d3d实现yuv,rgb最简单的渲染功能。只需传窗口句柄,数据大小即可完成初始化,然后就可以按照自己的频率往里送数据。
//JYD3DRender.h
#include <stdio.h>
#include <tchar.h>
#include <d3d9.h>
class JYD3DRender{
public:
JYD3DRender();
~JYD3DRender();
public:
int Init(HWND hwnd, unsigned int nWidth, unsigned int nHeight, bool isYuv);
void Cleanup();
bool Render(char *buffer);
private:
bool m_bIsYuv;
int m_nWidth;
int m_nHeight;
RECT m_rtViewport;
CRITICAL_SECTION m_critial;
IDirect3D9 *m_pDirect3D9;
IDirect3DDevice9 *m_pDirect3DDevice;
IDirect3DSurface9 *m_pDirect3DSurfaceRender;
};
//JYD3DRender.cpp
#include "JYD3DRender.h"
JYD3DRender::JYD3DRender()
{
m_pDirect3D9 = NULL;
m_pDirect3DDevice = NULL;
m_pDirect3DSurfaceRender = NULL;
}
JYD3DRender::~JYD3DRender()
{
}
int JYD3DRender::Init(HWND hwnd, unsigned int nWidth,