-
Notifications
You must be signed in to change notification settings - Fork 58
/
Effect.h
36 lines (29 loc) · 1017 Bytes
/
Effect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include "main.h"
// Base class for effects
class Effect {
protected:
IDirect3DDevice9* device;
IDirect3DVertexDeclaration9 *vertexDeclaration;
static const D3DVERTEXELEMENT9 vertexElements[3];
public:
Effect(IDirect3DDevice9* device) : device(device) {
device->CreateVertexDeclaration(vertexElements , &vertexDeclaration);
}
virtual ~Effect() {
SAFERELEASE(vertexDeclaration);
}
void quad(int width, int height) {
// Draw aligned fullscreen quad
D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / float(width), 1.0f / float(height));
float quad[4][5] = {
{ -1.0f - pixelSize.x, 1.0f + pixelSize.y, 0.5f, 0.0f, 0.0f },
{ 1.0f - pixelSize.x, 1.0f + pixelSize.y, 0.5f, 1.0f, 0.0f },
{ -1.0f - pixelSize.x, -1.0f + pixelSize.y, 0.5f, 0.0f, 1.0f },
{ 1.0f - pixelSize.x, -1.0f + pixelSize.y, 0.5f, 1.0f, 1.0f }
};
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(quad[0]));
}
};