25 #include "common/array.h" 26 #include "common/hashmap.h" 27 #include "common/rect.h" 28 #include "graphics/surface.h" 29 #include "graphics/opengl/shader.h" 30 #include "math/vector2d.h" 31 #include "math/matrix4.h" 46 Color(
float red = 1.0f,
float green = 1.0f,
float blue = 1.0f,
float alpha = 1.0f) {
53 static Color withAlpha(
const Color &c,
float alpha = 1.0f) {
55 result.rgba.a = alpha;
59 static Color rgb(
int c) {
60 return create((uint8)((c >> 16) & 0xFF), (uint8)((c >> 8) & 0xFF), (uint8)(c & 0xFF), 0xFF);
63 static Color fromRgba(
int c) {
64 return create((uint8)((c >> 16) & 0xFF), (uint8)((c >> 8) & 0xFF), (uint8)(c & 0xFF), (uint8)((c >> 24) & 0xFF));
67 static Color create(uint8 red, uint8 green, uint8 blue, uint8 alpha = 0xFF) {
68 return Color(red / 255.f, green / 255.f, blue / 255.f, alpha / 255.f);
76 return Color(rgba.r - c.rgba.r, rgba.g - c.rgba.g, rgba.b - c.rgba.b, rgba.a - c.rgba.a);
80 return Color(rgba.r + c.rgba.r, rgba.g + c.rgba.g, rgba.b + c.rgba.b, rgba.a + c.rgba.a);
83 Color operator*(
float f) {
84 return Color(rgba.r * f, rgba.g * f, rgba.b * f, rgba.a * f);
95 Math::Vector2d texCoords;
98 Vertex(
const Math::Vector2d &p,
const Color &c =
Color(),
const Math::Vector2d &t = Math::Vector2d());
107 static void bind(
const Texture *texture);
112 int width = 0, height = 0;
135 void init(
const char *name,
const char *vertex,
const char *fragment);
137 int getUniformLocation(
const char *name)
const;
139 void setUniform(
const char *name,
int value);
140 void setUniform(
const char *name,
float value);
141 void setUniform(
const char *name,
float *value,
size_t count);
142 void setUniform2(
const char *name,
float *value,
size_t count);
143 void setUniform3(
const char *name,
float *value,
size_t count);
145 void setUniform(
const char *name, Math::Vector2d value);
146 void setUniform3(
const char *name,
Color value);
147 void setUniform4(
const char *name,
Color value);
149 virtual void applyUniforms() {}
150 virtual int getNumTextures() {
return 0; };
151 virtual int getTexture(
int index) {
return 0; };
152 virtual int getTextureLoc(
int index) {
return 0; };
168 void camera(
const Math::Vector2d &size);
169 Math::Vector2d camera()
const;
170 Math::Vector2d cameraPos()
const {
return _cameraPos; }
171 void cameraPos(
const Math::Vector2d &pos) { _cameraPos = pos; }
173 Shader *getShader() {
return _shader; }
177 void clear(
const Color &color);
178 void drawPrimitives(uint32 primitivesType,
Vertex *vertices,
int v_size,
const Math::Matrix4 &transf = Math::Matrix4(),
Texture *texture = NULL);
179 void drawPrimitives(uint32 primitivesType,
Vertex *vertices,
int v_size, uint32 *indices,
int i_size,
const Math::Matrix4 &transf = Math::Matrix4(),
Texture *texture = NULL);
180 void drawLines(
Vertex *vertices,
int count,
const Math::Matrix4 &trsf = Math::Matrix4());
181 void drawLinesLoop(
Vertex *vertices,
int count,
const Math::Matrix4 &trsf = Math::Matrix4());
182 void draw(
Vertex *vertices,
int v_size, uint32 *indices,
int i_size,
const Math::Matrix4 &trsf = Math::Matrix4(),
Texture *texture = NULL);
183 void drawQuad(
const Math::Vector2d &size,
const Color &color =
Color(),
const Math::Matrix4 &trsf = Math::Matrix4());
184 void drawSprite(
const Common::Rect &textRect,
Texture &texture,
const Color &color =
Color(),
const Math::Matrix4 &trsf = Math::Matrix4(),
bool flipX =
false,
bool flipY =
false);
185 void drawSprite(
Texture &texture,
const Color &color =
Color(),
const Math::Matrix4 &trsf = Math::Matrix4(),
bool flipX =
false,
bool flipY =
false);
188 Math::Matrix4 getFinalTransform(
const Math::Matrix4 &trsf);
193 uint _vbo = 0, _ebo = 0;
195 Shader *_shader =
nullptr;
197 Math::Vector2d _cameraPos;
198 Math::Vector2d _cameraSize;
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: achievements_tables.h:27