00001
00002
00003
00004
00005
00006 #include "GlBaseClass.h"
00007
00008
00009 #ifdef ENABLE_OPENGL
00010
00011
00012 using namespace jbxwl;
00013
00014
00016
00017
00018 CGlBaseView::CGlBaseView()
00019 {
00020 m_hRC = NULL;
00021 m_pDC = NULL;
00022
00023 ZeroMemory(&glParam, sizeof(PIXELFORMATDESCRIPTOR));
00024 }
00025
00026
00027
00028 CGlBaseView::~CGlBaseView()
00029 {
00030 DEBUG_INFO("DESTRUCTOR: CGlBaseView\n");
00031 if (pApp!=NULL) pApp->ViewDestructor(this);
00032 }
00033
00034
00035
00036
00037
00038 void CGlBaseView::SetParameter(PIXELFORMATDESCRIPTOR* param)
00039 {
00040
00041
00042 ZeroMemory(param, sizeof(PIXELFORMATDESCRIPTOR));
00043 param->nSize = sizeof(PIXELFORMATDESCRIPTOR);
00044 param->nVersion = 1;
00045 param->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
00046 param->iPixelType = PFD_TYPE_RGBA;
00047 param->cColorBits = 24;
00048 param->cDepthBits = 16;
00049 param->iLayerType = PFD_MAIN_PLANE;
00050
00051 colorMode = GRAPH_COLOR_RGBA;
00052 }
00053
00054
00055
00056 BOOL CGlBaseView::InitDevice(int xsize, int ysize, CWnd* cwnd)
00057 {
00058 ::glDepthFunc(GL_LEQUAL);
00059 ::glEnable(GL_DEPTH_TEST);
00060
00061 ::glShadeModel(GL_SMOOTH);
00062
00063
00064
00065
00066
00067
00068 SetWindowSize(xsize, ysize);
00069
00070 return TRUE;
00071 }
00072
00073
00074
00075
00076
00077 POINT CGlBaseView::GetWindowDisplaySize(POINT pt)
00078 {
00079 int rx = GetSystemMetrics(SM_CXSCREEN);
00080 int ry = GetSystemMetrics(SM_CYSCREEN) - 14;
00081
00082 int scrSize = Min(rx, ry)*2/3;
00083 int sz = Max(pt.x, pt.y);
00084 if (sz<=0) return pt;
00085
00086 double rs = 1.0;
00087 if (sz>scrSize) {
00088 rs = (double)scrSize/sz;
00089 pt.x = (int)(pt.x*rs);
00090 pt.y = (int)(pt.y*rs);
00091 }
00092
00093 return pt;
00094 }
00095
00096
00097
00108 int CGlBaseView::GetMouseButton()
00109 {
00110 return 0;
00111 }
00112
00113
00114
00115 void CGlBaseView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
00116 {
00117 CExView::OnActivateView(bActivate, pActivateView, pDeactiveView);
00118 }
00119
00120
00121
00122
00124
00125
00126 BEGIN_MESSAGE_MAP(jbxwl::CGlBaseView, CExView)
00127 ON_WM_CREATE()
00128 ON_WM_DESTROY()
00129 ON_WM_SIZE()
00130 END_MESSAGE_MAP()
00131
00132
00133
00134 int CGlBaseView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00135 {
00136 if (CExView::OnCreate(lpCreateStruct)==-1) return -1;
00137
00138 m_pDC = new CClientDC(this);
00139 if (m_pDC==NULL) return -1;
00140
00141 SetParameter(&glParam);
00142
00143 m_hRC = WGLCreateContext(m_pDC, &glParam);
00144 if (m_hRC==NULL) {
00145 delete m_pDC;
00146 m_pDC = NULL;
00147 return -1;
00148 }
00149
00150 return 0;
00151 }
00152
00153
00154
00155 void CGlBaseView::OnDestroy()
00156 {
00157 CExView::OnDestroy();
00158
00159 WGLDeleteContext(m_hRC);
00160
00161 if (m_pDC) {
00162 delete m_pDC;
00163 m_pDC = NULL;
00164 }
00165 }
00166
00167
00168
00169 void CGlBaseView::OnSize(UINT nType, int cx, int cy)
00170 {
00171 CExView::OnSize(nType, cx, cy);
00172 }
00173
00174
00175
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 #endif // ENABLE_OPENGL