testglview.cpp
来自「如何在自己的ActiveX控件中集成OpenGL功能」· C++ 代码 · 共 745 行 · 第 1/2 页
CPP
745 行
MouseDownPoint=point;
// capture mouse movements even outside window borders
SetCapture();
}
void CTestGLView::OnLButtonUp(UINT nFlags, CPoint point)
{
// forget where we clicked
MouseDownPoint=CPoint(0,0);
// release mouse capture
ReleaseCapture();
}
void CTestGLView::OnMouseMove(UINT nFlags, CPoint point)
{
// check if we have captured the mouse
if (GetCapture()==this)
{
// increment the object rotation angles
X_Angle+=double(point.y-MouseDownPoint.y)/3.6;
Y_Angle+=double(point.x-MouseDownPoint.x)/3.6;
// redraw the view
Invalidate(TRUE);
// remember the mouse point
MouseDownPoint=point;
};
}
void CTestGLView::OnHelpOglinfo()
{
// istantiate dialog
COGLInfoDlg dlg;
int pos=0;
// get infos
dlg.m_accel=GetInformation(ACCELERATION);
dlg.m_rend=GetInformation(RENDERER);
dlg.m_vendor=GetInformation(VENDOR);
dlg.m_version=GetInformation(VERSION);
dlg.m_extensions=GetInformation(EXTENSIONS);
// convert the spaces in newlines
while ( (pos=dlg.m_extensions.Find(" "))!=-1 )
dlg.m_extensions.SetAt(pos,'\n');
// show dialog
dlg.DoModal();
}
void CTestGLView::OnTesselatorFill()
{
// toggle filling
TessFilling^=1;
// rebuild display list
BeginGLCommands();
BuildTessDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnUpdateTesselatorFill(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==1);
pCmdUI->SetCheck(TessFilling);
}
void CTestGLView::OnTesselatorNeg()
{
// set specified rule
TessWindRule=GLU_TESS_WINDING_NEGATIVE;
// rebuild display list
BeginGLCommands();
BuildTessDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnUpdateTesselatorNeg(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==1);
pCmdUI->SetCheck(TessWindRule==GLU_TESS_WINDING_NEGATIVE);
}
void CTestGLView::OnTesselatorNonzero()
{
// set specified rule
TessWindRule=GLU_TESS_WINDING_NONZERO;
// rebuild display list
BeginGLCommands();
BuildTessDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnUpdateTesselatorNonzero(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==1);
pCmdUI->SetCheck(TessWindRule==GLU_TESS_WINDING_NONZERO);
}
void CTestGLView::OnTesselatorOddrule()
{
// set specified rule
TessWindRule=GLU_TESS_WINDING_ODD;
// rebuild display list
BeginGLCommands();
BuildTessDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnUpdateTesselatorOddrule(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==1);
pCmdUI->SetCheck(TessWindRule==GLU_TESS_WINDING_ODD);
}
void CTestGLView::OnTesselatorPos()
{
// set specified rule
TessWindRule=GLU_TESS_WINDING_POSITIVE;
// rebuild display list
BeginGLCommands();
BuildTessDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnUpdateTesselatorPos(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==1);
pCmdUI->SetCheck(TessWindRule==GLU_TESS_WINDING_POSITIVE);
}
void CTestGLView::OnChangeScene()
{
// toggle scene
++sceneselect%=3;
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricFill()
{
// set specified parameter
quadricDwStyle=GLU_FILL;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricFlat()
{
// set specified parameter
quadricNormals=GLU_FLAT;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricInside()
{
// set specified parameter
quadricOrientation=GLU_INSIDE;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricLine()
{
// set specified parameter
quadricDwStyle=GLU_LINE;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricNone()
{
// set specified parameter
quadricNormals=GLU_NONE;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricOutside()
{
// set specified parameter
quadricOrientation=GLU_OUTSIDE;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricPoint()
{
// set specified parameter
quadricDwStyle=GLU_POINT;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricSilhouette()
{
// set specified parameter
quadricDwStyle=GLU_SILHOUETTE;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnQuadricSmooth()
{
// set specified parameter
quadricNormals=GLU_SMOOTH;
// rebuild display list
BeginGLCommands();
BuildQuadrDispList();
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnUpdateQuadricFill(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricDwStyle==GLU_FILL);
}
void CTestGLView::OnUpdateQuadricFlat(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricNormals==GLU_FLAT);
}
void CTestGLView::OnUpdateQuadricInside(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricOrientation==GLU_INSIDE);
}
void CTestGLView::OnUpdateQuadricLine(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricDwStyle==GLU_LINE);
}
void CTestGLView::OnUpdateQuadricNone(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricNormals==GLU_NONE);
}
void CTestGLView::OnUpdateQuadricOutside(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricOrientation==GLU_OUTSIDE);
}
void CTestGLView::OnUpdateQuadricPoint(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricDwStyle==GLU_POINT);
}
void CTestGLView::OnUpdateQuadricSilhouette(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricDwStyle==GLU_SILHOUETTE);
}
void CTestGLView::OnUpdateQuadricSmooth(CCmdUI* pCmdUI)
{
pCmdUI->Enable(sceneselect==2);
pCmdUI->SetCheck(quadricNormals==GLU_SMOOTH);
}
void CTestGLView::OnEnvirFlat()
{
BeginGLCommands();
// set flat shading
glShadeModel(GL_FLAT);
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnEnvirLighting()
{
BeginGLCommands();
// toggle lighting
if(glIsEnabled(GL_LIGHTING)) glDisable(GL_LIGHTING);
else glEnable(GL_LIGHTING);
EndGLCommands();
// redraw
Invalidate(TRUE);
}
void CTestGLView::OnEnvirSmooth()
{
BeginGLCommands();
// set smooth shading
glShadeModel(GL_SMOOTH);
EndGLCommands();
// redraw
Invalidate(TRUE);
}
/*************
NOTE: the funtions below retrieve OGL state to give some visual cue to menu items
but this is extremely slow (and it's been done for simplicity).
You should mantain local variables by which update the state of
menus,buttons etc.
*************/
void CTestGLView::OnUpdateEnvirLighting(CCmdUI* pCmdUI)
{
BeginGLCommands();
// update menu check
pCmdUI->SetCheck(glIsEnabled(GL_LIGHTING));
EndGLCommands();
}
void CTestGLView::OnUpdateEnvirFlat(CCmdUI* pCmdUI)
{
BeginGLCommands();
// check shading mode
GLint val;
glGetIntegerv(GL_SHADE_MODEL,&val);
// set check accordingly
pCmdUI->SetCheck(val==GL_FLAT);
EndGLCommands();
}
void CTestGLView::OnUpdateEnvirSmooth(CCmdUI* pCmdUI)
{
BeginGLCommands();
// check shading mode
GLint val;
glGetIntegerv(GL_SHADE_MODEL,&val);
// set check accordingly
pCmdUI->SetCheck(val==GL_SMOOTH);
EndGLCommands();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?