I want to use OpenGL to show a STL model . But why the picture look like in 2D ?
Public Sub CreateGLPannel(Pannel As PictureBox)
Dim PixelFormat As GLuint
Dim pfd As PIXELFORMATDESCRIPTOR
With pfd
.cColorBits = Bits
.cDepthBits = 16
.dwFlags = PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER
.iLayerType = PFD_MAIN_PLANE
.iPixelType = PFD_TYPE_RGBA
.nSize = Len(pfd)
.nVersion = 1
End With
PixelFormat = ChoosePixelFormat(Pannel.hdc, pfd)
SetPixelFormat Pannel.hdc, PixelFormat, pfd
hrc = wglCreateContext(Pannel.hdc)
wglMakeCurrent Pannel.hdc, hrc
InitGL
ResizeGLScene Pannel, 4000, 4000, 4000
End Sub
Private Sub InitGL()
glShadeModel smSmooth
glClearColor 0, 0, 0, 0
glClearDepth 1
glEnable glcDepthTest
glDepthFunc cfLEqual
glHint htPerspectiveCorrectionHint, hmNicest
Lighting
End Sub
Private Sub Lighting()
Dim Specular(0 To 3) As GLfloat
Specular(0) = 0.5: Specular(1) = 1.5: Specular(2) = 2.5: Specular(3) = 3.5
glMaterialf faceFrontAndBack, Shininess, 0.5
glMaterialf faceFrontAndBack, mprSpecular, Specular(0)
glMaterialf faceFrontAndBack, AmbientAndDiffuse, 0
glEnable glcColorMaterial
glLightf ltLight0, lpmPosition, -100
glEnable glcLighting
glEnable glcLight0
End Sub
Public Sub DrawPart()
glMatrixMode mmModelView
glLoadIdentity
Select Case isfrontview
Case True
gluLookAt 0, 0, 0, 0, -1, 0, 1, 0, 0
Case False
gluLookAt 0, 0, 0, 0, 0, -1, 0, 1, 0
End Select
Select Case zoomcounter
Case 1.5
glScalef 1.5, 1.5, 1.5
Case 2
glScalef 2, 2, 2
Case 2.5
glScalef 2.5, 2.5, 2.5
Case 3
glScalef 3, 3, 3
End Select
glTranslatef gpQuadX, 1000, -800
glRotatef grQuadX, 1, 0, 0
glRotatef grQuadY, 0, 1, 0
glRotatef grQuadZ, 0, 0, 1
DrawPartList
End Sub
Private Sub DrawPartList()
Dim i As Integer
Dim Temp As Integer
Dim TrangleCounter As Integer
TrangleCounter = CInt((PartVertexCounter - 1) / 3)
glColor3f PartColor.R, PartColor.G, PartColor.B
glBegin bmTriangles
For i = 1 To TrangleCounter
Temp = (i - 1) * 3 + 1
glVertex3f Abs_PartVertex(Temp).x, Abs_PartVertex(Temp).y, Abs_PartVertex(Temp).z
glVertex3f Abs_PartVertex(Temp + 1).x, Abs_PartVertex(Temp + 1).y, Abs_PartVertex(Temp + 1).z
glVertex3f Abs_PartVertex(Temp + 2).x, Abs_PartVertex(Temp + 2).y, Abs_PartVertex(Temp + 2).z
Next i
glEnd
End Sub
↧