* fixes, refactoring & color attribute for planets

This commit is contained in:
end 2016-09-29 02:50:51 +02:00
parent 6b8227b0c3
commit 1ee349e1fb
8 changed files with 111 additions and 67 deletions

View file

@ -0,0 +1,11 @@
R"raw_string(
#version 120
varying vec3 vertex;
uniform vec3 color;
void main()
{
//gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
//gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
gl_FragColor = vec4(color, 1.0);
}
)raw_string"

View file

@ -0,0 +1,12 @@
R"raw_string(
#version 120
varying vec3 vertex;
uniform mat4 model;
void main()
{
//vec3 p = position + scale*gl_Vertex.xyz;
vec3 p = (model*gl_Vertex).xyz;
gl_Position = vec4(p, 1.0);
vertex = p.xyz;
}
)raw_string"

View file

@ -38,59 +38,31 @@ namespace endofthejedi {
m_particles->upload(); m_particles->upload();
std::string vss_simple = std::string vss_simple =
"#version 120\n" #include "simple.vert"
"varying vec3 vertex;\n"
"void main()\n"
"{\n"
" gl_Position = gl_Vertex;\n"
" vertex = gl_Position.xyz;\n"
"}\n"
; ;
std::string fss_simple = std::string fss_simple =
"#version 120\n" #include "simple.frag"
"varying vec3 vertex;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);\n"
"}\n"
; ;
std::string vss_game_objects = std::string vss_game_objects =
"#version 120\n" #include "gameobjects.vert"
"varying vec3 vertex;\n"
"uniform mat4 model;\n"
"void main()\n"
"{\n"
//" vec3 p = position + scale*gl_Vertex.xyz;\n"
" vec3 p = (model*gl_Vertex).xyz;\n"
" gl_Position = vec4(p, 1.0);\n"
" vertex = p.xyz;\n"
"}\n"
; ;
std::string fss_game_objects = std::string fss_game_objects =
"#version 120\n" #include "gameobjects.frag"
"varying vec3 vertex;\n"
"uniform vec3 color;\n"
"void main()\n"
"{\n"
//" gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
//" gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);\n"
" gl_FragColor = vec4(color, 1.0);\n"
"}\n"
; ;
m_shader.init(); m_shader.init();
#if 0 #if 0
(void) vss_game_objects; (void) vss_simple;
(void) fss_game_objects; (void) fss_simple;
m_shader.load(vss_simple.c_str(), GL_VERTEX_SHADER); m_shader.load(vss_simple.c_str(), GL_VERTEX_SHADER);
m_shader.load(fss_simple.c_str(), GL_FRAGMENT_SHADER); m_shader.load(fss_simple.c_str(), GL_FRAGMENT_SHADER);
#else #else
(void) vss_simple; (void) vss_game_objects;
(void) fss_simple; (void) fss_game_objects;
m_shader.load(vss_game_objects.c_str(), GL_VERTEX_SHADER); m_shader.load(vss_game_objects.c_str(), GL_VERTEX_SHADER);
m_shader.load(fss_game_objects.c_str(), GL_FRAGMENT_SHADER); m_shader.load(fss_game_objects.c_str(), GL_FRAGMENT_SHADER);
#endif #endif
@ -135,8 +107,8 @@ namespace endofthejedi {
glm::mat4 model = computeModelMatrix(planet); glm::mat4 model = computeModelMatrix(planet);
glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model));
glm::vec3 c = glm::vec3(0.7, 0.2, 0.1); glm::vec3 c = planet->getColor();
glUniform3f(m_shader.location("color"), c.x, c.y, c.z); glUniform3f(m_shader.location("color"), c.x, c.y, c.z);
m_planetModel->render(); m_planetModel->render();
} }

View file

@ -0,0 +1,8 @@
R"raw_string(
#version 120
varying vec3 vertex;
void main()
{
gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
}
)raw_string"

View file

@ -0,0 +1,9 @@
R"raw_string(
#version 120
varying vec3 vertex;
void main()
{
gl_Position = gl_Vertex;
vertex = gl_Position.xyz;
}
)raw_string"

View file

@ -0,0 +1,11 @@
R"raw_string(
#version 120
varying vec3 vertex;
uniform vec3 color;
void main()
{
//gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
//gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
gl_FragColor = vec4(color, 1.0);
}
)raw_string"

View file

@ -0,0 +1,14 @@
R"raw_string(
#version 120
varying vec3 vertex;
uniform mat4 model;
void main()
{
//vec3 p = position + scale*gl_Vertex.xyz;
vec3 p = (model*gl_Vertex).xyz;
gl_Position = vec4(p, 1.0);
vertex = p.xyz;
}
)raw_string"

View file

@ -5,36 +5,43 @@
#include <cstdlib> #include <cstdlib>
namespace game { namespace game {
class Planet : public Object { class Planet : public Object {
public: public:
/** /**
* Planets are build out of one material. * Planets are build out of one material.
* TODO: support mixture or multiple material per planet. * TODO: support mixture or multiple material per planet.
*/ */
enum class Material { enum class Material { Rock, Metal, Sand, Gas, Ice, Water, Sun };
Rock,
Metal,
Sand,
Gas,
Ice,
Water,
Sun
};
Planet(const glm::vec2 &pos, int id, float r) : Planet(pos, id, r, Material::Rock) Planet(const glm::vec2 &pos, int id, float r)
{ : Planet(pos, id, r, Material::Rock) {}
Planet(const glm::vec2 &pos, int id, float r, Material mat)
: Object(pos, r), id(id), material(mat), seed(rand()) {}
glm::vec3 getColor() const {
switch (material) {
case Material::Rock:
return {x : 0.19, y : 0.19, z : 0.19};
case Material::Metal:
return {x : 0.19, y : 0.19, z : 0.19};
case Material::Sand:
return {x : 0.19, y : 0.19, z : 0.19};
case Material::Gas:
return {x : 0.19, y : 0.19, z : 0.19};
case Material::Ice:
return {x : 0.19, y : 0.19, z : 0.19};
case Material::Water:
return {x : 0.19, y : 0.40, z : 0.72};
case Material::Sun:
return {x : 0.64, y : 0.67, z : 0.19};
} }
return {x : 0.1, y : 0.1, z : 0.1};
}
Planet(const glm::vec2 &pos, int id, float r, Material mat) int id;
: Object(pos, r) Material material; // for rendering and physics (can fly through sun and
, id(id) // outer gas planets)
, material(mat) int seed; // just for rendering variation
, seed(rand()) };
{
}
int id;
Material material; // for rendering and physics (can fly through sun and outer gas planets)
int seed; // just for rendering variation
};
} }