Jump to content
  • Advertisement
Ivy_ZH

OpenGL Why my model can not show in 3D effects by OpenGL?

This topic is 532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

捕获.PNG

Share this post


Link to post
Share on other sites
Advertisement

are you just drawing a quad? if so that's probably why it looks 2d. Quads are flat, so if you just look at it straight on, it will just look like a square on the screen.

Share this post


Link to post
Share on other sites

Hi

I don't see where you setup your projection matrix, and if you don"t create one, the default OpenGL's projection is used, and it is an orthographic projection, explaining your 2D feeling.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!