dungeon_crawler

annotate prototype/src/colgrade.cc @ 72:a27528035e20

- re-organized the renderer classes a bit wrt final render-target - implemented identity color-grading palette for now - broke particle systems.... - removed multipass renderer
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 19 Oct 2012 02:45:57 +0300
parents
children 5981917093ff
rev   line source
nuclear@72 1 #include <stdio.h>
nuclear@72 2 #include "opengl.h"
nuclear@72 3 #include "colgrade.h"
nuclear@72 4
nuclear@72 5 GradePalette::GradePalette()
nuclear@72 6 {
nuclear@72 7 tex = 0;
nuclear@72 8 }
nuclear@72 9
nuclear@72 10 GradePalette::~GradePalette()
nuclear@72 11 {
nuclear@72 12 destroy();
nuclear@72 13 }
nuclear@72 14
nuclear@72 15 bool GradePalette::create(int sz)
nuclear@72 16 {
nuclear@72 17 unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP;
nuclear@72 18
nuclear@72 19 destroy();
nuclear@72 20
nuclear@72 21 glGenTextures(1, &tex);
nuclear@72 22 glBindTexture(GL_TEXTURE_3D, tex);
nuclear@72 23 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
nuclear@72 24 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
nuclear@72 25 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, clamp);
nuclear@72 26 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, clamp);
nuclear@72 27 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, clamp);
nuclear@72 28 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, sz, sz, sz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
nuclear@72 29
nuclear@72 30 unsigned char *scanline = new unsigned char[sz * 3];
nuclear@72 31
nuclear@72 32 size = sz;
nuclear@72 33 for(int i=0; i<sz; i++) { // for each slice...
nuclear@72 34 int b = 255 * i / (sz - 1);
nuclear@72 35 for(int j=0; j<sz; j++) { // for each scanline...
nuclear@72 36 int g = 255 * j / (sz - 1);
nuclear@72 37
nuclear@72 38 for(int k=0; k<sz; k++) {
nuclear@72 39 int r = 255 * k / (sz - 1);
nuclear@72 40
nuclear@72 41 scanline[k * 3] = r;
nuclear@72 42 scanline[k * 3 + 1] = g;
nuclear@72 43 scanline[k * 3 + 2] = b;
nuclear@72 44 }
nuclear@72 45 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, j, i, sz, 1, 1, GL_RGB,
nuclear@72 46 GL_UNSIGNED_BYTE, scanline);
nuclear@72 47 }
nuclear@72 48 }
nuclear@72 49
nuclear@72 50 delete [] scanline;
nuclear@72 51 return true;
nuclear@72 52 }
nuclear@72 53
nuclear@72 54 void GradePalette::destroy()
nuclear@72 55 {
nuclear@72 56 if(tex) {
nuclear@72 57 glDeleteTextures(1, &tex);
nuclear@72 58 }
nuclear@72 59 }
nuclear@72 60
nuclear@72 61 bool GradePalette::save_shot(const char *fname) const
nuclear@72 62 {
nuclear@72 63 return false; // TODO
nuclear@72 64 }
nuclear@72 65
nuclear@72 66 bool GradePalette::load_shot(const char *fname)
nuclear@72 67 {
nuclear@72 68 return false; // TODO
nuclear@72 69 }
nuclear@72 70
nuclear@72 71 unsigned int GradePalette::get_texture() const
nuclear@72 72 {
nuclear@72 73 return tex;
nuclear@72 74 }