graphics.h
#pragma once
#include <Windows.h>
#include <d2d1.h>
#pragma comment(lib, "D2d1.lib")
class Graphics
{
private:
ID2D1Factory* factory; //D2D工厂
ID2D1HwndRenderTarget* rendertarget; //D2D渲染目标
ID2D1SolidColorBrush* brush; //D2D画刷
public:
Graphics();
~Graphics();
bool Init(HWND hwnd);
void BeginDraw() { rendertarget->BeginDraw(); }
void EndDraw() { rendertarget->EndDraw(); }
void ClearScreen(float r, float g, float b);
void DrawCircle(float x, float y, float raduis, float r, float g, float b, float a);
};
graphics.cpp
#include "Graphics.h"
Graphics::Graphics()
{
factory = NULL;
rendertarget = NULL;
brush = NULL;
}
Graphics::~Graphics()
{
if (factory)factory->Release();
if (rendertarget) rendertarget->Release();
if (brush)brush->Release();
}
bool Graphics::Init(HWND hwnd)
{
HRESULT res = D2D1CreateFac