Bonjour,
j'essaye laborieusement d'utiliser Open GL avec VB.NET
Après des essais infructueux avec OpenTK et Sharpgl je me suis tourné vers CsGL ; ça tombe bien ils montrent un exemple en VB.NET : http://www.windowsdevcenter.com/pub/...gl.html?page=1
Mais je n'y arrive pas ; j'ai deux erreurs :
etMe.view.Dock = DockStyle.Fill => L'exeption System.TypeInitializationException s'est produite - Une exception a été levée par l'initialiseur de type pour 'CsGL.OSLib'.
C'est très frustrant... des tas d'appli utilisent OpenGL, y compris en VB.NET, mais quand les sources sont disponibles je n'arrive pas à les ouvrir ou l’exécution sur mon PC (en VB.NET 2010 ou .NET 2015) planteMe.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éé.
Étonnant sur le net on trouve beaucoup de sources montrant comment utiliser OpenGL en VB6.
Merci pour votre aide.
Voici le code de la form :
et celui de son designer (j'ai modifié une ligne marquée par '***)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Visu3D Inherits System.Windows.Forms.Form 'Form remplace la méthode Dispose pour nettoyer la liste des composants. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) Me.thrOpenGL.Abort() '*** End Try End Sub 'Requise par le Concepteur Windows Form Private components As System.ComponentModel.IContainer 'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form 'Elle peut être modifiée à l'aide du Concepteur Windows Form. 'Ne la modifiez pas à l'aide de l'éditeur de code. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.SuspendLayout() ' 'Visu3D ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(627, 519) Me.Name = "Visu3D" Me.Text = "Visu3D" Me.ResumeLayout(False) End Sub End Class
Partager