1 #ifndef INCLUDE_AL_GRAPHICS_HPP
2 #define INCLUDE_AL_GRAPHICS_HPP
48 #include "al/graphics/al_DefaultShaders.hpp"
49 #include "al/graphics/al_Light.hpp"
50 #include "al/graphics/al_OpenGL.hpp"
51 #include "al/graphics/al_RenderManager.hpp"
65 enum class ColoringMode : unsigned int {
78 inline void bufferToDraw(
unsigned int buffer) { gl::bufferToDraw(buffer); }
81 inline void blending(
bool doBlend) { gl::blending(doBlend); }
90 inline void blendMode(
unsigned int src,
unsigned int dst,
unsigned int eq) {
91 gl::blendMode(src, dst, eq);
94 inline void blendAdd() { gl::blendMode(GL_SRC_ALPHA, GL_ONE, GL_FUNC_ADD); }
97 gl::blendMode(GL_SRC_ALPHA, GL_ONE, GL_FUNC_REVERSE_SUBTRACT);
101 gl::blendMode(GL_ONE, GL_ONE_MINUS_SRC_COLOR, GL_FUNC_ADD);
104 inline void blendMult() { gl::blendMode(GL_DST_COLOR, GL_ZERO, GL_FUNC_ADD); }
107 gl::blendMode(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);
111 inline void depthTesting(
bool testDepth) { gl::depthTesting(testDepth); }
113 inline void depthMask(
bool maskDepth) { gl::depthMask(maskDepth); }
116 inline void scissorTest(
bool testScissor) { gl::scissorTest(testScissor); }
117 inline void scissorArea(
int left,
int bottom,
int width,
int height) {
118 gl::scissorArea(left, bottom, width, height);
122 inline void culling(
bool doCulling) { gl::culling(doCulling); }
124 inline void cullFace(
unsigned int face) { gl::cullFace(face); }
125 inline void cullFaceBack() { gl::cullFace(GL_BACK); }
126 inline void cullFaceFront() { gl::cullFace(GL_FRONT); }
127 inline void cullFaceBoth() { gl::cullFace(GL_FRONT_AND_BACK); }
132 inline void polygonMode(
unsigned int mode) { gl::polygonMode(mode); }
142 gl::colorMask(r, g, b, a);
147 inline void pointSize(
float size) { gl::pointSize(size); }
148 inline void lineWidth(
float size) { gl::lineWidth(size); }
151 inline void clearColor(
float r,
float g,
float b,
float a = 1.f) {
152 gl::clearColor(r, g, b, a);
155 inline void clearColor(Color
const &c) { gl::clearColor(c.r, c.g, c.b, c.a); }
158 inline void clearDepth(
float d = 1.f) { gl::clearDepth(d); }
161 inline void clearBuffer(
int buffer,
float r,
float g,
float b,
163 gl::clearBuffer(buffer, r, g, b, a);
167 inline void clear(
float r,
float g,
float b,
float a = 1.f) {
168 gl::clearColor(r, g, b, a);
172 inline void clear(
float grayscale = 0.f,
float a = 1.f) {
173 gl::clearColor(grayscale, grayscale, grayscale, a);
177 inline void clear(Color
const &c) { clear(c.r, c.g, c.b, c.a); }
183 void tint(Color
const &c);
184 void tint(
float r,
float g,
float b,
float a = 1.f);
185 void tint(
float grayscale,
float a = 1.f);
190 void color(
float r,
float g,
float b,
float a = 1.f);
192 void color(Color
const &c);
194 void color(
float grayscale,
float a = 1.f);
207 void material(Material
const &m);
210 void lighting(
bool b);
213 void numLight(
int n);
219 void enableLight(
int idx);
220 void disableLight(
int idx);
221 void toggleLight(
int idx);
224 void light(Light
const &l,
int idx = 0);
226 void quad(Texture &tex,
float x,
float y,
float w,
float h);
227 void quadViewport(Texture &tex,
float x = -1,
float y = -1,
float w = 2,
233 void shader(ShaderProgram &s);
234 ShaderProgram &shader();
235 ShaderProgram *shaderPtr();
237 using RenderManager::camera;
239 void camera(Viewpoint
const &v)
override;
241 void send_lighting_uniforms(ShaderProgram &s,
243 void update()
override;
247 static const float LEFT_EYE;
248 static const float RIGHT_EYE;
249 static const float MONO_EYE;
252 float eye() {
return mEye; }
254 Lens
const &lens()
const {
return mLens; }
256 void lens(Lens
const &l);
262 bool initialized =
false;
264 Color mColor{1, 1, 1, 1};
265 Color mTint{1, 1, 1, 1};
267 Graphics::ColoringMode mColoringMode = ColoringMode::UNIFORM;
268 bool mRenderModeChanged =
true;
269 bool mUniformChanged =
true;
270 bool mLightingEnabled =
false;
272 ShaderProgram mesh_shader;
273 ShaderProgram color_shader;
274 ShaderProgram tex_shader;
276 int color_location = 0;
277 int color_tint_location = 0;
278 int mesh_tint_location = 0;
279 int tex_tint_location = 0;
282 Light mLights[al_max_num_lights()];
283 bool mLightOn[al_max_num_lights()];
286 ShaderProgram lighting_color_shader[al_max_num_lights()];
287 ShaderProgram lighting_mesh_shader[al_max_num_lights()];
288 ShaderProgram lighting_tex_shader[al_max_num_lights()];
289 ShaderProgram lighting_material_shader[al_max_num_lights()];
291 int lighting_color_location[al_max_num_lights()];
292 int lighting_color_tint_location[al_max_num_lights()];
293 int lighting_mesh_tint_location[al_max_num_lights()];
294 int lighting_tex_tint_location[al_max_num_lights()];
295 int lighting_material_tint_location[al_max_num_lights()];
302 bool is_omni =
false;
304 ShaderProgram omni_mesh_shader;
305 ShaderProgram omni_color_shader;
306 ShaderProgram omni_tex_shader;
308 int omni_color_location = 0;
309 int omni_color_tint_location = 0;
310 int omni_mesh_tint_location = 0;
311 int omni_tex_tint_location = 0;
313 ShaderProgram omni_lighting_color_shader[al_max_num_lights()];
314 ShaderProgram omni_lighting_mesh_shader[al_max_num_lights()];
315 ShaderProgram omni_lighting_tex_shader[al_max_num_lights()];
316 ShaderProgram omni_lighting_material_shader[al_max_num_lights()];
318 int omni_lighting_color_location[al_max_num_lights()];
319 int omni_lighting_color_tint_location[al_max_num_lights()];
320 int omni_lighting_mesh_tint_location[al_max_num_lights()];
321 int omni_lighting_tex_tint_location[al_max_num_lights()];
322 int omni_lighting_material_tint_location[al_max_num_lights()];
Interface for loading fonts and rendering text.
void blendScreen()
Set blend mode to screen (symmetric multiplicative lighten)
void blendAdd()
Set blend mode to additive (symmetric additive lighten)
void polygonMode(unsigned int mode)
void blending(bool doBlend)
Turn blending on/off.
void polygonLine()
Draw only edges of polygons with lines.
void depthMask(bool maskDepth)
Turn the depth mask on/off.
void polygonFill()
Draw filled polygons.
void cullFace(unsigned int face)
face=[GL_FRONT, GL_BACK, GL_FRONT_AND_BACK], initial: GL_BACK
void colorMask(bool r, bool g, bool b, bool a)
Turn color mask RGBA components on/off.
void polygonPoint()
Draw only points of vertices.
void blendMult()
Set blend mode to multiplicative (symmetric multiplicative darken)
void colorMask(bool b)
Turn color mask on/off (all RGBA components)
void scissorTest(bool testScissor)
Turn scissor testing on/off.
void culling(bool doCulling)
Turn face culling on/off.
void blendSub()
Set blend mode to subtractive (symmetric additive darken)
void blendMode(unsigned int src, unsigned int dst, unsigned int eq)
void blendTrans()
Set blend mode to transparent (asymmetric)
void bufferToDraw(unsigned int buffer)
void depthTesting(bool testDepth)
Turn depth testing on/off.