KlassischeKeplerKriege/game/renderer_polygon_3d/renderer_polygon_3d.cpp

62 lines
1.5 KiB
C++
Raw Normal View History

2016-09-28 09:50:35 +00:00
#include "renderer_polygon_3d.hpp"
#include <iostream>
#include "polygon_model.hpp"
2016-09-28 09:50:35 +00:00
namespace endofthejedi {
void RendererPolygon3d::setup()
{
std::cout<<"setup 3d" << std::endl;
2016-09-28 11:38:31 +00:00
m_atomicBomb = new PolygonModel("../data/mesh/small_atomic_bomb.stl");
//m_atomicBomb = new PolygonModel("../data/mesh/quad_screen_coords.stl");
2016-09-28 11:36:22 +00:00
m_atomicBomb->import();
m_atomicBomb->uploadToOpenGl();
m_models.push_back(m_atomicBomb);
2016-09-28 11:36:22 +00:00
std::string vss =
"varying vec3 vertex;\n"
"void main()\n"
"{\n"
" gl_Position = gl_Vertex;\n"
" vertex = gl_Vertex.xyz;\n"
"}\n"
;
std::string fss =
"varying vec3 vertex;\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"
"}\n"
;
m_shader.init();
m_shader.load(vss.c_str(), GL_VERTEX_SHADER);
m_shader.load(fss.c_str(), GL_FRAGMENT_SHADER);
2016-09-28 09:50:35 +00:00
}
void RendererPolygon3d::render(const game::State *state)
{
2016-09-28 11:36:22 +00:00
m_shader.bind();
2016-09-28 09:50:35 +00:00
(void) state;
2016-09-28 11:38:31 +00:00
m_atomicBomb->bind();
m_atomicBomb->render();
2016-09-28 11:36:22 +00:00
2016-09-28 11:38:31 +00:00
//glColor3f(1.0, 0.0, 0.0);
//glBegin(GL_QUADS);
//glVertex2f(-1.0f, -1.0f);
//glVertex2f(1.0f, -1.0f);
//glVertex2f(1.0f, 1.0f);
//glVertex2f(-1.0f, 1.0f);
//glEnd();
//std::cout<<"render 3d" << std::endl;
2016-09-28 09:50:35 +00:00
}
}