我的代码如下:
void CWnd3D::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
HDC hdc = ::GetDC(m_hWnd);
HGLRC hglrc; // TODO: Add your message handler code here
glClearColor(0,0,0,0);
glColor3f(1, 1, 1); if (hglrc = wglCreateContext(hdc))
{
// try to make it the thread's current rendering context
if(wglMakeCurrent(hdc, hglrc))
{
//render here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(m_fRot[0], 1, 0, 0);
glRotatef(m_fRot[1], 0, 1, 0); glScalef(200, 300, 256);/////注意这行!! //画坐标轴
if (m_bAxis)
{
DrawAxis();
}
glPopMatrix();
// glFlush();
SwapBuffers(hdc);
}
} wglMakeCurrent(NULL, NULL) ;
::ReleaseDC (m_hWnd, hdc) ;
wglDeleteContext(hglrc); // Do not call CWnd::OnPaint() for painting messages
}
void CWnd3D::DrawAxis()
{
glBegin(GL_LINES);
glColor3f(1,0,0);//x轴
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glColor3f(0,1,0);//y轴
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glColor3f(0,0,1);//z轴
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glEnd();
}我想画坐标超过100的图元(如画线从(0,0,0)到(200,120,200)),怎么办?用glScalef()怎么没有反应???
void CWnd3D::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
HDC hdc = ::GetDC(m_hWnd);
HGLRC hglrc; // TODO: Add your message handler code here
glClearColor(0,0,0,0);
glColor3f(1, 1, 1); if (hglrc = wglCreateContext(hdc))
{
// try to make it the thread's current rendering context
if(wglMakeCurrent(hdc, hglrc))
{
//render here
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(m_fRot[0], 1, 0, 0);
glRotatef(m_fRot[1], 0, 1, 0); glScalef(200, 300, 256);/////注意这行!! //画坐标轴
if (m_bAxis)
{
DrawAxis();
}
glPopMatrix();
// glFlush();
SwapBuffers(hdc);
}
} wglMakeCurrent(NULL, NULL) ;
::ReleaseDC (m_hWnd, hdc) ;
wglDeleteContext(hglrc); // Do not call CWnd::OnPaint() for painting messages
}
void CWnd3D::DrawAxis()
{
glBegin(GL_LINES);
glColor3f(1,0,0);//x轴
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glColor3f(0,1,0);//y轴
glVertex3f(0,0,0);
glVertex3f(0,1,0);
glColor3f(0,0,1);//z轴
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glEnd();
}我想画坐标超过100的图元(如画线从(0,0,0)到(200,120,200)),怎么办?用glScalef()怎么没有反应???
解决方案 »
- 求助,怎么用opengl在一个三维空间中画一个小人。
- 如何用OnPaint来自绘VC中的CButton?
- 系统托盘图标色深的问题
- 初学“不规则窗口的实现”中出现的问题
- 如何创建灰色背景的内存区域?
- 请教一个在vc里面调用应用程序的问题?(已经帖了很多次,一直没人回复?)
- OLE COM 的问题 ,IShellIconOverlayIdentifier 中的疑问
- 怎样缩短猫的登陆时间?
- 如何将一普通动态链接库工程转换为ActiveX dll?
- 谁知道是怎么回事:LINK : warning LNK4089: all references to "WSOCK32.dll" discarded by /OPT:REF
- hjf00005大侠,谢谢你的指教,请进来取分,聊表谢意.
- 如何用SMTP发信,最好用WIN32的方法(急用)?
{
glClearColor(m_SimBkColor.Red,m_SimBkColor.Green,m_SimBkColor.Blue,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//公共变换
glLoadIdentity();
glTranslatef(m_SimMove.MoveX,m_SimMove.MoveY,-m_SimMove.MoveZ);
glScaled(m_SimScale,m_SimScale,m_SimScale);
glRotatef(m_SimRotate.RotateX,1.0,0.0,0.0);
glRotatef(m_SimRotate.RotateY,0.0,1.0,0.0);
glRotatef(m_SimRotate.RotateZ,0.0,0.0,1.0);
//画轴线
glDisable(GL_LIGHTING);
DrawAxis(); if(m_SimMode==SIM_PART_MODE)
{
glLightfv(GL_LIGHT0,GL_AMBIENT,m_SimLight.Ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,m_SimLight.Diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,m_SimLight.Specular);
// glLightfv(GL_LIGHT0,GL_POSITION,m_SimLight.Position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
}
else
{
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
}
}
void CNCSimView::DrawAxis()
{
glPushMatrix();
glBegin(GL_LINES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(500.0f,0.0f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,500.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,500.0f);
glEnd();
glPopMatrix();//1
}void CNCSimView::DrawScreen()
{
InitDraw();/* if(m_SimMode==SIM_PART_MODE)
{
DrawPart();
}
else
{
DrawNodeList();
}
DrawTool();*/
SwapBuffers(wglGetCurrentDC());
}BOOL CNCSimView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
DrawScreen();
return TRUE;
// return CView::OnEraseBkgnd(pDC);
}