首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

利用opengl在vbnet下画线的有关问题

2012-02-10 
利用opengl在vbnet下画线的问题最近在学用tao opengl 在vbnet下画三维坐标可是怎么也画不出线来,可以画三

利用opengl在vbnet下画线的问题
最近在学用tao opengl 在vbnet下画三维坐标

可是怎么也画不出线来,可以画三角形,矩形,多边形,就是没线,大家看下我程序,帮我分析下,
Public Class Form1
  Dim hDC As System.IntPtr
  Dim hRC As System.IntPtr

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  hDC = User.GetDC(Me.Handle)
  EnableOpenGL(hDC)
  Me.Show()
  End Sub

  Public Sub EnableOpenGL(ByVal ghDC As System.IntPtr)
  Dim pfd As Gdi.PIXELFORMATDESCRIPTOR
  Dim PixelFormat As Integer
  ZeroMemory(pfd, Len(pfd))
  pfd.Size = Len(pfd)
  pfd.Version = 1
  pfd.Flags = Gdi.PFD_DRAW_TO_WINDOW Or Gdi.PFD_SUPPORT_OPENGL Or Gdi.PFD_DOUBLEBUFFER
  pfd.PixelType = Gdi.PFD_TYPE_RGBA
  pfd.ColorBits = 32
  pfd.DepthBits = 32
  pfd.StencilBits = 32
  pfd.LayerType = Gdi.PFD_MAIN_PLANE

  PixelFormat = Gdi.ChoosePixelFormat(ghDC, pfd)
  If PixelFormat = 0 Then
  MessageBox.Show("Unable to retrieve pixel format")
  End
  End If
  If Not (Gdi.SetPixelFormat(ghDC, PixelFormat, pfd)) Then
  MessageBox.Show("Unable to set pixel format")
  End
  End If
  hRC = Wgl.wglCreateContext(ghDC)
  If hRC.ToInt32 = 0 Then
  MessageBox.Show("Unable to get rendering context")
  End
  End If
  If Not (Wgl.wglMakeCurrent(ghDC, hRC)) Then
  MessageBox.Show("Unable to make rendering context current")
  End
  End If
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  DrawScene()
  End Sub

  Private Sub DrawScene()
  Gl.glClear(Gl.GL_COLOR_BUFFER_BIT + Gl.GL_DEPTH_BUFFER_BIT)
  Gl.glViewport(0, 0, Width, Height)
  Glu.gluLookAt(0.0, 10.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0)
  Gl.glMatrixMode(Gl.GL_MODELVIEW)
  Gl.glLoadIdentity()
  Gl.glPushMatrix()
  Gl.glBegin(Gl.GL_LINE)
  Gl.glColor3f(1, 0, 0) : Gl.glVertex3f(0, 0, 0)
  Gl.glColor3f(1, 0, 0) : Gl.glVertex3f(0, 4, 0)
  Gl.glEnd()
  Gl.glBegin(Gl.GL_TRIANGLES)
  Gl.glColor3f(1, 0, 0) : Gl.glVertex3f(1, 0, 0)
  Gl.glColor3f(0, 1, 0) : Gl.glVertex3f(0, 1, 0)
  Gl.glColor3f(0, 0, 1) : Gl.glVertex3f(0, 0, 1)
  Gl.glEnd()
  Gl.glPopMatrix()
  Gl.glFlush()
  Gdi.SwapBuffers(hDC)
  End Sub

还有就是改变glViewport和gluLookAt 里的值,图形没有变化啊,不是改变眼睛的位置吗?




[解决办法]
使用过点GDI+也是简单的画。OpenGL去VC ++论坛比较多。

热点排行