21#ifndef _TGX_RENDERER3D_H_
22#define _TGX_RENDERER3D_H_
57 extern const uint16_t UNIT_CUBE_FACES[6*4];
58 extern const uint16_t UNIT_CUBE_FACES_NORMALS[6 * 4];
111 template<
typename color_t, Shader LOADED_SHADERS = TGX_SHADER_MASK_ALL,
typename ZBUFFER_t =
float>
118 static_assert(is_color<color_t>::value,
"color_t must be one of the color types defined in color.h");
119 static_assert((std::is_same<ZBUFFER_t, float>::value) || (std::is_same<ZBUFFER_t, uint16_t>::value),
"The Z-buffer type must be either float or uint16_t");
122 static constexpr int ENABLE_TEXTURING = (TGX_SHADER_HAS_ONE_FLAG(LOADED_SHADERS , (
SHADER_TEXTURE | TGX_SHADER_MASK_TEXTURE_MODE | TGX_SHADER_MASK_TEXTURE_QUALITY)));
127 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_PROJECTION),
"At least one of the two shaders SHADER_PERSPECTIVE or SHADER_ORTHO must be enabled");
128 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_ZBUFFER),
"At least one of the two shaders SHADER_NOZBUFFER or SHADER_ZBUFFER must be enabled");
129 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_SHADING),
"At least one of the two shaders SHADER_FLAT or SHADER_GOURAUD must be enabled");
130 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_TEXTURE),
"At least one of the two shaders SHADER_TEXTURE or SHADER_NOTEXTURE must be enabled");
131 static_assert((~(TGX_SHADER_HAS_TEXTURE(ENABLED_SHADERS))) || (TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_TEXTURE_QUALITY)),
"When using texturing, at least one of the two shaders SHADER_TEXTURE_BILINEAR or SHADER_TEXTURE_NEAREST must be enabled");
132 static_assert((~(TGX_SHADER_HAS_TEXTURE(ENABLED_SHADERS))) || (TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS, TGX_SHADER_MASK_TEXTURE_MODE)),
"When using texturing, at least one of the two shaders SHADER_TEXTURE_WRAP_POW2 or SHADER_TEXTURE_CLAMP must be enabled");
303 void setOrtho(
float left,
float right,
float bottom,
float top,
float zNear,
float zFar);
322 void setFrustum(
float left,
float right,
float bottom,
float top,
float zNear,
float zFar);
504 void setLookAt(
float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ);
777 void setMaterial(
RGBf color,
float ambiantStrength,
float diffuseStrength,
float specularStrength,
int specularExponent);
840 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr,
841 const fVec2 * T1 =
nullptr,
const fVec2 * T2 =
nullptr,
const fVec2 * T3 =
nullptr,
858 const RGBf & col1,
const RGBf & col2,
const RGBf & col3,
859 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr);
881 const uint16_t * ind_vertices,
const fVec3 * vertices,
882 const uint16_t * ind_normals =
nullptr,
const fVec3* normals =
nullptr,
883 const uint16_t * ind_texture =
nullptr,
const fVec2* textures =
nullptr,
904 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr,
const fVec3 * N4 =
nullptr,
905 const fVec2 * T1 =
nullptr,
const fVec2 * T2 =
nullptr,
const fVec2 * T3 =
nullptr,
const fVec2 * T4 =
nullptr,
927 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr,
const fVec3 * N4 =
nullptr);
953 const uint16_t * ind_vertices,
const fVec3 * vertices,
954 const uint16_t * ind_normals =
nullptr,
const fVec3* normals =
nullptr,
955 const uint16_t * ind_texture =
nullptr,
const fVec2* textures =
nullptr,
1259 void drawWireFrameLines(
int nb_lines,
const uint16_t* ind_vertices,
const fVec3* vertices,
float thickness, color_t color,
float opacity);
1391 void drawWireFrameQuads(
int nb_quads,
const uint16_t* ind_vertices,
const fVec3* vertices,
float thickness, color_t color,
float opacity);
1583 void drawPixels(
int nb_pixels,
const fVec3* pos_list,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
1646 void drawDots(
int nb_dots,
const fVec3* pos_list,
const int* radius_ind,
const int* radius,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
1672 TGX_INLINE
float _clipbound_xy()
const
1674 return (256 + 3*((MAXVIEWPORTDIMENSION * 256) / ((_lx > _ly) ? _lx : _ly))) / 1024.0f;
1680 TGX_INLINE
bool _validDraw()
const
1682 return ((_lx > 0) && (_ly > 0) && (_uni.im !=
nullptr) && (_uni.im->isValid()));
1687 TGX_NOINLINE
void _recompute_wa_wb();
1694 TGX_NOINLINE
void _rectifyShaderOrtho();
1697 TGX_NOINLINE
void _rectifyShaderZbuffer();
1700 TGX_NOINLINE
void _rectifyShaderShading(Shader new_shaders);
1703 TGX_NOINLINE
void _rectifyShaderTextureWrapping();
1706 TGX_NOINLINE
void _rectifyShaderTextureQuality();
1715 void _drawTriangleClipped(
const int RASTER_TYPE,
1716 const fVec4* Q0,
const fVec4* Q1,
const fVec4* Q2,
1717 const fVec3* N0,
const fVec3* N1,
const fVec3* N2,
1718 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
1719 const RGBf& Vcol0,
const RGBf& Vcol1,
const RGBf& Vcol2);
1723 void _drawTriangleClippedSub(
const int RASTER_TYPE,
const int plane,
1724 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3);
1728 void _drawTriangle(
const int RASTER_TYPE,
1729 const fVec3* P0,
const fVec3* P1,
const fVec3* P2,
1730 const fVec3* N0,
const fVec3* N1,
const fVec3* N2,
1731 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
1732 const RGBf& Vcol0,
const RGBf& Vcol1,
const RGBf& Vcol2);
1736 void _drawQuad(
const int RASTER_TYPE,
1737 const fVec3* P0,
const fVec3* P1,
const fVec3* P2,
const fVec3* P3,
1738 const fVec3* N0,
const fVec3* N1,
const fVec3* N2,
const fVec3* N3,
1739 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
const fVec2* T3,
1740 const RGBf& Vcol0,
const RGBf& Vcol1,
const RGBf& Vcol2,
const RGBf& Vcol3);
1744 void _drawMesh(
const int RASTER_TYPE,
const Mesh3D<color_t>* mesh);
1753 template<
bool DRAW_FAST>
void _drawWireFrameMesh(
const Mesh3D<color_t>* mesh,
bool draw_chained_meshes, color_t color,
float opacity,
float thickness);
1755 template<
bool DRAW_FAST>
void _drawWireFrameLine(
const fVec3& P1,
const fVec3& P2, color_t color,
float opacity,
float thickness);
1757 template<
bool DRAW_FAST>
void _drawWireFrameLines(
int nb_lines,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
1759 template<
bool DRAW_FAST>
void _drawWireFrameTriangle(
const fVec3& P1,
const fVec3& P2,
const fVec3& P3, color_t color,
float opacity,
float thickness);
1761 template<
bool DRAW_FAST>
void _drawWireFrameTriangles(
int nb_triangles,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
1763 template<
bool DRAW_FAST>
void _drawWireFrameQuad(
const fVec3& P1,
const fVec3& P2,
const fVec3& P3,
const fVec3& P4, color_t color,
float opacity,
float thickness);
1765 template<
bool DRAW_FAST>
void _drawWireFrameQuads(
int nb_quads,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
1775 template<
bool USE_BLENDING>
void _drawPixel(
const fVec3& pos, color_t color,
float opacity);
1778 template<
bool USE_COLORS,
bool USE_BLENDING>
void _drawPixels(
int nb_pixels,
const fVec3* pos_list,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
1781 template<
bool USE_BLENDING>
void _drawDot(
const fVec3& pos,
int r, color_t color,
float opacity);
1784 template<
bool USE_RADIUS,
bool USE_COLORS,
bool USE_BLENDING>
void _drawDots(
int nb_dots,
const fVec3* pos_list,
const int* radius_ind,
const int* radius,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
1788 template<
bool CHECKRANGE,
bool USE_BLENDING> TGX_INLINE
inline void drawPixelZbuf(
int x,
int y, color_t color,
float opacity,
float z)
1790 if (CHECKRANGE && ((x < 0) || (x >= _uni.im->lx()) || (y < 0) || (y >= _uni.im->ly())))
return;
1791 ZBUFFER_t& W = _uni.zbuf[x + _uni.im->lx() * y];
1792 const ZBUFFER_t aa = (std::is_same<ZBUFFER_t, uint16_t>::value) ? ((ZBUFFER_t)(z * _uni.wa + _uni.wb)) : ((ZBUFFER_t)z);
1796 if (USE_BLENDING) _uni.im->template drawPixel<false>({ x, y }, color, opacity);
else _uni.im->template drawPixel<false>({ x, y }, color);
1801 template<
bool CHECKRANGE,
bool USE_BLENDING> TGX_INLINE
inline void drawHLineZbuf(
int x,
int y,
int w, color_t color,
float opacity,
float z)
1805 const int lx = _uni.im->lx();
1806 const int ly = _uni.im->ly();
1807 if ((y < 0) || (y >= ly) || (x >= lx))
return;
1808 if (x < 0) { w += x; x = 0; }
1809 if (x + w > lx) { w = lx - x; }
1811 while(w--) drawPixelZbuf<CHECKRANGE, USE_BLENDING>(x++, y, color, opacity, z);
1815 template<
bool CHECKRANGE,
bool USE_BLENDING>
void _drawCircleZbuf(
int xm,
int ym,
int r, color_t color,
float opacity,
float z);
1821 float _unitSphereScreenDiameter();
1824 template<
bool WIREFRAME,
bool DRAWFAST>
void _drawSphere(
int nb_sectors,
int nb_stacks,
const Image<color_t>* texture,
float thickness, color_t color,
float opacity);
1834 void _clip(
int & fl,
const fVec4 & P,
float bx,
float Bx,
float by,
float By)
1836 if (P.x >= bx) { fl &= (~(1)); }
1837 if (P.x <= Bx) { fl &= (~(2)); }
1838 if (P.y >= by) { fl &= (~(4)); }
1839 if (P.y <= By) { fl &= (~(8)); }
1840 if ((P.z >= -1.0f)&&(P.w > 0)) { fl &= (~(16)); }
1841 if (P.z <= +1.0f) { fl &= (~(32)); }
1846 void _clip(
int & fl,
const fVec3 & P,
float bx,
float Bx,
float by,
float By,
const fMat4 & M)
1848 fVec4 S = M.mult1(P);
1850 return _clip(fl, S, bx, Bx, by, By);
1856 bool _discardBox(
const fBox3 & bb,
const fMat4 & M)
1858 if ((bb.minX == 0) && (bb.maxX == 0) && (bb.minY == 0) && (bb.maxY == 0) && (bb.minZ == 0) && (bb.maxZ == 0))
1861 const float ilx = 2.0f *
fast_inv((
float)_lx);
1862 const float bx = (_ox - 1) * ilx - 1.0f;
1863 const float Bx = (_ox + _uni.im->width() + 1) * ilx - 1.0f;
1864 const float ily = 2.0f *
fast_inv((
float)_ly);
1865 const float by = (_oy - 1) * ily - 1.0f;
1866 const float By = (_oy + _uni.im->height() + 1) * ily - 1.0f;
1869 _clip(fl,
fVec3(bb.minX, bb.minY, bb.minZ), bx, Bx, by, By, M);
1870 if (fl == 0)
return false;
1871 _clip(fl,
fVec3(bb.minX, bb.minY, bb.maxZ), bx, Bx, by, By, M);
1872 if (fl == 0)
return false;
1873 _clip(fl,
fVec3(bb.minX, bb.maxY, bb.minZ), bx, Bx, by, By, M);
1874 if (fl == 0)
return false;
1875 _clip(fl,
fVec3(bb.minX, bb.maxY, bb.maxZ), bx, Bx, by, By, M);
1876 if (fl == 0)
return false;
1877 _clip(fl,
fVec3(bb.maxX, bb.minY, bb.minZ), bx, Bx, by, By, M);
1878 if (fl == 0)
return false;
1879 _clip(fl,
fVec3(bb.maxX, bb.minY, bb.maxZ), bx, Bx, by, By, M);
1880 if (fl == 0)
return false;
1881 _clip(fl,
fVec3(bb.maxX, bb.maxY, bb.minZ), bx, Bx, by, By, M);
1882 if (fl == 0)
return false;
1883 _clip(fl,
fVec3(bb.maxX, bb.maxY, bb.maxZ), bx, Bx, by, By, M);
1884 if (fl == 0)
return false;
1891 bool _discardTriangle(
const fVec4 & P1,
const fVec4 & P2,
const fVec4 & P3)
1893 const float ilx = 2.0f *
fast_inv((
float)_lx);
1894 const float bx = (_ox - 1) * ilx - 1.0f;
1895 const float Bx = (_ox + _uni.im->width() + 1) * ilx - 1.0f;
1896 const float ily = 2.0f *
fast_inv((
float)_ly);
1897 const float by = (_oy - 1) * ily - 1.0f;
1898 const float By = (_oy + _uni.im->height() + 1) * ily - 1.0f;
1901 _clip(fl, P1, bx, Bx, by, By);
1902 if (fl == 0)
return false;
1903 _clip(fl, P2, bx, Bx, by, By);
1904 if (fl == 0)
return false;
1905 _clip(fl, P3, bx, Bx, by, By);
1906 if (fl == 0)
return false;
1912 bool _clip2(
float clipboundXY,
const fVec3 & P,
const fMat4 & M)
1914 fVec4 S = M.mult1(P);
1918 if (S.w <= 0) S.z = -2;
1920 return ((S.x <= -clipboundXY) || (S.x >= clipboundXY)
1921 || (S.y <= -clipboundXY) || (S.y >= clipboundXY)
1922 || (S.z <= -1) || (S.z >= 1));
1927 bool _clipTestNeeded(
float clipboundXY,
const fBox3 & bb,
const fMat4 & M)
1929 return (_clip2(clipboundXY,
fVec3(bb.minX, bb.minY, bb.minZ), M)
1930 || _clip2(clipboundXY,
fVec3(bb.minX, bb.minY, bb.maxZ), M)
1931 || _clip2(clipboundXY,
fVec3(bb.minX, bb.maxY, bb.minZ), M)
1932 || _clip2(clipboundXY,
fVec3(bb.minX, bb.maxY, bb.maxZ), M)
1933 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.minY, bb.minZ), M)
1934 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.minY, bb.maxZ), M)
1935 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.maxY, bb.minZ), M)
1936 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.maxY, bb.maxZ), M));
1956 return (CP.
x * P.
x) + (CP.
y * P.
y) + (CP.
z * P.
z) + (CP.
w * P.
w) + off;
1969 inline float _cpfactor(
const tgx::fVec4& CP,
const float sdistA,
const float sdistB)
1971 return sdistA / (sdistA - sdistB);
1976 void _triangleClip1in(
int shader,
tgx::fVec4 CP,
1977 float cp1,
float cp2,
float cp3,
1978 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3,
1979 RasterizerVec4& nP1, RasterizerVec4& nP2, RasterizerVec4& nP3, RasterizerVec4& nP4);
1983 void _triangleClip2in(
int shader,
tgx::fVec4 CP,
1984 float cp1,
float cp2,
float cp3,
1985 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3,
1986 RasterizerVec4& nP1, RasterizerVec4& nP2, RasterizerVec4& nP3, RasterizerVec4& nP4);
1989 int _triangleClip(
int shader,
tgx::fVec4 CP,
float off,
1990 const RasterizerVec4 & P1,
const RasterizerVec4 & P2,
const RasterizerVec4 & P3,
1991 RasterizerVec4 & nP1, RasterizerVec4 & nP2, RasterizerVec4 & nP3, RasterizerVec4 & nP4);
1999 static const int _POWTABSIZE = 32;
2002 float _fastpowtab[_POWTABSIZE];
2005 TGX_INLINE
inline void _precomputeSpecularTable(
int exponent)
2007 if (_currentpow == exponent)
return;
2008 _precomputeSpecularTable2(exponent);
2011 TGX_NOINLINE
void _precomputeSpecularTable2(
int exponent);
2015 TGX_INLINE
inline float _powSpecular(
float x)
const
2017 const float indf = (_powmax - x) * _POWTABSIZE;
2018 const int indi =
max(0,(
int)indf);
2019 return (indi >= (_POWTABSIZE - 1)) ? 0.0f : (_fastpowtab[indi] + (indf - indi) * (_fastpowtab[indi + 1] - _fastpowtab[indi]));;
2024 template<
bool TEXTURE> TGX_INLINE
inline RGBf _phong(
float v_diffuse,
float v_specular)
const
2026 RGBf col = _r_ambiantColor;
2027 col += _r_diffuseColor *
max(v_diffuse, 0.0f);
2028 col += _r_specularColor * _powSpecular(v_specular);
2029 if (!(TEXTURE)) col *= _r_objectColor;
2036 TGX_INLINE
inline RGBf _phong(
float v_diffuse,
float v_specular, RGBf color)
const
2038 RGBf col = _r_ambiantColor;
2039 col += _r_diffuseColor *
max(v_diffuse, 0.0f);
2040 col += _r_specularColor * _powSpecular(v_specular);
2062 RasterizerParams<color_t, color_t,ZBUFFER_t> _uni;
2067 int _texture_wrap_mode;
2068 int _texture_quality;
2077 RGBf _specularColor;
2085 float _ambiantStrength;
2086 float _diffuseStrength;
2087 float _specularStrength;
2088 int _specularExponent;
2092 fMat4 _r_modelViewM;
2095 fVec3 _r_light_inorm;
2098 RGBf _r_ambiantColor;
2099 RGBf _r_diffuseColor;
2100 RGBf _r_specularColor;
2101 RGBf _r_objectColor;
2107 struct ExtVec4 :
public RasterizerVec4
2126#include "Renderer3D.inl"
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Mat4< float > fMat4
4x4 matrix with single (float) precision
Definition: Mat4.h:54
Utility/miscellaneous functions used throughout the library.
TGX_INLINE T max(const T &a, const T &b)
Don't know why but much faster than fmaxf() for floats.
Definition: Misc.h:184
TGX_INLINE float fast_inv(float x)
Fast (approximate) computation of 1/x.
Definition: Misc.h:219
3D triangle rasterizer function.
#define TGX_RASTERIZE_SUBPIXEL_BITS
Sub-pixel precision bits.
Definition: Rasterizer.h:46
Shader
List of shaders available for 3D graphics.
Definition: ShaderParams.h:44
@ SHADER_NOTEXTURE
disable texture mapping
Definition: ShaderParams.h:58
@ SHADER_TEXTURE
enable texture mapping
Definition: ShaderParams.h:59
Triangle shader functions.
Vec3< float > fVec3
Floating point valued 3D vector with single (float) precision.
Definition: Vec3.h:52
Vec4< float > fVec4
Floating point valued 4D vector with single (float) precision.
Definition: Vec4.h:54
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:143
Class for drawing 3D objects onto a Image [MAIN CLASS FOR THE 3D API].
Definition: Renderer3D.h:113
void drawAdaptativeSphere(float quality=1.0f)
Draw a unit radius sphere centered at the origin S(0,1) in model space.
void drawQuads(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices, const uint16_t *ind_normals=nullptr, const fVec3 *normals=nullptr, const uint16_t *ind_texture=nullptr, const fVec2 *textures=nullptr, const Image< color_t > *texture_image=nullptr)
Draw a collection of quads.
void drawWireFrameLine(const fVec3 &P1, const fVec3 &P2)
Draw a wireframe line segment [low quality].
void drawMesh(const Mesh3D< color_t > *mesh, bool use_mesh_material=true, bool draw_chained_meshes=true)
Draw a Mesh3D object.
void drawDot(const fVec3 &pos, int r, color_t color, float opacity)
Draw a dot/circle at a given position in model space.
void setMaterialAmbiantStrength(float strenght=0.1f)
Set how much the object material reflects the ambient light.
void drawSphere(int nb_sectors, int nb_stacks)
Draw a unit radius sphere centered at the origin S(0,1) in model space.
void drawWireFrameAdaptativeSphere(float quality, float thickness, color_t color, float opacity)
Draw a wireframe unit radius sphere centered at the origin (in model space) [high quality].
void setMaterialSpecularExponent(int exponent=16)
Set the object specular exponent.
void drawWireFrameTriangle(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3)
Draw a wireframe triangle [low quality].
void drawWireFrameCube()
Draw the wireframe cube [0,1]^3 (in model space) [low quality].
void setMaterialSpecularStrength(float strenght=0.5f)
Set how much the object material reflects the specular light.
void setMaterialDiffuseStrength(float strenght=0.6f)
Set how much the object material reflects the diffuse light.
void drawWireFrameQuad(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4)
Draw a wireframe quad [low quality].
void setShaders(Shader shaders)
Set the shaders to use for subsequent drawing operations.
iVec2 modelToImage(fVec3 P)
Convert from model coordinates to the corresponding image pixel.
void setModelPosScaleRot(const fVec3 ¢er=fVec3{ 0, 0, 0 }, const fVec3 &scale=fVec3(1, 1, 1), float rot_angle=0, const fVec3 &rot_dir=fVec3{ 0, 1, 0 })
Set the model tranformation matrix to move an object to a given a given location, scale and rotation.
void drawCube(const Image< color_t > *texture_front, const Image< color_t > *texture_back, const Image< color_t > *texture_top, const Image< color_t > *texture_bottom, const Image< color_t > *texture_left, const Image< color_t > *texture_right)
draw a textured unit cube [-1,1]^3 (in model space)
void drawDots(int nb_dots, const fVec3 *pos_list, const int *radius_ind, const int *radius, const int *colors_ind, const color_t *colors, const int *opacities_ind, const float *opacities)
Draw a list of dots/circles at given positions in model space.
fMat4 getViewMatrix() const
Return the current view matrix.
void setLookAt(const fVec3 eye, const fVec3 center, const fVec3 up)
Set the view matrix so that the camera is looking at a given direction.
void drawWireFrameMesh(const Mesh3D< color_t > *mesh, bool draw_chained_meshes, float thickness, color_t color, float opacity)
Draw a mesh in wireframe [high quality].
void drawWireFrameQuads(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a collection of wireframe quads [low quality].
void setLightAmbiant(const RGBf &color)
Set the scene ambiant light color.
void drawWireFrameAdaptativeSphere(float quality=1.0f)
Draw a wireframe unit radius sphere centered at the origin (in model space) [low quality].
void drawCube()
Draw the unit cube [-1,1]^3 in model space.
void drawWireFrameSphere(int nb_sectors, int nb_stacks, float thickness, color_t color, float opacity)
Draw a wireframe unit radius sphere centered at the origin (in model space) [high quality].
fMat4 getProjectionMatrix() const
Return the current projection matrix.
void drawWireFrameLines(int nb_lines, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a collection of wireframe line segments [low quality].
void setZbuffer(ZBUFFER_t *zbuffer)
Set the z-buffer.
void setMaterialColor(RGBf color)
Set the object material color.
void setLightDirection(const fVec3 &direction)
Set the light source direction.
void setLight(const fVec3 direction, const RGBf &ambiantColor, const RGBf &diffuseColor, const RGBf &specularColor)
Set all the lighting parameters of the scene at once.
void setMaterial(RGBf color, float ambiantStrength, float diffuseStrength, float specularStrength, int specularExponent)
Set all the object material properties at once.
void setTextureWrappingMode(Shader wrap_mode)
Set the wrap mode when for texturing.
void drawDots(int nb_dots, const fVec3 *pos_list, const int radius)
Draw a list of dots/circles at given positions in model space.
fVec4 worldToNDC(fVec3 P)
Convert from world coordinates to normalized device coordinates (NDC).
void setViewMatrix(const fMat4 &M)
Set the view transformation matrix.
void setViewportSize(const iVec2 &viewport_dim)
Set the size of the viewport.
TGX_NOINLINE Renderer3D(const iVec2 &viewportSize={0, 0}, Image< color_t > *im=nullptr, ZBUFFER_t *zbuffer=nullptr)
Constructor.
void setViewportSize(int lx, int ly)
Set the size of the viewport.
iVec2 worldToImage(fVec3 P)
Convert from world coordinates to the corresponding image pixel.
void setCulling(int w)
Set the face culling strategy.
void drawTriangleWithVertexColor(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const RGBf &col1, const RGBf &col2, const RGBf &col3, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr)
Draw a single triangle with a given colors on each of its vertices.
void usePerspectiveProjection()
Set projection mode to perspective (ie with z-divide).
void setModelMatrix(const fMat4 &M)
Set the model tranformation matrix.
void drawWireFrameTriangle(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, float thickness, color_t color, float opacity)
Draw a wireframe triangle [high quality].
void setPerspective(float fovy, float aspect, float zNear, float zFar)
Set the projection matrix as a perspective matrix.
void drawWireFrameQuads(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a collection of wireframe quads [high quality].
void drawPixel(const fVec3 &pos)
Draw a single pixel at a given position in model space.
void setOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
Set the projection matrix as an orthographic matrix.
fMat4 getModelMatrix() const
Return the model tranformation matrix.
void drawWireFrameLines(int nb_lines, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a collection of wireframe line segments [high quality].
void setImage(Image< color_t > *im)
Set the image that will be drawn onto.
void drawPixels(int nb_pixels, const fVec3 *pos_list)
Draw a list of pixels at given positions in model space.
void drawPixel(const fVec3 &pos, color_t color, float opacity)
Draw a single pixel at a given position in model space.
void setLightDiffuse(const RGBf &color)
Set the scene diffuse light color.
void setLightSpecular(const RGBf &color)
Set the scene specular light color.
void setOffset(const iVec2 &offset)
Set the offset of the image relative to the viewport.
void drawCube(const fVec2 v_front_ABCD[4], const Image< color_t > *texture_front, const fVec2 v_back_EFGH[4], const Image< color_t > *texture_back, const fVec2 v_top_HADE[4], const Image< color_t > *texture_top, const fVec2 v_bottom_BGFC[4], const Image< color_t > *texture_bottom, const fVec2 v_left_HGBA[4], const Image< color_t > *texture_left, const fVec2 v_right_DCFE[4], const Image< color_t > *texture_right)
Draw a textured unit cube [-1,1]^3 in model space.
void drawWireFrameQuad(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4, float thickness, color_t color, float opacity)
Draw a wireframe quad [high quality].
void setLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Set the view matrix so that the camera is looking at a given direction.
void useOrthographicProjection()
Set projection mode to orthographic (ie no z-divide).
void drawTriangle(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr, const fVec2 *T1=nullptr, const fVec2 *T2=nullptr, const fVec2 *T3=nullptr, const Image< color_t > *texture=nullptr)
Draw a single triangle.
void drawTriangles(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices, const uint16_t *ind_normals=nullptr, const fVec3 *normals=nullptr, const uint16_t *ind_texture=nullptr, const fVec2 *textures=nullptr, const Image< color_t > *texture_image=nullptr)
Draw a collection of triangles.
void clearZbuffer()
Clear the Zbuffer.
void drawWireFrameLine(const fVec3 &P1, const fVec3 &P2, float thickness, color_t color, float opacity)
Draw a wireframe line segment [high quality].
void drawQuadWithVertexColor(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4, const RGBf &col1, const RGBf &col2, const RGBf &col3, const RGBf &col4, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr, const fVec3 *N4=nullptr)
Draw a single quad with a given colors on each of its four vertices.
void drawWireFrameMesh(const Mesh3D< color_t > *mesh, bool draw_chained_meshes=true)
Draw a mesh in wireframe [low quality].
fVec4 modelToNDC(fVec3 P)
Convert from model coordinates to normalized device coordinates (NDC).
void drawWireFrameTriangles(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a collection of wireframe triangles [high quality].
void drawSphere(int nb_sectors, int nb_stacks, const Image< color_t > *texture)
Draw a textured unit radius sphere centered at the origin S(0,1) in model space.
void drawDot(const fVec3 &pos, int r)
Draw a dot/circle at a given position in model space.
void setFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
Set the projection matrix as a perspective matrix.
void setProjectionMatrix(const fMat4 &M)
Set the projection matrix.
void setTextureQuality(Shader quality)
Set the texturing quality.
void drawPixels(int nb_pixels, const fVec3 *pos_list, const int *colors_ind, const color_t *colors, const int *opacities_ind, const float *opacities)
Draw a list of pixels at given positions in model space with different colors and opacities.
void drawAdaptativeSphere(const Image< color_t > *texture, float quality=1.0f)
Draw a textured unit radius sphere centered at the origin S(0,1) in model space.
void drawWireFrameSphere(int nb_sectors, int nb_stacks)
Draw a wireframe unit radius sphere centered at the origin (in model space) [low quality].
void drawWireFrameTriangles(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a collection of wireframe triangles [low quality].
void drawQuad(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr, const fVec3 *N4=nullptr, const fVec2 *T1=nullptr, const fVec2 *T2=nullptr, const fVec2 *T3=nullptr, const fVec2 *T4=nullptr, const Image< color_t > *texture=nullptr)
Draw a single quad.
void setOffset(int ox, int oy)
Set the offset of the image relative to the viewport.
void drawWireFrameCube(float thickness, color_t color, float opacity)
Draw the wireframe cube [0,1]^3 (in model space) [high quality].
3D mesh data stucture.
Definition: Mesh3D.h:155
Color in R,G,B float format.
Definition: Color.h:2407
void clamp()
Clamp all color channel to [0.0f,1.0f].
Definition: Color.h:2647
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73
T z
'z' coordinate (third dimension)
Definition: Vec3.h:83
T w
'w' coordinate (fourth dimension)
Definition: Vec4.h:85
void zdivide()
Performs the 'z-divide' operation.
Definition: Vec4.h:478