Skip to content

Hello World Tutorial

Stefan Maierhofer edited this page Feb 3, 2017 · 4 revisions

Getting started

Clone the aardvark.docs repository and run build to install all packages:

> git clone https://github.com/aardvarkplatform/aardvark.docs.git
> cd aardvark.docs
> build

Open the source code in your favorite editor. In this tutorial we use Visual Studio Code:

> code . src\HelloWorld\Program.fs

Idea

Render colored cubes arranged in a three-dimensional grid and add simple mouse navigation. This will teach us how to

  • setup a render application
  • deal with colors
  • create geometric primitives
  • specify a scene graph
  • use default shaders
  • use default camera controllers

and how to put everything together.

Implementation

Runtime system and render application

Always initialize Aardvark's runtime system before doing anything else!!!

Ag.initialize(); Aardvark.Init()

Next, we create an OpenGL-based application and a simple render window.

use app = new OpenGlApplication()
let win = app.CreateSimpleRenderWindow()
win.Text <- "Hello World (aardvark.docs)"
// view and projection and default camera controllers
let initialView = CameraView.lookAt (V3d(9.3, 9.9, 8.6)) V3d.Zero V3d.OOI
let view = initialView |> DefaultCameraController.control win.Mouse win.Keyboard win.Time
let proj = win.Sizes |> Mod.map (fun s -> Frustum.perspective 60.0 0.1 1000.0 (float s.X / float s.Y))

Colors and boxes

// generate 11 x 11 x 11 colored boxes
let norm x = (x + 5.0) * 0.1
let boxes = seq {
    for x in -5.0..5.0 do
        for y in -5.0..5.0 do
            for z in -5.0..5.0 do
                let bounds = Box3d.FromCenterAndSize(V3d(x, y, z), V3d(0.5, 0.5, 0.5))
                let color = C4b(norm x, norm y, norm z)
                yield Sg.box' color bounds
}

Scene

let sg =
    boxes
        |> Sg.group
        |> Sg.effect [
            DefaultSurfaces.trafo |> toEffect
            DefaultSurfaces.vertexColor |> toEffect
            DefaultSurfaces.simpleLighting |> toEffect
           ]
        |> Sg.viewTrafo (view |> Mod.map CameraView.viewTrafo)
        |> Sg.projTrafo (proj |> Mod.map Frustum.projTrafo)

Run

// specify render task
let task =
    app.Runtime.CompileRender(win.FramebufferSignature, sg)
        |> DefaultOverlays.withStatistics

// start
win.RenderTask <- task
win.Run()
Clone this wiki locally
You can’t perform that action at this time.