dungeon_crawler

view 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 source
1 #include <stdio.h>
2 #include "opengl.h"
3 #include "colgrade.h"
5 GradePalette::GradePalette()
6 {
7 tex = 0;
8 }
10 GradePalette::~GradePalette()
11 {
12 destroy();
13 }
15 bool GradePalette::create(int sz)
16 {
17 unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP;
19 destroy();
21 glGenTextures(1, &tex);
22 glBindTexture(GL_TEXTURE_3D, tex);
23 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
24 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
25 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, clamp);
26 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, clamp);
27 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, clamp);
28 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, sz, sz, sz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
30 unsigned char *scanline = new unsigned char[sz * 3];
32 size = sz;
33 for(int i=0; i<sz; i++) { // for each slice...
34 int b = 255 * i / (sz - 1);
35 for(int j=0; j<sz; j++) { // for each scanline...
36 int g = 255 * j / (sz - 1);
38 for(int k=0; k<sz; k++) {
39 int r = 255 * k / (sz - 1);
41 scanline[k * 3] = r;
42 scanline[k * 3 + 1] = g;
43 scanline[k * 3 + 2] = b;
44 }
45 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, j, i, sz, 1, 1, GL_RGB,
46 GL_UNSIGNED_BYTE, scanline);
47 }
48 }
50 delete [] scanline;
51 return true;
52 }
54 void GradePalette::destroy()
55 {
56 if(tex) {
57 glDeleteTextures(1, &tex);
58 }
59 }
61 bool GradePalette::save_shot(const char *fname) const
62 {
63 return false; // TODO
64 }
66 bool GradePalette::load_shot(const char *fname)
67 {
68 return false; // TODO
69 }
71 unsigned int GradePalette::get_texture() const
72 {
73 return tex;
74 }