发布网友 发布时间:2022-04-24 04:59
共1个回答
热心网友 时间:2023-10-30 07:03
我在网上找的一段代码,不知正确不正确,你自己试一试
http://bbs.cfan.com.cn/viewthread.php?tid=495436
Public Function Initialize() As Boolean
w_x = 5
w_y = 5
w_z = 10
draging = False
Dim pfd As PIXELFORMATDESCRIPTOR
Dim R&, pos!(0 To 3)
'set standard parameters
pfd.nSize = Len(pfd)
pfd.nVersion = 1
pfd.dwFlags = PFD_SUPPORT_OPENGL Or PFD_DRAW_TO_WINDOW Or PFD_DOUBLEBUFFER Or PFD_TYPE_RGBA
pfd.iPixelType = PFD_TYPE_RGBA
pfd.cColorBits = 16
pfd.cDepthBits = 16
pfd.iLayerType = PFD_MAIN_PLANE
R = ChoosePixelFormat(hDC, pfd)
If R = 0 Then
MsgBox "ChoosePixelFormat failed"
Exit Function
End If
R = SetPixelFormat(hDC, R, pfd)
'palette?
'
'=================
'=================
m_hGLRC = wglCreateContext(hDC)
wglMakeCurrent hDC, m_hGLRC
glClearColor 0, 0, 0, 1
'depth
glClearDepth 1
glEnable GL_DEPTH_TEST
'color
glEnable glcColorMaterial
glColorMaterial faceFront, GL_AMBIENT_AND_DIFFUSE
'lighting
glEnable GL_LIGHTING
glEnable glcLight0
'move light
pos(0) = 10: pos(1) = 10: pos(2) = 10: pos(3) = 1
glLightfv ltLight0, lpmPosition, pos(0)
pos(0) = -1: pos(1) = -1: pos(2) = -1
glLightfv ltLight0, lpmSpotDirection, pos(0)
glLightfv ltLight0, lpmSpotCutoff, 40
glLightfv ltLight0, lpmSpotExponent, 4
'viewport
m_AspectRatio = 1
m_FarPlane = 200
m_NearPlane = 0.5
m_fieldOfView = 45
'
DrawWorld
Initialize = True
End Function
Public Sub DrawWorld()
Dim obj&
Dim i
glPushMatrix
glNewList WORLD_LIST, GL_COMPILE
glColor3f 0.2, 0.8, 0
obj = gluNewQuadric
glTranslatef 0, 0, 0
glColor3f c_r, c_g, c_b
gluQuadricDrawStyle obj, GLU_SILHOUETTE
gluSphere obj, 5, 32, 20
glEndList
glPopMatrix
End Sub
'Adjusts the viewport to match the window size.
Public Sub OnSize(ByVal W&, ByVal H&)
If H = 0 Then H = 1
m_AspectRatio = W / H
glViewport 0, 0, W, H
SetViewPort
End Sub
Private Sub SetViewPort()
Dim W&, H&
Dim X#, Y#, Z#
glMatrixMode mmProjection
glLoadIdentity
gluPerspective m_fieldOfView, _
m_AspectRatio, _
m_NearPlane, _
m_FarPlane
glMatrixMode mmModelView
glLoadIdentity
参考资料:http://www.programsalon.com/downloads38/sourcecode/windows/opengl/detail126872.html