Skip to content

Instantly share code, notes, and snippets.

#include "Owl.hpp"
Owl owlInstance;
Owl::Owl()
{
this->b_init = false;
}
Owl::~Owl()
@pingpoli
pingpoli / Owl.hpp
Last active September 5, 2020 10:32
#pragma once
#include <fstream>
#include <iostream>
#include <string>
#include "timeutil.hpp"
#include "util.hpp"
class Owl;
extern Owl owlInstance;
#include "SimpleParticles.hpp"
/*
emitter
*/
#pragma once
#include "Z:/cpp/SRC/lgl3/include/lgl3_includes.hpp"
#include "Z:/cpp/SRC/lgl3/include/lglShader.hpp"
/*
emitter
*/
void SimpleEmitter::draw()
{
glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 4 );
// update the position buffer
glBindBuffer( GL_ARRAY_BUFFER , this->positionBuffer );
glBufferSubData( GL_ARRAY_BUFFER , 0 , this->particles.size()*4*sizeof(float) , this->positions );
// vertex buffer
void SimpleEmitter::update( const float dt )
{
for ( uint i = 0 ; i < this->particles.size() ; ++i )
{
// subtract from the particles lifetime
this->particles[i].lifetime -= dt;
// if the lifetime is below 0 respawn the particle
if ( this->particles[i].lifetime <= 0.0f )
{
SimpleEmitter::SimpleEmitter()
{
// create 100 particles
this->particles.resize( 100 );
for ( uint i = 0 ; i < this->particles.size() ; ++i )
{
// give every particle a random position
this->particles[i].position = lstd_random_between( vec3( -1.0f ) , vec3( 1.0f ) );
this->particles[i].lifetime = lstd_random_between( 1.0f , 2.0f );
}
const std::string SimpleParticleShader::VS = "#version 330 core\n"
"layout ( location = 0 ) in vec3 vertex_position;"
"layout ( location = 4 ) in vec4 position;"
"uniform mat4 M_v;"
"uniform mat4 M_p;"
"uniform float particleSize;"
"out float lifetime;"
"void main()"
"{"
" vec4 position_viewspace = M_v * vec4( position.xyz , 1 );"
#version 330 core
in vec2 uv;
uniform sampler2D sampler;
uniform float desaturationFactor;
out vec4 fragColor;
void main()
{
vec3 color = texture2D( sampler , uv ).rgb;
vec3 gray = vec3( dot( color , vec3( 0.2126 , 0.7152 , 0.0722 ) ) );
fragColor = vec4( mix( color , gray , desaturationFactor ) , 1.0 );
#version 330 core
layout ( location = 0 ) in vec2 vertex_position;
layout ( location = 2 ) in vec2 vertex_uv;
uniform mat4 M_mvp;
out vec2 uv;
void main()
{
gl_Position = M_mvp * vec4( vertex_position , 0.0 , 1.0 );
uv = vertex_uv;
}