OpenGL显示的图形没有三维效果,请大神帮忙看看是什么问题。万分感激。

OpenGL显示时是这个样子
想要的效果是这样的

我是读取了一个STL文件,想用OpenGL显示,但是显示出的效果却是第一幅图像平面的,我希望是像第二幅图那样显示的。请问是光照或者其他什么设置问题吗?希望大家能帮我看看,非常感谢!部分代码是这样的。

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


1个回答

gluLookAt(GLdouble eyex,GLdouble eyey,GLdouble eyez,GLdouble centerx,GLdouble centery,GLdouble centerz,GLdouble upx,GLdouble upy,GLdouble upz);
glutLookAt(眼睛的位置,眼睛看的位置,世界坐标正方向)
世界正方向为0,1,0
改变gluLookAt的参数,调整镜头方向就可以了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问