0

I'm looking at the GtkGL tutorial here, and I'm doing some modifications. Specifically, when I introduce a rotation:

Gtk.timeoutAddFull (do
      preservingMatrix $ do -- from here
        matrixMode $= Modelview 0
        rotate 10 (Vector3 0.0 1.0 (0.0 :: GLfloat)) -- to here
      Gtk.widgetQueueDraw canvas
      return True)
    Gtk.priorityDefaultIdle animationWaitTime

It works nicely. However, when I introduce a lookAt in the display function:

display = do
  loadIdentity
  color (Color3 1 1 1 :: Color3 GLfloat)

  renderPrimitive Polygon $ do
    vertex (Vertex3 0.0 0.0 0.0 :: Vertex3 GLfloat)
    vertex (Vertex3 1.0 0.0 0.0 :: Vertex3 GLfloat)
    vertex (Vertex3 1.0 1.0 0.0 :: Vertex3 GLfloat)
    vertex (Vertex3 0.0 1.0 0.0 :: Vertex3 GLfloat)

  preservingMatrix $ do -- from here
    matrixMode $= Modelview 0
    loadIdentity
    lookAt (Vertex3 0 1 0) (Vertex3 1 1 0) (Vector3 0 1 0) -- to here
  flush

The camera changes its position, but the rotation does not happen.

guaraqe
  • 249
  • 1
  • 7
  • if you look at your code the first thing you do is `loadIdentity` - this will reset your camera - sadly I don't know to much about GtkGl but you have to either do the `rotate 10 ...` again or somehow reload the current transformation/camera – Random Dev Oct 09 '14 at 05:04
  • PS: as you don't need the `loadIdentity` in your first code you can maybe just remove it` – Random Dev Oct 09 '14 at 05:05
  • I tried to remove the loadIdentity, but all that happened was a black screen. Is there something about OpenGL that actions can only be made at some kind of matrixMode? – guaraqe Oct 09 '14 at 14:28
  • I was able to make what I wanted by implementing myself a lookAt, so the code works, but I still do not understand the problem. Thanks! – guaraqe Oct 10 '14 at 20:09

0 Answers0