Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Shaptic / Animate.fs
Created February 10, 2013 22:14
Animation fragment shader
#version 330 core
uniform sampler2D texture;
// Individual sprite dimensions expressed in the proper texcoord range.
// For example, a 32x32 sprite would be <0.03125, 0.03125>
// This would then be interpolated from [0, 0.03125], properly rendering
// all of the texels in the desired sprite.
uniform vec2 tc_offset;
@Shaptic
Shaptic / Animation.cpp
Last active December 12, 2015 09:28
Animation loading implementation
#include "Entity/Animation.hpp"
bool CAnimation::LoadFromFile(const std::string& filename,
gfx::CVertexBuffer& VBO)
{
// Open the .icanim file.
std::ifstream anim(filename, std::ios::binary);
CAnimation::AnimationHeader& header = m_SheetDetails;
memset(&header, NULL, sizeof header);
@Shaptic
Shaptic / Animation.hpp
Last active December 12, 2015 09:28
Animation class header
#ifndef ANIMATION_HPP
#define ANIMATION_HPP
// Framebuffer object
#include "Graphics/Framebuffer.hpp"
// Animation inherits rigid body entity
#include "Entity/RigidBody.hpp"
// For the timer
@Shaptic
Shaptic / FontRender.fs
Created February 4, 2013 06:35
Fragment shader for mono-chrome texture rendering.
#version 330 core
// Our texture
uniform sampler2D texture;
// Incoming attributes from the vertex shader
smooth in vec2 fs_texc;
smooth in vec4 fs_color;
// Output color
@Shaptic
Shaptic / Font.cpp
Last active October 5, 2021 00:53
CFont::RenderText() - Renders a line of text at the given position in OpenGL.
rect_t CFont::RenderText(const std::string& text, const vector2_t& Pos)
{
// VAO and buffers that will contain our text vertex data.
uint32_t vao = 0, vbo = 0, ibo = 0;
// Track total text size.
rect_t Size(Pos.x, Pos.y, 0, 0);
if(!m_loaded || !CFont::s_loaded || text.empty()) return Size;
@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.
@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: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.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 / 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.