dungeon_crawler
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/prototype/src/colgrade.cc Fri Oct 19 02:45:57 2012 +0300 1.3 @@ -0,0 +1,74 @@ 1.4 +#include <stdio.h> 1.5 +#include "opengl.h" 1.6 +#include "colgrade.h" 1.7 + 1.8 +GradePalette::GradePalette() 1.9 +{ 1.10 + tex = 0; 1.11 +} 1.12 + 1.13 +GradePalette::~GradePalette() 1.14 +{ 1.15 + destroy(); 1.16 +} 1.17 + 1.18 +bool GradePalette::create(int sz) 1.19 +{ 1.20 + unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP; 1.21 + 1.22 + destroy(); 1.23 + 1.24 + glGenTextures(1, &tex); 1.25 + glBindTexture(GL_TEXTURE_3D, tex); 1.26 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.27 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.28 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, clamp); 1.29 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, clamp); 1.30 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, clamp); 1.31 + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, sz, sz, sz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 1.32 + 1.33 + unsigned char *scanline = new unsigned char[sz * 3]; 1.34 + 1.35 + size = sz; 1.36 + for(int i=0; i<sz; i++) { // for each slice... 1.37 + int b = 255 * i / (sz - 1); 1.38 + for(int j=0; j<sz; j++) { // for each scanline... 1.39 + int g = 255 * j / (sz - 1); 1.40 + 1.41 + for(int k=0; k<sz; k++) { 1.42 + int r = 255 * k / (sz - 1); 1.43 + 1.44 + scanline[k * 3] = r; 1.45 + scanline[k * 3 + 1] = g; 1.46 + scanline[k * 3 + 2] = b; 1.47 + } 1.48 + glTexSubImage3D(GL_TEXTURE_3D, 0, 0, j, i, sz, 1, 1, GL_RGB, 1.49 + GL_UNSIGNED_BYTE, scanline); 1.50 + } 1.51 + } 1.52 + 1.53 + delete [] scanline; 1.54 + return true; 1.55 +} 1.56 + 1.57 +void GradePalette::destroy() 1.58 +{ 1.59 + if(tex) { 1.60 + glDeleteTextures(1, &tex); 1.61 + } 1.62 +} 1.63 + 1.64 +bool GradePalette::save_shot(const char *fname) const 1.65 +{ 1.66 + return false; // TODO 1.67 +} 1.68 + 1.69 +bool GradePalette::load_shot(const char *fname) 1.70 +{ 1.71 + return false; // TODO 1.72 +} 1.73 + 1.74 +unsigned int GradePalette::get_texture() const 1.75 +{ 1.76 + return tex; 1.77 +}