-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawOGL.cpp
340 lines (286 loc) · 11.1 KB
/
DrawOGL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//---------------------------------------------------------------------------
#pragma hdrstop
#include "DrawOGL.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
// OpenGL OpenGL OpenGL OpenGL OpenGL OpenGL OpenGL OpenGL
//---------------------------------------------------------------------------
//double OffsetVaweGL = -1.0 ;
static HGLRC ghRC = 0 ;
static HDC ghDC = 0 ;
static HWND HandleGL = 0 ;
#define GRID 1
#define WAVE 2
#define CNL_1 11
#define CNL_2 12
#define CNL_3 13
#define CNL_4 14
#define SHP_OGL 20
#define CUR_OGL 30
//---------------------------------------------------------------------------
BOOL bSetupPixelFormat(HDC hdc) ;
//---------------------------------------------------------------------------
GLvoid DrawCursorsGL(TDsoCursor* Cur[],int CntCur)
{uint32_t lstGL = CUR_OGL ;
if(TDsoCursor::flChng){ TDsoCursor::flChng = false ;
if(glIsList(lstGL)) glDeleteLists(lstGL,1) ;
glNewList(lstGL,GL_COMPILE) ;{
// glLineWidth(2) ;
glLineStipple(4,0xAAAA) ;//1,0x3F07) ;
glEnable(GL_LINE_STIPPLE) ;
for(int is=0;is<CntCur;is++) Cur[is]->DrawGL() ;
glDisable(GL_LINE_STIPPLE) ;
// glLineWidth(1) ;
} glEndList() ;
}
}
//---------------------------------------------------------------------------
GLvoid DrawShapesGL(TShapeGL* shp[],int CntShp)
{uint32_t lstGL = SHP_OGL ;
if(TShapeGL::flChng){ TShapeGL::flChng = false ;
if(glIsList(lstGL)) glDeleteLists(lstGL,1) ;
glNewList(lstGL,GL_COMPILE) ;{
for(int is=0;is<CntShp;is++) shp[is]->DrawGL() ;
}glEndList() ;
}
}
//---------------------------------------------------------------------------
GLvoid DrawWaveGL_M(TParamsDrawWave* prms)
{
uint32_t ix, lstGL = CNL_1 + prms->nCh ;
// if(glIsList(lst)) glDeleteLists(lst,1) ;
// êîë-âî îòñ÷¸òîâ â ViewOGL
double stpX = prms->StpOGL ;// øàã ïî ãîðèçîíòàëè
double stpY = 2.0 / 256.0 ;// Øàã ïî âåðòèêàëè
double ofst = prms->Offset_H ;
ULONG ixArr = prms->IxArr ;
// int cntArr = prms->CntArr ;
// short* pSrcData = prms->pSrcData ;
if(!prms->pSrcData || !prms->ChEnbl) return ;
glNewList(lstGL,GL_COMPILE) ;{
glLineWidth(1) ;
glBegin(GL_LINE_STRIP) ;{
glColorT(prms->clrRGB) ;
if(prms->CHMode == 4) // Q: four channel mode
for(ix=0;ix<prms->nSrcDataLen;ix++){
glVertex2f((ix * stpX + ofst),prms->pSrcData[ixArr][ix] * stpY-1.0) ;
}
else if(prms->CHMode == 2) // D: dual channel mode
for(ix=0;ix<prms->nSrcDataLen;ix++){
if(!prms->flDbg2){
glVertex2f(( 2*ix * stpX + ofst),prms->pSrcData[ixArr+0][ix] * stpY-1.0) ;
glVertex2f(((2*ix+1) * stpX + ofst),prms->pSrcData[ixArr+1][ix] * stpY-1.0) ;}
else{
glVertex2f(( 2*ix * stpX + ofst),prms->pSrcData[ixArr+1][ix] * stpY-1.0) ;
glVertex2f(((2*ix+1) * stpX + ofst),prms->pSrcData[ixArr+0][ix] * stpY-1.0) ;}
}
else if(prms->CHMode == 1) // S: single channel mode
for(ix=0;ix<prms->nSrcDataLen;ix++){
glVertex2f(( 4*ix * stpX + ofst),prms->pSrcData[ixArr ][ix] * stpY-1.0) ;
glVertex2f(((4*ix+1) * stpX + ofst),prms->pSrcData[ixArr+1][ix] * stpY-1.0) ;
glVertex2f(((4*ix+2) * stpX + ofst),prms->pSrcData[ixArr+2][ix] * stpY-1.0) ;
glVertex2f(((4*ix+3) * stpX + ofst),prms->pSrcData[ixArr+3][ix] * stpY-1.0) ;
}
} glEnd() ;
}glEndList() ;
}
//---------------------------------------------------------------------------
GLvoid DrawWaveGL_D(TParamsDrawWave* prms)
{
uint32_t ix, lstGL = CNL_1 + prms->nCh ;
// if(glIsList(lst)) glDeleteLists(lst,1) ;
TColor clr[4] = {clBlue,clRed,clGreen,clPurple};
// êîë-âî îòñ÷¸òîâ â ViewOGL
double XX, stpX = prms->StpOGL ;// øàã ïî ãîðèçîíòàëè
double YY, stpY = 2.0 / 256.0 ;// Øàã ïî âåðòèêàëè
double ofst = prms->Offset_H ;
ULONG ixArr = prms->IxArr ;
// int cntArr = prms->CntArr ;
// short* pSrcData = prms->pSrcData ;
if(!prms->pSrcData || !prms->ChEnbl) return ;
int ch, cntCh = prms->CHMode == 1 ? 4 : prms->CHMode == 2 ? 2 : 1 ;
glNewList(lstGL,GL_COMPILE) ;{
glLineWidth(1) ;
for(ch=0;ch<cntCh;ch++){
glColorT(clr[ch]) ;
glBegin(GL_LINE_STRIP) ;{
for(ix=0;ix<prms->nSrcDataLen;ix++){
XX = (ix*cntCh+ch) * stpX ;
YY = prms->pSrcData[ixArr+ch][ix]*stpY ;
glVertex2f(XX + ofst,YY - 1.0) ;
}
} glEnd() ;
}
}glEndList() ;
}
//---------------------------------------------------------------------------
GLvoid DrawWaveGL(TParamsDrawWave* prms)
{
uint32_t lst = CNL_1 + prms->nCh ;
// if(glIsList(lst)) glDeleteLists(lst,1) ;
// êîë-âî îòñ÷¸òîâ â ViewOGL
double stpX = prms->StpOGL ;// øàã ïî ãîðèçîíòàëè
double stpY = 2.0 / 256.0 ;// Øàã ïî âåðòèêàëè
double ofst = prms->Offset_H ;
short* pSrcData = prms->pSrcData[prms->nCh] ;
if(!pSrcData) return ;
glNewList(lst,GL_COMPILE) ;{
glLineWidth(1) ;
glBegin(GL_LINE_STRIP) ;{
glColorT(prms->clrRGB) ;
for(ULONG ix=0;ix<prms->nSrcDataLen;ix++){
glVertex2f((ix * stpX + ofst),pSrcData[ix] * stpY-1.0) ;}
} glEnd() ;
}glEndList() ;
}
//---------------------------------------------------------------------------
GLvoid DrawSceneGL(GLsizei width, GLsizei height,bool dbg)
{if(!ghDC || !ghRC) return ;
glViewport( 0, 0,width,height) ;// óñòàíàâëèâàåì îáëàñòü âûâîäà
glMatrixMode( GL_PROJECTION ) ;// óñòàíàâëèâàåì ðåæèì ìàòðèöû âèäîâîãî ïðåîáðàçîâàíèÿ
glLoadIdentity() ;// çàìåíÿåì òåêóùóþ ìàòðèöó âèäîâîãî ïðåîáðàçîâàíèÿ
glMatrixMode( GL_MODELVIEW ) ;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // î÷èùàåì áóôåð êàäðà
glDisable(GL_BLEND) ;
glPushMatrix() ;
//-------
for(int nCh=0;nCh<4;nCh++)
if(glIsList(CNL_1+nCh)){ glCallList(CNL_1+nCh); glDeleteLists(CNL_1+nCh,1) ;}
//-------
if(glIsList(SHP_OGL)) glCallList(SHP_OGL) ;
if(glIsList(CUR_OGL)) glCallList(CUR_OGL) ;
if(glIsList(GRID )) glCallList(GRID) ;
// glDisable(GL_ALPHA_TEST) ;
glDisable(GL_COLOR_MATERIAL) ;
glEnable (GL_COLOR_MATERIAL) ;
glPopMatrix() ;
SwapBuffers(ghDC) ; // âûâîäèì âñ¸ íà ýêðàí
}
//---------------------------------------------------------------------------
GLvoid InitializeGL(HWND handle,GLsizei width, GLsizei height,TColor _color)
{
GLfloat maxObjectSize, aspect;
GLdouble near_plane;
HandleGL = handle ;
ghDC = GetDC(handle) ;
if(bSetupPixelFormat(ghDC)){
ghRC = wglCreateContext(ghDC) ;
wglMakeCurrent(ghDC, ghRC) ;}
else{ DestroyGL() ; return ;}
// glClearIndex( (GLfloat)BLACK_INDEX);
glClearDepth( 1.0 );
// glEnable(GL_DEPTH_TEST);
glMatrixMode( GL_PROJECTION );
aspect = (GLfloat) width / height;
gluPerspective( 45.0, aspect, 1.0, 10.0 );
glMatrixMode( GL_MODELVIEW );
GLfloat specular [] = { 1.0, 1.0, 1.0, 1.0};
GLfloat diffuse [] = { 1.0, 1.0, 1.0, 1.0};
GLfloat emission [] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat ambient [] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat shininess [] = { 100.0 };
GLfloat specularM [] = { 1.0, 1.0, 1.0, 1.0};
GLfloat diffuseM [] = { 0.8, 0.8, 0.8, 1.0};
GLfloat ambientM [] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat shininessM [] = { 50.0 };
GLfloat emissionM [] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat position [] = { 2.0, 2.0, 2.0, 0.0 };
GLfloat position1 [] = { -1.0, 1.0, 1.0, 0.0 };
Trgb rgb(_color) ;
glClearColor(rgb.rf(),rgb.gf(),rgb.bf(),1) ;// Set the clear color
// glClearColor(0.7, 0.7, 0.7, 0.0);
// Set the shading model
// glShadeModel(GL_SMOOTH);
glShadeModel(GL_FLAT);
// glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
// Set the polygon mode to fill
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glPolygonMode(GL_FRONT, GL_FILL);
// Enable depth testing for hidden line removal
glEnable(GL_DEPTH_TEST);
// Define material properties of specular color and degree of
// shininess. Since this is only done once in this particular
// example, it applies to all objects. Material properties can
// be set for individual objects, individual faces of the objects,
// individual vertices of the faces, etc...
// glMaterialfv(GL_FRONT, GL_SPECULAR , specularM);
// glMaterialfv(GL_FRONT, GL_SHININESS, shininessM);
// glMaterialfv(GL_FRONT, GL_EMISSION , emissionM);
// Set the GL_AMBIENT_AND_DIFFUSE color state variable to be the
// one referred to by all following calls to glColor
// glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
// Create a Directional Light Source
// glLightfv(GL_LIGHT0,GL_POSITION, position);
// glLightfv(GL_LIGHT0,GL_DIFFUSE , diffuse);
// glLightfv(GL_LIGHT0,GL_SPECULAR, specular);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// glBlendFunc(GL_SRC_ALPHA,GL_SRC_ALPHA);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glPixelStorei(GL_UNPACK_ALIGNMENT,2) ;
// glEnable(GL_BLEND);
near_plane = 3.0;
maxObjectSize = 3.0F;
// CreateObjects();
}
//---------------------------------------------------------------------------
GLvoid DrawGridGL(USHORT cntGrid_H,USHORT cntGrid_V,USHORT nBright,USHORT IsGrid)
{
float lenT1 = 1.0f, lenT2 = 0.015f ;
glNewList(GRID,GL_COMPILE) ;{
glLineWidth(1) ;
glLineStipple(1,0xAAAA) ;//1,0x3F07) ;
glEnable(GL_LINE_STIPPLE) ;
glBegin(GL_LINES) ;{
glColorT(clGray) ;// glColor3ub(50,90,40) ;
glVertex2f(-1.0f, 0.0f) ;
glVertex2f( 1.0f, 0.0f) ;
glVertex2f( 0.0f, 1.0f) ;
glVertex2f( 0.0f,-1.0f) ;
for(float ix=-1.0;ix<1.0f;ix+=2.0f/cntGrid_H){
glVertex2f( ix,-lenT1) ; glVertex2f( ix, lenT1) ;}
for(float ix=-1.0;ix<1.0f;ix+=0.4f/cntGrid_H){
glVertex2f( ix,-lenT2) ; glVertex2f( ix, lenT2) ;}
lenT2 = lenT2 * cntGrid_V / cntGrid_H ;
for(float ix=-1.0;ix<1.0f;ix+=2.0f/cntGrid_V){
glVertex2f(-lenT1, ix) ; glVertex2f( lenT1, ix) ;}
for(float ix=-1.0;ix<1.0f;ix+=0.4f/cntGrid_V){
glVertex2f(-lenT2, ix) ; glVertex2f( lenT2, ix) ;}
} glEnd() ;
glDisable(GL_LINE_STIPPLE) ;
}glEndList() ;
}
//---------------------------------------------------------------------------
GLvoid DestroyGL(void)
{
if(ghRC){
wglMakeCurrent(ghDC,0) ;
wglDeleteContext(ghRC) ;}
if(ghDC) ReleaseDC(HandleGL, ghDC) ;
ghDC = 0 ; ghRC = 0 ; HandleGL = 0 ;}
//---------------------------------------------------------------------------
BOOL bSetupPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd, *ppfd;
int pixelformat;
ppfd = &pfd;
ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR) ;
ppfd->nVersion = 1 ;
ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
ppfd->dwLayerMask= PFD_MAIN_PLANE ;
ppfd->iPixelType = PFD_TYPE_RGBA ;//COLORINDEX;
ppfd->cColorBits = 8 ;
ppfd->cDepthBits = 16 ;
ppfd->cAccumBits = 0 ;
ppfd->cStencilBits = 0 ;
if((pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 ){
MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK) ; return FALSE ;}
if(SetPixelFormat(hdc,pixelformat,ppfd) == FALSE){
MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK) ; return FALSE ;}
return TRUE;
}
//-----------------------------------------------------------------------------