Morph-SynRJ
view trans_glow.cxx @ 0:22de913c2d84
morph-synrj intro
| author | "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>" |
|---|---|
| date | Tue Nov 27 15:23:52 2007 +0100 (2007-11-27) |
| parents | |
| children |
line source
1 #include "trans_glow.h"
2 #include "gl_header.h"
3 #include "cmn_intro.h"
5 GLuint trans_Glow_t::CreateOnePass(int x, int y)
6 {
7 GLuint txtnumber;
8 unsigned char *data;
10 glEnable(GL_TEXTURE_2D);
12 data = (unsigned char *)new GLuint[((x * y)*4*sizeof(unsigned int))];
14 glGenTextures(1, &txtnumber);
15 glBindTexture(GL_TEXTURE_2D, txtnumber);
16 glTexImage2D(GL_TEXTURE_2D, 0, 4, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
17 #ifdef USE_MOZAIK
18 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
19 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
20 #else
21 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
22 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
23 #endif
24 delete [] data;
26 return txtnumber;
27 }
29 void trans_Glow_t::RenderSceneToQuad(GLuint dst, float alpha)
30 {
31 glEnable(GL_TEXTURE_2D);
32 glBindTexture(GL_TEXTURE_2D, dst);
34 glLoadIdentity();
36 glEnable(GL_BLEND);
37 glDepthMask(false);
39 glColor4f( 1, 1, 1, alpha);
41 glBegin(GL_QUADS);
42 glTexCoord2f(0.f, 0.f); glVertex3f(-1.f, -1.f, 0.f);
43 glTexCoord2f(0.f, 1.f); glVertex3f(-1.f, 1.f, 0.f);
44 glTexCoord2f(1.f, 1.f); glVertex3f(1.f, 1.f, 0.f);
45 glTexCoord2f(1.f, 0.f); glVertex3f(1.f, -1.f, 0.f);
46 glEnd();
48 glDepthMask(true);
49 }
51 void trans_Glow_t::StartGlow(void)
52 {
53 glMatrixMode(GL_MODELVIEW);
54 glLoadIdentity();
56 glMatrixMode(GL_PROJECTION);
57 glLoadIdentity();
59 gluPerspective(90.f,1.33333f,1.f,5000.0f);
61 glDisable(GL_LIGHTING);
63 glViewport(0, 0, 32, 32);
64 }
66 void trans_Glow_t::EndGlow(void)
67 {
68 glMatrixMode(GL_MODELVIEW);
69 glLoadIdentity();
71 glMatrixMode(GL_PROJECTION);
72 glLoadIdentity();
74 glViewport(0, 0, RX, RY);
76 glEnable(GL_LIGHTING);
77 }
79 void trans_Glow_t::StartRendering(GLuint dst, int x, int y)
80 {
81 glEnable(GL_TEXTURE_2D);
82 glBindTexture(GL_TEXTURE_2D, dst);
84 #ifdef USE_MOZAIK
85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
87 #else
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
90 #endif
91 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, x, y, 0);
93 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
94 glDisable(GL_TEXTURE_2D);
95 }
97 void trans_Glow_t::AddPass(GLuint src, GLuint dst, int render_size_x, int render_size_y)
98 {
99 glViewport(0, 0, render_size_x, render_size_y);
101 glPushMatrix();
103 glDisable(GL_CULL_FACE);
104 RenderSceneToQuad(src, 1.f);
105 glEnable(GL_CULL_FACE);
107 glPopMatrix();
109 glEnable(GL_TEXTURE_2D);
110 glBindTexture(GL_TEXTURE_2D,dst);
112 #ifdef USE_MOZAIK
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
115 #else
116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
117 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
118 #endif
119 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, render_size_x, render_size_y, 0);
121 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
122 glDisable(GL_TEXTURE_2D);
123 }
125 void trans_Glow_t::DoAllDefaultPasses(void)
126 {
127 glDisable(GL_LIGHTING);
129 AddPass(glowPass[0], glowPass[1], 64, 64);
130 AddPass(glowPass[1], glowPass[2], 128, 128);
131 AddPass(glowPass[2], glowPass[3], 256, 256);
133 glEnable(GL_LIGHTING);
134 }
136 void trans_Glow_t::ApplyGlowToScene(GLuint last_glow_pass, float alpha)
137 {
138 glDisable(GL_CULL_FACE);
139 glDisable(GL_LIGHTING);
140 glEnable(GL_BLEND);
141 glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
142 // glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
143 // glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR);
144 // glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_DST_ALPHA);
146 glDisable(GL_CULL_FACE);
147 RenderSceneToQuad(last_glow_pass, alpha);
148 glEnable(GL_CULL_FACE);
150 glDisable(GL_BLEND);
151 glEnable(GL_LIGHTING);
152 }
