Dim m_hGLRC As Long Private Sub Form_Initialize() Initialize ViewSet End Sub Private Sub Picture1_Paint() Draw End Sub Private Function Initialize() As Boolean Dim pfd As PIXELFORMATDESCRIPTOR Dim R& Picture1.ScaleMode = vbPixels 'set standard parameters pfd.nSize = Len(pfd) pfd.nVersion = 1 pfd.dwFlags = PFD_SUPPORT_OPENGL Or PFD_DRAW_TO_WINDOW Or PFD_SINGLE Or PFD_TYPE_RGBA pfd.iPixelType = PFD_TYPE_RGBA pfd.cColorBits = 24 pfd.cDepthBits = 16 pfd.iLayerType = PFD_MAIN_PLANE R = ChoosePixelFormat(Picture1.hDC, pfd) If R = 0 Then MsgBox "ChoosePixelFormat failed" Exit Function End If R = SetPixelFormat(Picture1.hDC, R, pfd) m_hGLRC = wglCreateContext(Picture1.hDC) wglMakeCurrent Picture1.hDC, m_hGLRC Initialize = True End Function Private Sub Form_Unload(Cancel As Integer) If m_hGLRC <> 0 Then wglMakeCurrent 0, 0 wglDeleteContext m_hGLRC End If End Sub Private Sub ViewSet() glMatrixMode GL_PROJECTION glLoadIdentity glOrtho -1, 1, -1, 1, -1, 1 glMatrixMode GL_MODELVIEW End Sub Public Sub Draw() glClearColor 0, 0, 0, 0 glClear GL_COLOR_BUFFER_BIT glColor3f 1#, 1#, 1# glLoadIdentity glBegin GL_POLYGON glVertex2f -0.5, -0.5 glVertex2f -0.5, 0.5 glVertex2f 0.5, 0.5 glVertex2f 0.5, -0.5 glEnd glFlush End Sub