00001
00002
00003
00004
00005
00006
00007
00008 #include "MFCBase.h"
00009 #include "GlProcView.h"
00010
00011
00012 #ifdef ENABLE_OPENGL
00013
00014
00015 using namespace jbxl;
00016 using namespace jbxwl;
00017
00018
00019
00020
00021 IMPLEMENT_DYNCREATE(CGlProcView, CExView)
00022
00023
00024 CGlProcView::CGlProcView()
00025 {
00026 hasViewData = TRUE;
00027
00028 initFunc = NULL;
00029 dispFunc = NULL;
00030 postFunc = NULL;
00031 }
00032
00033
00034
00035 CGlProcView::~CGlProcView()
00036 {
00037 }
00038
00039
00040
00041
00042
00043 void CGlProcView::ExecRender()
00044 {
00045 if (!WGLGetCurrent(this->m_pDC, this->m_hRC)) return;
00046
00047
00048
00049 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00050
00051
00052
00053
00054
00055
00056 ::glEnable(GL_NORMALIZE);
00057 ::glEnable(GL_AUTO_NORMAL);
00058 ::glPushMatrix();
00059
00060 if (dispFunc!=NULL) (*dispFunc)();
00061
00062 ::glPopMatrix();
00063 ::glDisable(GL_AUTO_NORMAL);
00064 ::glDisable(GL_NORMALIZE);
00065
00066
00067 ::glFlush();
00068
00069 SwapBuffers(m_pDC->GetSafeHdc());
00070 if (postFunc!=NULL) (*postFunc)();
00071 }
00072
00073
00074
00076
00077
00078
00079
00080
00081 void CGlProcView::OnInitialUpdate()
00082 {
00083
00084
00085
00086 if (xsize<=0) xsize = 400;
00087 if (ysize<=0) ysize = 400;
00088
00089
00090 origXSize = xsize;
00091 origYSize = ysize;
00092 sizeXYRate = (float)ysize/(float)xsize;
00093
00094
00095 InitDevice(xsize, ysize);
00096 InitObject();
00097 if (initFunc!=NULL) {
00098 WGLGetCurrent(this->m_pDC, this->m_hRC);
00099 (*initFunc)();
00100 }
00101
00102 return;
00103 }
00104
00105
00106
00108
00109
00110 BEGIN_MESSAGE_MAP(CGlProcView, CGlBaseView)
00111 ON_WM_SIZE()
00112 ON_WM_CREATE()
00113 ON_WM_DESTROY()
00114 END_MESSAGE_MAP()
00115
00116
00117 void CGlProcView::OnSize(UINT nType, int cx, int cy)
00118 {
00119 if (!WGLGetCurrent(this->m_pDC, this->m_hRC)) return;
00120
00121 CGlBaseView::OnSize(nType, cx, cy);
00122
00123
00124 if(0>=cx || 0>=cy) return;
00125
00126 ::glViewport(0, 0, cx, cy);
00127 ::glMatrixMode(GL_PROJECTION);
00128 ::glLoadIdentity();
00129 ::gluPerspective(40.0f, (GLfloat)cx/(GLfloat)cy, 0.1f, 20.0f);
00130 ::glMatrixMode(GL_MODELVIEW);
00131 ::glLoadIdentity();
00132
00133
00134 ::glTranslatef( 0.0f, 0.0f, -5.0f );
00135 ::glRotatef( 0.0f, 0.0f, 0.0f, 0.0f );
00136 }
00137
00138
00139
00140 int CGlProcView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00141 {
00142
00143
00144 if (CGlBaseView::OnCreate(lpCreateStruct)==-1) return -1;
00145
00146 return 0;
00147 }
00148
00149
00150
00151 void CGlProcView::OnDestroy()
00152 {
00153 CGlBaseView::OnDestroy();
00154 }
00155
00156
00157
00158
00159
00160 #ifdef _DEBUG
00161 void CGlProcView::AssertValid() const
00162 {
00163 CGlBaseView::AssertValid();
00164 }
00165
00166
00167 #ifndef _WIN32_WCE
00168 void CGlProcView::Dump(CDumpContext& dc) const
00169 {
00170 CGlBaseView::Dump(dc);
00171 }
00172 #endif
00173 #endif //_DEBUG
00174
00175
00176 #endif // ENABLE_OPENGL