Cogni's picture

Do we have/need a glutPostRedisplay() and a glutIdleFunc() ?


I am starting to learn OpenGL and OpenTK by working some examples from the OpenGL Red book. I'm still on Chapter 1!

In Example 1-3 at there is a call to glutPostRedisplay(). The closest I can find is to invalidate the graphics context if using Windows, but I am on Ubuntu. Is this call necessary?

Also, I do not know where to put the code to spin the rectangle because I cannot find an equivalent to glutIdleFunc(), so I have no mouse input coded yet.

Here is my code with comments where I am confused. How am I doing with my use of OpenTK and how do I find those functions or work around not having them? Oh, by the way, it's in F#.

open System
open System.Drawing
open System.Collections.Generic
open OpenTK
open OpenTK.Graphics
open OpenTK.Graphics.OpenGL
open OpenTK.Input
namespace Redbook.Double
type OTKWin() =
  inherit GameWindow(250, 250, GraphicsMode.Default, "Red Book Example 1-3")
  let mutable rectSpin = 0.f
  let rectSpinIncrement = 2.f
  do base.VSync <- VSyncMode.On
  member self.SpinRect =
    rectSpin <- rectSpin + rectSpinIncrement
    if rectSpin > 360.f then rectSpin <- rectSpin - 360.f
    // I want to glutPostRedisplay here, (I think!)
  override self.OnLoad e =
    base.OnLoad e
    GL.ClearColor(0.f, 0.f, 0.f, 0.f)
  override self.OnRenderFrame(e) =
    base.OnRenderFrame e
    self.SpinRect  // This shouldn't be here, but I just wanted to see something happen :-)
    GL.Rotate(rectSpin, 0.f, 0.f, 1.f)
    GL.Color3(1.f, 1.f, 1.f)
    GL.Rect(-25.f, -25.f, 25.f, 25.f)
  override self.OnResize e =
    base.OnResize e
    GL.Viewport(base.ClientRectangle.X, base.ClientRectangle.Y,
                base.ClientRectangle.Width, base.ClientRectangle.Height)
    GL.Ortho(-50., 50., -50., 50., -1., 1.)
  override self.OnUpdateFrame e =
    base.OnUpdateFrame e
    if base.Keyboard.[Key.Escape] then base.Close()
let main _ =
  let win = new OTKWin()
  do win.Run(30.)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Cogni's picture

Ubuntu 12.04.2 LTS
Pentium(R) Dual-Core @2.93 GHz - 64 bit width - 4 GB RAM
NVIDIA GeForce 9500 GT (rev a1)
OpenTK 2010-10-06

That was supposed to be my automatic signature. Didn't work. (Sorry, first post here.)