vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevDataGrid - Gönnen Sie Ihrem SQL-Kommando diesen krönenden Abschluß!  
 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: 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
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Lighting in Open TK1.871argoped02.09.14 21:36
Re: Lighting in Open TK1.633argoped02.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.377argoped04.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