1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| Imports CsGL.OpenGL
Public Class Visu3D
Inherits System.Windows.Forms.Form
Private view As myOpenGL.myView
Private thrOpenGL As Threading.Thread
Public Sub New()
InitializeComponent()
Me.view = New myOpenGL.myView()
Me.view.Parent = Me
'Me.view.Dock = DockStyle.Fill 'DECLENCHE UNE ERREUR :
' L'exeption System.TypeInitializationException s'est produite - Une exception a été levée par l'initialiseur de type pour 'CsGL.OSLib'.
Me.thrOpenGL = New Threading.Thread(AddressOf Me.OpenGL_Start)
Me.thrOpenGL.Start()
End Sub
Private Sub OpenGL_Start()
While 1 = 1
Me.view.Refresh() 'Opération inter-threads non valide : le contrôle '' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.
End While
End Sub
End Class
Namespace myOpenGL
Public Class myView
Inherits OpenGLControl
Private Enum GLConstants
GL_COLOR_BUFFER_BIT = &H4000
GL_DEPTH_BUFFER_BIT = &H100
GL_SMOOTH = &H1D01
GL_DEPTH_TEST = &HB71
GL_LEQUAL = &H203
GL_PERSPECTIVE_CORRECTION_HINT = &HC50
GL_NICEST = &H1102
GL_PROJECTION = &H1701
GL_MODELVIEW = &H1701
GL_POLYGON = &H9
End Enum
Public Overrides Sub glDraw()
GL.glClearColor(0.0, 0.0, 0.0, 0.0)
GL.glClear( _
Convert.ToUInt32( _
GLConstants.GL_COLOR_BUFFER_BIT Or _
GLConstants.GL_DEPTH_BUFFER_BIT))
GL.glLoadIdentity()
'
' Fun begins
'
GL.glColor3f(1.0, 1.0, 1.0)
GL.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0)
GL.glBegin(Convert.ToUInt32(GLConstants.GL_POLYGON))
GL.glVertex3f(0.25, 0.25, 0.0)
GL.glVertex3f(0.75, 0.25, 0.0)
GL.glVertex3f(0.75, 0.75, 0.0)
GL.glVertex3f(0.25, 0.75, 0.0)
GL.glEnd()
GL.glFlush()
'
End Sub
Protected Overrides Sub InitGLContext()
GL.glShadeModel(Convert.ToUInt32(GLConstants.GL_SMOOTH))
GL.glClearColor(0.0, 0.0, 0.0, 0.5)
GL.glClearDepth(1.0)
GL.glEnable(Convert.ToUInt32(GLConstants.GL_DEPTH_TEST))
GL.glDepthFunc(Convert.ToUInt32(GLConstants.GL_LEQUAL))
GL.glHint( _
Convert.ToUInt32( _
GLConstants.GL_PERSPECTIVE_CORRECTION_HINT), _
Convert.ToUInt32(GLConstants.GL_NICEST))
End Sub
Protected Overloads Sub OnSizeChanged(ByVal e As Object)
Me.OnSizeChanged(e)
Dim s As Size
Dim aspect_ratio As Double
s = Me.Size
aspect_ratio = s.Width / s.Height
GL.glMatrixMode(Convert.ToUInt32(GLConstants.GL_PROJECTION))
GL.glLoadIdentity()
GL.gluPerspective(45.0, aspect_ratio, 0.1, 100.0)
GL.glMatrixMode(Convert.ToUInt32(GLConstants.GL_MODELVIEW))
GL.glLoadIdentity()
End Sub
Protected Sub myView_OnKeyDown(ByVal Sender As Object, _
ByVal kea As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown
If (kea.KeyCode = Keys.Escape) Then
Application.Exit()
End If
End Sub
End Class
End Namespace |
Partager