AGL  0
3D graphics library
agl Namespace Reference

Classes

class  BaseEntity
 The base for all Entity and Light. More...
 
class  Camera
 Camera class for the scene. More...
 
class  Entity
 The Entity; basically all visible objects in AGL. More...
 
class  Light
 Light, adds reality to the scene. More...
 
class  Material
 Material class for entities. More...
 
class  Scene
 Scene class, which holds everything. More...
 
class  SharedEntity
 A SharedEntity shares its data off another Entity. More...
 

Functions

Light DirectionalLight (const glm::vec3 &dir=glm::vec3(0), const glm::vec4 &color=glm::vec4(1))
 Create a directional Light. More...
 
Light DirectionalLight (const glm::vec3 &dir=glm::vec3(0), float r=1, float g=1, float b=1, float a=1)
 Create a directional Light. See DirectionalLight. More...
 
Entity loadObj (const char *path, bool includeNormals, bool includeUVs)
 
void defKeyCB (GLFWwindow *window, int key, int scancode, int action, int mods)
 Default callback for key press. More...
 
void defScrollCB (GLFWwindow *window, double xoffset, double yoffset)
 Default scroll callback. More...
 
void defWindowSizeCB (GLFWwindow *window, int w, int h)
 Default window resize callback. More...
 
Entity tetrahedron ()
 Create a tetrahedron. More...
 
Entity cube (bool calcNorm=false, bool calcUV=false)
 Create a cube. More...
 
Entity cuboid (float x=2, float y=2, float z=2, bool calcNorm=false, bool calcUV=false)
 Create a cuboid. More...
 
Entity octahedron ()
 Create an octahedron. More...
 
Entity dodecahedron ()
 Create a dodecahedron. More...
 
Entity icosahedron ()
 Create an icosahedron. More...
 
Entity sphere (int lat=20, int lng=20, bool calcNorm=false, bool calcUV=false)
 Create a unit sphere. More...
 
Entity icosphere (int subdivision=3, bool calcNorm=false)
 Create a unit sphere. More...
 
Entity cylinder (float r=1, float h=2, int strips=20)
 Create a cylinder. More...
 
Entity plane (float x=2, float z=2, bool calcNorm=false, bool calcUV=false)
 Create a plane on the xz-plane. More...
 
Entity tessellatedPlane (int l=10, int h=10)
 Create a plane on the xz-plane. More...
 
void normalizeVertices (Entity &e, float t=1)
 Normalize all vertices of e. More...
 
void subdivideFaces (Entity &e)
 Subdivide all faces of e. More...
 
void calcNormals (Entity &e, bool perFace=false)
 Calculates the normals for the Entity algorithmically. More...
 
void calcTextureCoords (Entity &e, glm::vec3 px=glm::vec3(.5, 0,.5), glm::vec3 py=glm::vec3(.5,.5, 0), bool normalize=false)
 Calculates texture coordinates for the Entity algorithmically. More...
 
std::vector< GLuint > triangulatePolygon (const std::vector< GLuint > &polygon)
 Triangulates polygons with 3+ vertices. More...
 
GLuint loadShaders (std::string vertShader, std::string fragShader)
 Load a pair of shaders. More...
 
GLuint loadShadersFromFile (const char *vsPath, const char *fsPath)
 Load shaders from files. More...
 
std::string readTextFile (const char *path)
 Reads a text file. More...
 
void saveImage (const char *path, int w, int h)
 Save the current render as a ppm image. More...
 

Function Documentation

◆ defKeyCB()

void defKeyCB ( GLFWwindow *  window,
int  key,
int  scancode,
int  action,
int  mods 
)

Default callback for key press.

This moves and rotates the camera on key press. The movement is Minecraft like. Available keys are:

  • W: Moves the camera forward on the xz-plane.
  • A: Moves the camera left on the xz-plane.
  • S: Moves the camera backward on the xz-plane.
  • D: Moves the camera right on the xz-plane.
  • Q: Moves the camera down along the y-axis.
  • E: Moves the camera up along the y-axis.
  • Arrow keys: Rotates the camera around itself in the direction of the arrow.
  • 0: Resets the camera position to (3, 4, 5) and looking at the origin.

◆ defScrollCB()

void defScrollCB ( GLFWwindow *  window,
double  xoffset,
double  yoffset 
)

Default scroll callback.

This rotates the camera in the direction of the scroll. This works best with touch pads.

◆ defWindowSizeCB()

void defWindowSizeCB ( GLFWwindow *  window,
int  w,
int  h 
)

Default window resize callback.

Resizes the scene's Scene::width and Scene::height and sets a projection matrix with the appropriate aspect ratio, a 45 degree FOV and a near and far value of 0.1 and 100 respectively.

◆ loadObj()

Entity loadObj ( const char *  path,
bool  includeNormals,
bool  includeUVs 
)

◆ loadShaders()

GLuint loadShaders ( std::string  vertShader,
std::string  fragShader 
)

Load a pair of shaders.

Parameters
vertShaderThe vertex shader.
fragShaderThe fragment shader.
Returns
The program ID after loading the shaders.

This function takes in two strings consisting a vertex and a fragment shader, compiles them and creates a program. It loads the program in the current OpenGL context and returns the program ID which can be used to access the shaders.

◆ loadShadersFromFile()

GLuint loadShadersFromFile ( const char *  vsPath,
const char *  fsPath 
)

Load shaders from files.

Parameters
vsPathPath to the vertex shader.
fsPathPath to the fragment shader.
Returns
The program ID after loading the shaders.

This function loads the vertex and fragment shaders from two files and loads them with loadShaders.

◆ readTextFile()

std::string readTextFile ( const char *  path)

Reads a text file.

Parameters
pathPath to the file.
Returns
The contents of the file as a string.

◆ saveImage()

void saveImage ( const char *  path,
int  w,
int  h 
)

Save the current render as a ppm image.

Parameters
pathPath to save the image as.
wWidth of the image.
hHeight of the image.

This function saves the render of the current OpenGL context as a PPM P6 file. You can use PPM viewer or converter to view the image. ffmpeg has support for PPM.