Skip to content

Instantly share code, notes, and snippets.

@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 / 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();
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 / 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:
/**
@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 / Shadows.cpp
Created October 1, 2012 01:46
Render shadows in OpenGL
void RenderShadows(const math::CVector2& LightPos),
const std::vector<Object*>& shadowCastingObjects)
{
// Set up rendering modes
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_BLEND);
glColor4f(0.3f, 0.3f, 0.3f, 1.0f); // Dark gray
@Shaptic
Shaptic / Shadows.cpp
Created September 30, 2012 01:21
Render shadows in OpenGL
void RenderShadows(const math::CVector2& LightPos),
const std::vector<Object*>& shadowCastingObjects)
{
// Set up rendering modes
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_BLEND);
glColor4f(0.3f, 0.3f, 0.3f, 1.0f); // Dark gray
@Shaptic
Shaptic / RayCollision.cpp
Created September 27, 2012 22:54
Checks whether two line-segments interset.
/**
* Checks for intersection with another line segment. Touching at
* endpoints qualifies as intersections.
*
* @param math::CRay2 The other line
*
* @return TRUE if they intersect, FALSE otherwise.
* @see http://gamedev.stackexchange.com/questions/26004/how-to-detect-2d-line-on-line-collision
**/
bool CRay2::CheckCollision(const CRay2& Other, math::CVector2* p_Intersection) const
@Shaptic
Shaptic / Lighting.c
Created September 21, 2012 23:33
Collapse point-lighting fragment shader
/**
* @file
* Fragment shader for lighting.
* Per-pixel point light lighting is done in this shader.
*
* @author George Kudrayvtsev (switch1440)
* @version 1.0
* @copyright Apache License v2.0
* Licensed under the Apache License, Version 2.0 (the "License").\n
* You may not use this file except in compliance with the License.\n
@Shaptic
Shaptic / Lighting.c
Created September 21, 2012 23:32
Collapse point-lighting fragment shader
/**
* @file
* Fragment shader for lighting.
* Per-pixel point light lighting is done in this shader.
*
* @author George Kudrayvtsev (switch1440)
* @version 1.0
* @copyright Apache License v2.0
* Licensed under the Apache License, Version 2.0 (the "License").\n
* You may not use this file except in compliance with the License.\n