Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Shaptic / Lighting.c
Last active January 3, 2019 20:29
Point-lighting shader
#define MAX_LIGHTS 10 // Re-written on the fly
/**
* @file
* Fragment shader for lighting.
* Per-pixel point light lighting is done in this shader.
*
* @author me
* @addtogroup Shaders
* @{
@Shaptic
Shaptic / CMeshInstance.hpp
Created November 14, 2012 01:03
CMeshInstance class in IronClad
// IronClad vertex buffer object wrapper.
#include "VertexBuffer.hpp"
// IronClad custom mesh loader.
#include "Mesh.hpp"
class CMeshInstance
{
public:
/**
void CScene::Render()
// Model-view matrix.
static math::matrix4x4_t MVMatrix = math::IDENTITY;
// Offload vertex data onto the GPU if it has not been done yet.
if(!m_GeometryVBO.Finalized()) m_GeometryVBO.FinalizeBuffer();
// Bind VBO that contains the mesh vertex data.
m_GeometryVBO.Bind();
@Shaptic
Shaptic / CScene.cpp
Created November 14, 2012 01:21
Rendering meshes in a scene.
void CScene::Render()
{
// Model-view identity matrix, to be loaded later.
static math::matrix4x4_t MVMatrix = math::IDENTITY;
// Offload vertex data onto the GPU if it has not been done yet.
if(!m_GeometryVBO.Finalized()) m_GeometryVBO.FinalizeBuffer();
// Bind VBO that contains the mesh vertex data.
m_GeometryVBO.Bind();
@Shaptic
Shaptic / Default.vs
Created November 14, 2012 01:44
Basic vertex shader.
#version 330
// Input from program: vertex, texture coordinates,
// and color.
//
// In IronClad, these are part of a vertex2_t struct
// that is passed to the VBO after being loaded with
// mesh data.
smooth in vec2 vs_vertex;
smooth in vec2 vs_texc;
@Shaptic
Shaptic / Types.hpp
Last active December 12, 2015 02:39
Basic types used in the font renderer.
/// Various data structures for simplifying font handling.
#ifndef TYPES_HPP
#define TYPES_HPP
/// Represents a point in 2D rectangular-coordinate space.
struct vector2_t
{
float x, y;
/// Default constructor that sets components to 0.
@Shaptic
Shaptic / Font.hpp
Last active December 12, 2015 02:39
Font class for rendering TrueType fonts in OpenGL.
// Font class header.
#ifndef FONT_HPP
#define FONT_HPP
// Storing {char:glyph} pairs.
#include <map>
// Include files for FreeType 2.
#include "ft2build.h"
#include "freetype/freetype.h"
@Shaptic
Shaptic / Font.cpp
Last active December 12, 2015 03:09
CFont::CFont() constructor.
CFont::CFont() : m_ready(false), m_loaded(false)
{
// Initialize FreeType.
if(!CFont::Initialize()) return;
// Load the shader.
if(!m_FontRender.LoadFromFile("Default.vs", "FontRender.fs"))
return;
// Give the font shader an identity matrix for the model-view
@Shaptic
Shaptic / Font.cpp
Created February 4, 2013 05:53
CFont::Initialize() - Initializes the TrueType 2 library.
bool CFont::Initialize()
{
if(s_loaded) return true;
if(FT_Init_FreeType(&s_Library) != 0) return false;
return (s_loaded = true);
}
@Shaptic
Shaptic / Font.cpp
Last active December 12, 2015 03:18
CFont::LoadFromFile() - Loads a font file in a certain size.
bool CFont::LoadFromFile(const std::string& filename, const uint16_t size)
{
// Make sure everything is ready.
if(!m_ready || !CFont::s_loaded) return false;
// Create a new font face.
if(FT_New_Face(s_Library, filename.c_str(), 0, &m_FontFace) != 0)
return false;
// Set the size of the font face.