Mit OpenTK habe ich mal in C# für 2D-Grafik ein paar Quads texturiert.
Dazu brauchte ich keine Beleuchtung.
Das Control wird hier zur Laufzeit eingefügt.
Zumindest Punkt 3 sollte funktionieren.
Option Strict On
Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Public Class Form1
Dim WithEvents GlControl1 As New OpenTK.GLControl With {.Dock = _
DockStyle.Fill, .Parent = Me}
Dim camX As Single = 200
Dim camY As Single = 200
Dim camZ As Single = 150
Dim ox As Single = 0
Dim oy As Single = 0
Dim alpha As Single = 0
Dim glLoaded As Boolean = False
Private Sub GlControl1_KeyDown(sender As Object, e As KeyEventArgs) Handles _
GlControl1.KeyDown
If glLoaded Then
If e.KeyCode = Keys.D Then ox += 5
If e.KeyCode = Keys.A Then ox -= 5
If e.KeyCode = Keys.W Then oy += 5
If e.KeyCode = Keys.S Then oy -= 5
If e.KeyCode = Keys.Y Then alpha = CSng(alpha + 3.6)
If e.KeyCode = Keys.X Then alpha = CSng(alpha - 3.6)
GlControl1.Invalidate()
End If
End Sub
Private Sub GlControl1_Load(sender As Object, e As EventArgs) Handles _
GlControl1.Load
glLoaded = True
Me.ClientSize = New Size(1024, 768)
GlControl1.VSync = True
End Sub
Private Sub GlControl1_Paint(sender As Object, e As PaintEventArgs) Handles _
GlControl1.Paint
GL.ClearColor(Color.Black)
GL.Clear(CType(ClearBufferMask.ColorBufferBit + _
ClearBufferMask.DepthBufferBit, ClearBufferMask))
GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
Dim w As Integer = GlControl1.Width
Dim h As Integer = GlControl1.Height
Dim aspect As Single = CSng(w / h)
Dim persp As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(0.45, _
aspect, 0.1, 10000)
Dim lookat As Matrix4 = Matrix4.LookAt(camX, camY, camZ, 0, 0, 0, 0, 0, _
1)
Dim sw As Stopwatch = New Stopwatch
GL.MatrixMode(MatrixMode.Projection)
GL.LoadIdentity()
GL.LoadMatrix(lookat * persp)
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
GL.Translate(ox, oy, 0)
GL.Rotate(alpha, Vector3.UnitZ)
GL.Enable(EnableCap.DepthTest)
GL.Light(LightName.Light0, LightParameter.Ambient, Color4.White)
GL.Enable(EnableCap.Light0)
GL.Enable(EnableCap.Lighting)
GL.Enable(EnableCap.ColorMaterial)
GL.ShadeModel(ShadingModel.Smooth)
'Drawing Objects -----------------------------
GL.Begin(PrimitiveType.Triangles)
GL.Color3(Color.Blue)
GL.Normal3(1, 1, 1)
GL.Vertex3(30, 0, 0)
GL.Vertex3(0, 30, 0)
GL.Vertex3(0, 0, 30)
GL.Color3(Color.Red)
GL.Normal3(1, -1, 1)
GL.Vertex3(30, 0, 0)
GL.Vertex3(0, -30, 0)
GL.Vertex3(0, 0, 30)
GL.Color3(Color.Green)
GL.Normal3(-1, -1, 1)
GL.Vertex3(-30, 0, 0)
GL.Vertex3(0, -30, 0)
GL.Vertex3(0, 0, 30)
GL.Color3(Color.Yellow)
GL.Normal3(-1, 1, 1)
GL.Vertex3(-30, 0, 0)
GL.Vertex3(0, 30, 0)
GL.Vertex3(0, 0, 30)
GL.End()
GL.MatrixMode(MatrixMode.Modelview)
GL.LoadIdentity()
'Grid ------------------------------------
GL.LineWidth(1.0F)
GL.Begin(PrimitiveType.Lines)
For i = -100 To 100 Step 10
GL.Color3(Color.Gray)
GL.Vertex3(-100, i, 0)
GL.Color3(Color.Gray)
GL.Vertex3(100, i, 0)
GL.Vertex3(i, -100, 0)
GL.Color3(Color.Gray)
GL.Vertex3(i, 100, 0)
Next
GL.End()
' Die 3 Achsen-----------------------------
GL.LineWidth(3.0F)
GL.Begin(PrimitiveType.Lines)
GL.Color3(Color.Red)
GL.Vertex3(-100, 0, 0)
GL.Vertex3(100, 0, 0)
GL.Color3(Color.Green)
GL.Vertex3(0, -100, 0)
GL.Vertex3(0, 100, 0)
GL.Color3(Color.Blue)
GL.Vertex3(0, 0, -100)
GL.Vertex3(0, 0, 100)
GL.End()
GlControl1.SwapBuffers()
End Sub
End Class MfG GPM 0 |