vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
SEPA-Dateien erstellen inkl. IBAN-, BLZ-/Kontonummernprüfung  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Re: Lighting in Open TK 
Autor: GPM
Datum: 03.09.14 00:08

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
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Lighting in Open TK1.871argoped02.09.14 21:36
Re: Lighting in Open TK1.632argoped02.09.14 21:37
Re: Lighting in Open TK1.809GPM03.09.14 00:08
Re: Lighting in Open TK1.374argoped03.09.14 01:25
Re: Lighting in Open TK1.376argoped04.09.14 12:41

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel