JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
GlProcView.cpp
Go to the documentation of this file.
1//
2// GlProcView.cpp : 実装ファイル
3//
4//
5// Document はダミーとなる
6//
7
8#include "MFCBase.h"
9#include "GlProcView.h"
10
11
12#ifdef ENABLE_OPENGL
13
14
15using namespace jbxl;
16using namespace jbxwl;
17
18
19// GlProcView
20
21IMPLEMENT_DYNCREATE(CGlProcView, CExView)
22
23
24CGlProcView::CGlProcView()
25{
26 hasViewData = TRUE;
27 //
28 initFunc = NULL;
29 dispFunc = NULL;
30 postFunc = NULL;
31}
32
33
34CGlProcView::~CGlProcView()
35{
36}
37
38
39// GlProcView 描画
40
41void CGlProcView::ExecRender()
42{
43 if (!WGLGetCurrent(this->m_pDC, this->m_hRC)) return;
44
45// CDocument* pDoc = GetDocument();
46
47 ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
48
49 // 描画モード
50// ::glMatrixMode(GL_MODELVIEW);
51// ::glLoadIdentity();
52
53 //
54 ::glEnable(GL_NORMALIZE);
55 ::glEnable(GL_AUTO_NORMAL);
56 ::glPushMatrix();
57
58 if (dispFunc!=NULL) (*dispFunc)();
59
60 ::glPopMatrix();
61 ::glDisable(GL_AUTO_NORMAL);
62 ::glDisable(GL_NORMALIZE);
63
64 //::glFinish();
65 ::glFlush();
66
67 SwapBuffers(m_pDC->GetSafeHdc());
68 if (postFunc!=NULL) (*postFunc)();
69}
70
71
72
74// CGlProcView メッセージ ハンドラ
75
76//
77// called from ExecDocFrmView();
78//
79void CGlProcView::OnInitialUpdate()
80{
81 //DEBUG_INFO("CGlProcView::OnInitialUpdate()\n");
82
83 // ウィンドウサイズ xsize, ysize の4バイト境界の問題は呼び出し側の責任
84 if (xsize<=0) xsize = 400;
85 if (ysize<=0) ysize = 400;
86
87 //
88 origXSize = xsize;
89 origYSize = ysize;
90 sizeXYRate = (float)ysize/(float)xsize;
91
92 //
93 InitDevice(xsize, ysize);
94 InitObject();
95 if (initFunc!=NULL) {
96 WGLGetCurrent(this->m_pDC, this->m_hRC);
97 (*initFunc)();
98 }
99
100 return;
101}
102
103
104
106//
107
108BEGIN_MESSAGE_MAP(CGlProcView, CGlBaseView)
109 ON_WM_SIZE()
110 ON_WM_CREATE()
111 ON_WM_DESTROY()
112END_MESSAGE_MAP()
113
114
115void CGlProcView::OnSize(UINT nType, int cx, int cy)
116{
117 if (!WGLGetCurrent(this->m_pDC, this->m_hRC)) return;
118
119 CGlBaseView::OnSize(nType, cx, cy);
120
121 //
122 if(0>=cx || 0>=cy) return;
123
124 ::glViewport(0, 0, cx, cy);
125 ::glMatrixMode(GL_PROJECTION);
126 ::glLoadIdentity();
127 ::gluPerspective(40.0f, (GLfloat)cx/(GLfloat)cy, 0.1f, 20.0f);
128 ::glMatrixMode(GL_MODELVIEW);
129 ::glLoadIdentity();
130
131 //
132 ::glTranslatef( 0.0f, 0.0f, -5.0f );
133 ::glRotatef( 0.0f, 0.0f, 0.0f, 0.0f );
134}
135
136
137int CGlProcView::OnCreate(LPCREATESTRUCT lpCreateStruct)
138{
139 //DEBUG_INFO("CGlProcView::OnCreate()\n");
140
141 if (CGlBaseView::OnCreate(lpCreateStruct)==-1) return -1;
142
143 return 0;
144}
145
146
147void CGlProcView::OnDestroy()
148{
149 CGlBaseView::OnDestroy();
150}
151
152
153// GlProcView 診断
154
155#ifdef _DEBUG
156void CGlProcView::AssertValid() const
157{
158 CGlBaseView::AssertValid();
159}
160
161
162#ifndef _WIN32_WCE
163void CGlProcView::Dump(CDumpContext& dc) const
164{
165 CGlBaseView::Dump(dc);
166}
167#endif
168#endif //_DEBUG
169
170
171#endif // ENABLE_OPENGL