nuclear@1: #include "opengl.h" nuclear@1: #include "renderer.h" nuclear@1: nuclear@1: Renderer::Renderer() nuclear@1: { nuclear@1: leveltex = 0; nuclear@1: sdrprog = 0; nuclear@1: } nuclear@1: nuclear@1: Renderer::~Renderer() nuclear@1: { nuclear@1: shutdown(); nuclear@1: } nuclear@1: nuclear@1: bool Renderer::init() nuclear@1: { nuclear@1: sdrprog = new SdrProg; nuclear@1: /*if(!sdrprog->load("sdr/bloboray.v.glsl", "sdr/bloboray.p.glsl")) { nuclear@1: return false; nuclear@1: }*/ nuclear@1: nuclear@1: leveltex = new Texture3D; nuclear@1: nuclear@1: return true; nuclear@1: } nuclear@1: nuclear@1: void Renderer::shutdown() nuclear@1: { nuclear@1: delete leveltex; nuclear@1: delete sdrprog; nuclear@1: } nuclear@1: nuclear@1: static void draw_cube(const Vector3 &pos, float sz); nuclear@1: nuclear@1: void Renderer::render(const Level *lvl) const nuclear@1: { nuclear@1: Volume *vol = lvl->terrain; nuclear@1: nuclear@1: glEnable(GL_COLOR_MATERIAL); nuclear@1: glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); nuclear@1: nuclear@1: glBegin(GL_QUADS); nuclear@1: for(int i=0; iget_size(0); i++) { nuclear@1: for(int j=0; jget_size(1); j++) { nuclear@1: for(int k=0; kget_size(2) - 1; k++) { nuclear@1: Vector4 vox = vol->get_voxel(i, j, k); nuclear@1: Vector4 next = vol->get_voxel(i, j, k + 1); nuclear@1: nuclear@1: if(vox.w > 0.1 && next.w < 0.1) { nuclear@1: glColor3f(vox.x, vox.y, vox.z); nuclear@1: nuclear@1: float x = ((float)i - vol->get_size(0) / 2) * 0.1; nuclear@1: float z = ((float)j - vol->get_size(1) / 2) * 0.1; nuclear@1: float y = ((float)k - vol->get_size(2) / 2) * 0.1; nuclear@1: draw_cube(Vector3(x, y, z), 0.1); nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: } nuclear@1: glEnd(); nuclear@1: nuclear@1: glDisable(GL_COLOR_MATERIAL); nuclear@1: } nuclear@1: nuclear@1: nuclear@1: static void draw_cube(const Vector3 &pos, float sz) nuclear@1: { nuclear@1: sz /= 2.0; nuclear@1: nuclear@1: glNormal3f(0, 0, 1); nuclear@1: glVertex3f(pos.x - sz, pos.y - sz, pos.z + sz); nuclear@1: glVertex3f(pos.x + sz, pos.y - sz, pos.z + sz); nuclear@1: glVertex3f(pos.x + sz, pos.y + sz, pos.z + sz); nuclear@1: glVertex3f(pos.x - sz, pos.y + sz, pos.z + sz); nuclear@1: nuclear@1: glNormal3f(1, 0, 0); nuclear@1: glVertex3f(pos.x + sz, pos.y - sz, pos.z + sz); nuclear@1: glVertex3f(pos.x + sz, pos.y - sz, pos.z - sz); nuclear@1: glVertex3f(pos.x + sz, pos.y + sz, pos.z - sz); nuclear@1: glVertex3f(pos.x + sz, pos.y + sz, pos.z + sz); nuclear@1: nuclear@1: glNormal3f(0, 0, -1); nuclear@1: glVertex3f(pos.x + sz, pos.y - sz, pos.z - sz); nuclear@1: glVertex3f(pos.x - sz, pos.y - sz, pos.z - sz); nuclear@1: glVertex3f(pos.x - sz, pos.y + sz, pos.z - sz); nuclear@1: glVertex3f(pos.x + sz, pos.y + sz, pos.z - sz); nuclear@1: nuclear@1: glNormal3f(-1, 0, 0); nuclear@1: glVertex3f(pos.x - sz, pos.y - sz, pos.z - sz); nuclear@1: glVertex3f(pos.x - sz, pos.y - sz, pos.z + sz); nuclear@1: glVertex3f(pos.x - sz, pos.y + sz, pos.z + sz); nuclear@1: glVertex3f(pos.x - sz, pos.y + sz, pos.z - sz); nuclear@1: nuclear@1: glNormal3f(0, 1, 0); nuclear@1: glVertex3f(pos.x - sz, pos.y + sz, pos.z + sz); nuclear@1: glVertex3f(pos.x + sz, pos.y + sz, pos.z + sz); nuclear@1: glVertex3f(pos.x + sz, pos.y + sz, pos.z - sz); nuclear@1: glVertex3f(pos.x - sz, pos.y + sz, pos.z - sz); nuclear@1: nuclear@1: glNormal3f(0, -1, 0); nuclear@1: glVertex3f(pos.x - sz, pos.y - sz, pos.z - sz); nuclear@1: glVertex3f(pos.x + sz, pos.y - sz, pos.z - sz); nuclear@1: glVertex3f(pos.x + sz, pos.y - sz, pos.z + sz); nuclear@1: glVertex3f(pos.x - sz, pos.y - sz, pos.z + sz); nuclear@1: nuclear@1: }