确实是在paint里画的,而且resize里面有修改视口变换,图形应该在resize之后重新投影,
protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
if(m_uint_DC == 0 || m_uint_RC == 0)
return;
WGL.wglMakeCurrent(m_uint_DC, m_uint_RC);
// Just clear the screen
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GL.glLoadIdentity();
GLU.gluLookAt(50, 50, 50, 0, 0, 0, 0, 0, 1);
//画球
int quadric = GLU.gluNewQuadric();
GLU.gluQuadricDrawStyle(quadric, GLU.GLU_SILHOUETTE);
GL.glPushMatrix();
GL.glColor3f(0.0f, 1.0f, 0.0f);
GL.glRotated(90, 1.0, 0.0, 0.0);
GLU.gluSphere(quadric, 20, 36, 18);
GL.glPopMatrix();
GL.glFlush();
GL.glDisable(GL.GL_DEPTH_TEST);
WGL.wglSwapBuffers(m_uint_DC);
WGL.wglMakeCurrent(0, 0);
}
protected virtual void ResizeGL(int w, int h)
{//在OnResize里调用
WGL.wglMakeCurrent(m_uint_DC,m_uint_RC);
GL.glViewport( 0, 0, w, h);
GL.glMatrixMode ( GL.GL_PROJECTION );
GL.glLoadIdentity();
GLU.gluPerspective( 30.0,((double)(w) / (double)(h)), 1.0,1000.0);
GL.glMatrixMode ( GL.GL_MODELVIEW );
GL.glLoadIdentity();
}