Morph-SynRJ
view cmn_intro.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 "cmn_intro.h"
2 #include <windows.h>
3 #include <GL/gl.h>
4 #include <GL/glu.h>
5 #include "cmn_texture.h"
7 // DBUG TIME (Console)
8 #ifdef SOTA_DEBUG_MODE
9 HANDLE stdOut;
11 #include <string.h>
12 void Write2Console(const char * data )
13 {
14 WriteConsole( stdOut, data, strlen( data ), NULL, NULL );
15 WriteConsole( stdOut, "\n", 1, NULL, NULL );
16 }
17 #endif
20 void cmnClearScreen(float r,float g,float b,float a)
21 {
22 glClearColor(r,g,b,a);
23 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
24 }
27 void cmnSetFrustrum(float _fov,float _zmin,float _zmax)
28 {
29 glMatrixMode(GL_PROJECTION);
30 glLoadIdentity();
31 gluPerspective(_fov,800/600,_zmin,_zmax);
32 }
35 void cmnSetCamera(const mth::Vector3_t& _position,const mth::Vector3_t& _lookat,const mth::Vector3_t& up)
36 {
37 glMatrixMode(GL_MODELVIEW);
38 glLoadIdentity();
39 gluLookAt(_position[0],_position[1],_position[2],_lookat[0],_lookat[1],_lookat[2],up[0],up[1],up[2]);
41 }
44 #ifndef FINAL_RELEASE
45 static int cmnPushStateValue=0;
46 void cmnPushGLState()
47 {
48 glPushAttrib(GL_ALL_ATTRIB_BITS);
49 cmnPushStateValue++;
50 }
53 void cmnPopGLState()
54 {
55 glPopAttrib();
56 cmnPushStateValue--;
57 SYS_ASSERT(cmnPushStateValue>=0);
58 }
61 #endif
66 static double cmnTimerGetTime()
67 {
68 static double SCALE_COUNTER=-1;
70 if (SCALE_COUNTER==-1.0) {
71 LARGE_INTEGER pc;
73 if(!QueryPerformanceFrequency((LARGE_INTEGER *)&pc)) {
74 SYS_ASSERT(0 && "No freqency !!!\n");
75 }
77 SCALE_COUNTER=1.0/((double)pc.QuadPart);
79 }
80 //unsigned int perf_cnt = pc.QuadPart;
82 //double scale_time = 1.0 / perf_cnt;
83 LARGE_INTEGER ct;
84 double count;
85 if(!QueryPerformanceCounter((LARGE_INTEGER *) &ct)) {
86 SYS_ASSERT(0 && "No timer !!!\n");
87 return 1;
88 }
89 count=(double)ct.QuadPart;
90 count*=SCALE_COUNTER;
91 return count;
92 }
96 void cmnTimer_t::Init()
97 {
98 startTime=cmnTimerGetTime();
99 currentTime=0;
100 frameTime=0;
101 }
104 double cmnTimer_t::GetRealTime()
105 {
106 return currentTime; //cmnTimerGetTime()-startTime;
107 }
110 double cmnTimer_t::GetFrameTime()
111 {
112 return frameTime;
113 }
115 void cmnTimer_t::Update()
116 {
117 double tmp=cmnTimerGetTime()-startTime; //GetRealTime();
118 frameTime=tmp-currentTime;
119 currentTime=tmp;
120 }
123 void cmnPushMatrix()
124 {
125 glMatrixMode(GL_PROJECTION);
126 glPushMatrix();
128 glMatrixMode(GL_MODELVIEW);
129 glPushMatrix();
130 }
132 void cmnPopMatrix()
133 {
134 glMatrixMode(GL_MODELVIEW);
135 glPopMatrix();
137 glMatrixMode(GL_PROJECTION);
138 glPopMatrix();
139 }
142 void cmnSetPlanarView()
143 {
144 glMatrixMode(GL_PROJECTION);
145 glLoadIdentity();
146 glOrtho(0,RX,0,RY,-100,100);
147 glMatrixMode(GL_MODELVIEW);
148 glLoadIdentity();
149 }
152 void cmnScope(unsigned char alpha, float trans)
153 {
154 glEnable(GL_BLEND);
155 glBlendFunc(GL_ONE, GL_SRC_ALPHA);
157 glColor4ub(0, 0, 0, alpha);
159 cmnPushMatrix();
160 glMatrixMode(GL_PROJECTION);
161 glLoadIdentity();
162 glMatrixMode(GL_MODELVIEW);
163 glLoadIdentity();
165 glBegin(GL_QUADS);
166 glVertex2f(-1.f, -1.f);
167 glVertex2f(-1.f, -trans);
168 glVertex2f(1.f, -trans);
169 glVertex2f(1.f, -1.f);
170 glEnd();
172 glBegin(GL_QUADS);
173 glVertex2f(-1.f, trans);
174 glVertex2f(-1.f, 1.f);
175 glVertex2f(1.f, 1.f);
176 glVertex2f(1.f, trans);
177 glEnd();
180 cmnPopMatrix();
181 glDisable(GL_BLEND);
183 }
185 void cmnDisplayBackground(GLuint _texture,int _r,int _g,int _b,int _a, int _nbPasses,int _side)
186 {
187 cmnPushMatrix();
188 cmnPushGLState();
190 glMatrixMode(GL_PROJECTION);
191 glLoadIdentity();
193 glMatrixMode(GL_MODELVIEW);
194 glLoadIdentity();
196 glDisable(GL_DEPTH_TEST);
197 glShadeModel(GL_SMOOTH);
199 // glEnable(GL_BLEND);
200 // glBlendFunc(GL_ONE,GL_ONE);
202 txtBindTexture2d(_texture,0);
203 glBegin(GL_QUADS);
205 for (int i=0;i<_nbPasses;i++) {
207 glColor4ub(0,0,0,0);
208 glTexCoord2f(0,0);
209 glVertex3f(-1,1,0);
211 if (_side)
212 glColor4ub(0,0,0,0);
213 else
214 glColor4ub(_r,_g,_b,_a);
215 glTexCoord2f(1,0);
216 glVertex3f(1,1,0);
218 glColor4ub(_r,_g,_b,_a);
219 glTexCoord2f(1,1);
220 glVertex3f(1,-1,0);
222 if (_side)
223 glColor4ub(0,0,0,0);
224 else
225 glColor4ub(_r,_g,_b,_a);
226 glTexCoord2f(0,1);
227 glVertex3f(-1,-1,0);
228 }
230 glEnd();
232 cmnPopGLState();
234 // txtUnBindTexture2d(0);
235 // glEnable(GL_DEPTH_TEST);
237 cmnPopMatrix();
238 glMatrixMode(GL_MODELVIEW);
239 }
