vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevAniGif - als kostenlose Vollversion auf unserer vb@rchiv CD Vol.5  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

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

VB.NET - Ein- und Umsteiger
Lighting in Open TK 
Autor: argoped
Datum: 02.09.14 21:36

Hallo,
ich versuche gerade etwas mit OpenTK zu machen allerdings finde ich im Netz sehr wenig das mir das ganze klarer machen würde. Deshalb mal ein Versuch hier etwas Licht ins Dunkel zu bekommen.
1) Irgendwie klappt das mit der Beleuchtung nicht richtig. Ich hätte erwartet, dass die Dreiecke je nach Orientierung zur Lichtquelle verschieden gefärbt werden. Hier schein es so als würde die Lichtquelle mit dem Objekt mitgedreht werden. Was mache ich hier falsch?
2) Wie bekomme ich es hin, dass das Objekt noch eine Farbe mitbekommt.
Wenn ich GL.Enable(EnableCap.ColorMaterial) einschalte wird Lighting abgeschaltet!?
3) Zudem hätte ich gerne die Achsen dicker gezeichnet. Linewidth ändert nix.
Hier mein Code ich verwende ein GLControl auf der Form. Mit den Tasten x und y wird das Objekt gedreht.

Schon mal vielen Dank
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: Lighting in Open TK 
Autor: argoped
Datum: 02.09.14 21:37

Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
 
Public Class Form1
    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 += 3.6
            If e.KeyCode = Keys.X Then alpha -= 3.6
 
            GlControl1.Invalidate()
        End If
    End Sub
 
    Private Sub GlControl1_Load(sender As Object, e As EventArgs) Handles _
      GlControl1.Load
        glLoaded = True
    End Sub
 
 
    Private Sub GlControl1_Paint(sender As Object, e As PaintEventArgs) Handles _
      GlControl1.Paint
        GL.ClearColor(Color.WhiteSmoke)
        GL.Clear(ClearBufferMask.ColorBufferBit + _
          ClearBufferMask.DepthBufferBit)
 
        GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
        Dim w As Integer = GlControl1.Width
        Dim h As Integer = GlControl1.Height
 
        Dim aspect As Single = 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.CullFace)
        'GL.Disable(EnableCap.CullFace)
        GL.Enable(EnableCap.DepthTest)
        GL.DepthFunc(DepthFunction.Lequal)
 
        'Lighting
        GL.Light(LightName.Light0, LightParameter.Ambient, Color4.White)
        GL.Light(LightName.Light0, LightParameter.Diffuse, Color4.White)
        GL.Light(LightName.Light0, LightParameter.Position, (New Vector4(100, _
          100, 100, 0)))
        'GL.Light(LightName.Light0, LightParameter.SpotDirection, New Vector4( 
        ' -1, -1, -1, 0))
 
        GL.Enable(EnableCap.Light0)
        GL.Enable(EnableCap.Lighting)
        'GL.Enable(EnableCap.ColorMaterial)   '<--- schaltet Lichtberechnung ab?
        GL.ShadeModel(ShadingModel.Smooth)
        GL.Enable(EnableCap.Normalize)
 
        '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.Normal3(1, -1, 1)
        GL.Vertex3(30, 0, 0)
        GL.Vertex3(0, -30, 0)
        GL.Vertex3(0, 0, 30)
 
        GL.Normal3(-1, -1, 1)
        GL.Vertex3(-30, 0, 0)
        GL.Vertex3(0, -30, 0)
        GL.Vertex3(0, 0, 30)
 
        '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()
 
        GL.Disable(EnableCap.Lighting)
 
        'Grid ------------------------------------
        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.Color3(Color.Gray)
            GL.Vertex3(i, -100, 0)
            GL.Color3(Color.Gray)
            GL.Vertex3(i, 100, 0)
 
        Next
 
        'Axes
        GL.Disable(EnableCap.LineSmooth)
        'GL.Enable(EnableCap.LineSmooth)
        GL.LineWidth(15) '<---- macht nix?
        GL.Color3(Color.Red)
        GL.Vertex3(-80, 0, 0)
        GL.Vertex3(100, 0, 0)
 
        GL.Color3(Color.Green)
        GL.Vertex3(0, -80, 0)
        GL.Vertex3(0, 100, 0)
 
        GL.Color3(Color.Blue)
        GL.Vertex3(0, 0, -80)
        GL.Vertex3(0, 0, 100)
 
        GL.End()
 
 
        'GraphicsContext.CurrentContext.VSync = True
        GlControl1.SwapBuffers()
 
    End Sub
End Class
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

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
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: Lighting in Open TK 
Autor: argoped
Datum: 03.09.14 01:25

Option Strict Off
Dirty Code On
Jau,
Du hast den Aufruf zu LineWidth ausserhalb des GL.Begin ... GL.End eingebaut. Das war's wohl.
Damit ist Punkt 3 erledigt.

Cool, vielen Dank
Geht auch ohne die Floats
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: Lighting in Open TK 
Autor: argoped
Datum: 04.09.14 12:41

OK,
hat sich erledigt. Ist ja auch nicht wirklich eine VB Frage.
aber trotzdem Danke
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

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-2024 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