merged
This commit is contained in:
commit
c06e138b3e
14 changed files with 48 additions and 60 deletions
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
|
||||
varying vec3 vertex;
|
||||
|
@ -42,4 +41,3 @@ void main()
|
|||
gl_FragColor = vec4((IAmbient + IDiffuse) + ISpecular, 1.0);
|
||||
//gl_FragColor = vec4(0.5+0.5*normal, 1.0);
|
||||
}
|
||||
)raw_string"
|
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
|
||||
attribute vec3 in_vertex;
|
||||
|
@ -22,4 +21,3 @@ void main()
|
|||
|
||||
gl_Position = vec4(p, 1.0);
|
||||
}
|
||||
)raw_string"
|
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
varying vec2 vertex;
|
||||
varying vec2 velocity;
|
||||
|
@ -15,4 +14,3 @@ void main()
|
|||
// (length(10.0*velocity));
|
||||
gl_FragColor = vec4(1.0/max(1.0, decay), 1.0/max(1.0, 6.0*decay), 0.0, 1.0);
|
||||
}
|
||||
)raw_string"
|
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
attribute vec2 in_vertex;
|
||||
attribute vec2 in_position;
|
||||
|
@ -17,4 +16,3 @@ void main()
|
|||
vertex = in_vertex;
|
||||
velocity = in_velocity;
|
||||
}
|
||||
)raw_string"
|
|
@ -1,8 +1,6 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
varying vec3 vertex;
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
|
||||
}
|
||||
)raw_string"
|
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
varying vec3 vertex;
|
||||
void main()
|
||||
|
@ -6,4 +5,3 @@ void main()
|
|||
gl_Position = gl_Vertex;
|
||||
vertex = gl_Position.xyz;
|
||||
}
|
||||
)raw_string"
|
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
varying vec3 vertex;
|
||||
uniform vec3 color;
|
||||
|
@ -8,4 +7,3 @@ void main()
|
|||
//gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
||||
)raw_string"
|
|
@ -1,4 +1,3 @@
|
|||
R"raw_string(
|
||||
#version 120
|
||||
varying vec3 vertex;
|
||||
uniform mat4 model;
|
||||
|
@ -11,4 +10,3 @@ void main()
|
|||
gl_Position = vec4(p, 1.0);
|
||||
vertex = p.xyz;
|
||||
}
|
||||
)raw_string"
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace endofthejedi {
|
||||
VAO::VAO() { glGenVertexArrays(1, &m_name); }
|
||||
|
@ -80,7 +82,7 @@ namespace endofthejedi {
|
|||
|
||||
void Shader::unbind() { glUseProgram(0); }
|
||||
|
||||
void Shader::load(const std::string &path, GLenum shadertype) {
|
||||
void Shader::load(const std::string &data, GLenum shadertype) {
|
||||
if (m_program == 0) {
|
||||
std::cout<<"[shader] error: shader program is invalid (0)!" << std::endl;
|
||||
exit(-1);
|
||||
|
@ -89,7 +91,7 @@ namespace endofthejedi {
|
|||
|
||||
GLuint shader = glCreateShader(shadertype);
|
||||
|
||||
const char *shaderdata = path.c_str();
|
||||
const char *shaderdata = data.c_str();
|
||||
glShaderSource(shader, 1, &shaderdata, NULL);
|
||||
glCompileShader(shader);
|
||||
checkShader(shader);
|
||||
|
@ -101,6 +103,25 @@ namespace endofthejedi {
|
|||
glDeleteShader(shader);
|
||||
}
|
||||
|
||||
void Shader::loadFile(const std::string &path, GLenum shadertype) {
|
||||
std::string content;
|
||||
std::ifstream fileStream(path, std::ios::in);
|
||||
|
||||
if(!fileStream.is_open()) {
|
||||
std::cerr << "Could not read file " << path << ". File does not exist." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string line = "";
|
||||
while(!fileStream.eof()) {
|
||||
std::getline(fileStream, line);
|
||||
content.append(line + "\n");
|
||||
}
|
||||
|
||||
fileStream.close();
|
||||
load(content, shadertype);
|
||||
}
|
||||
|
||||
GLuint Shader::location(const std::string &name) {
|
||||
return glGetUniformLocation(m_program, name.c_str());
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ class Shader {
|
|||
void bind();
|
||||
void unbind();
|
||||
void load(const std::string &data, GLenum shadertype);
|
||||
void loadFile(const std::string& data, GLenum shadertype);
|
||||
GLuint location(const std::string &name);
|
||||
GLuint program();
|
||||
};
|
||||
|
|
|
@ -30,17 +30,12 @@ namespace endofthejedi {
|
|||
m_data_kind.resize(m_numParticles);
|
||||
m_data_max_age.resize(m_numParticles);
|
||||
|
||||
std::string vss_particles =
|
||||
#include "particle.vert"
|
||||
;
|
||||
|
||||
std::string fss_particles =
|
||||
#include "particle.frag"
|
||||
;
|
||||
std::string vss_particles = "../data/shader/particle.vert";
|
||||
std::string fss_particles = "../data/shader/particle.frag";
|
||||
|
||||
m_shader.init();
|
||||
m_shader.load(vss_particles.c_str(), GL_VERTEX_SHADER);
|
||||
m_shader.load(fss_particles.c_str(), GL_FRAGMENT_SHADER);
|
||||
m_shader.loadFile(vss_particles, GL_VERTEX_SHADER);
|
||||
m_shader.loadFile(fss_particles, GL_FRAGMENT_SHADER);
|
||||
}
|
||||
|
||||
ParticleBatch::~ParticleBatch()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "polygon_model.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void discardLastGlError()
|
||||
{
|
||||
glGetError();
|
||||
|
@ -22,6 +24,7 @@ void checkAndPrintGlError()
|
|||
std::cout<<"glGetAttribLocation() returned error: " << errString << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
namespace endofthejedi {
|
||||
PolygonModel::PolygonModel(const std::string &filename)
|
||||
: m_filename(filename)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <assimp/Importer.hpp> // C++ importer interface
|
||||
#include <assimp/scene.h> // Output data structure
|
||||
|
|
|
@ -13,34 +13,18 @@ namespace endofthejedi {
|
|||
|
||||
std::cout<<"setup polygon 3d" << std::endl;
|
||||
|
||||
std::string vss_simple =
|
||||
#include "simple.vert"
|
||||
;
|
||||
|
||||
std::string fss_simple =
|
||||
#include "simple.frag"
|
||||
;
|
||||
|
||||
std::string vss_game_objects =
|
||||
#include "gameobjects.vert"
|
||||
;
|
||||
|
||||
std::string fss_game_objects =
|
||||
#include "gameobjects.frag"
|
||||
;
|
||||
|
||||
m_shader.init();
|
||||
|
||||
#if 0
|
||||
(void) vss_simple;
|
||||
(void) fss_simple;
|
||||
m_shader.load(vss_simple.c_str(), GL_VERTEX_SHADER);
|
||||
m_shader.load(fss_simple.c_str(), GL_FRAGMENT_SHADER);
|
||||
std::string vss_simple = "../data/shader/simple.vert";
|
||||
std::string fss_simple = "../data/shader/simple.frag";
|
||||
m_shader.loadFile(vss_simple, GL_VERTEX_SHADER);
|
||||
m_shader.loadFile(fss_simple, GL_FRAGMENT_SHADER);
|
||||
#else
|
||||
(void) vss_game_objects;
|
||||
(void) fss_game_objects;
|
||||
m_shader.load(vss_game_objects.c_str(), GL_VERTEX_SHADER);
|
||||
m_shader.load(fss_game_objects.c_str(), GL_FRAGMENT_SHADER);
|
||||
std::string vss_game_objects = "../data/shader/gameobjects.vert";
|
||||
std::string fss_game_objects = "../data/shader/gameobjects.frag";
|
||||
m_shader.loadFile(vss_game_objects, GL_VERTEX_SHADER);
|
||||
m_shader.loadFile(fss_game_objects, GL_FRAGMENT_SHADER);
|
||||
#endif
|
||||
|
||||
addModel("../data/mesh/small_atomic_bomb.stl", &m_missileModel);
|
||||
|
|
Loading…
Reference in a new issue