Hi, have you tried something like :

1
2
3
4
5
6
7
8
9
10
let Keyboard(key:byte, x, y) =


  if x < 0 then invalidArg "x" "Keyboard(...) : x < 0 "


  if y < 0 then invalidArg "y" "Keyboard(...) : y < 0 "


  printfn "byte received : %A" key

with the arguments between parenthesis ?

By on 9/2/2009 6:15 AM ()

Yep and I get this error, btw I'm using Microsoft Visual Studio 2010 beta.

Error: Type mismatch. Expecting a byte -> int -> int -> unit but given a byte * int * int -> unit. The type 'byte' does not match the type 'byte * int * int'

By on 9/2/2009 6:46 AM ()

Yep and I get this error, btw I'm using Microsoft Visual Studio 2010 beta.

Error: Type mismatch. Expecting a  byte -> int -> int -> unit but given a  byte * int * int -> unit. The type 'byte' does not match the type 'byte * int * int'

I've never used Glut, so I can't speak to your larger issue. But the error your seeing is due to the way a function is declared versus the way a function is called. Specifically:

1
2
foo : byte -> int -> int -> unit

means

1
2
let foo a b c = ()

meanwhile

1
2
foo : byte * int * int -> unit

means

1
2
let foo (a,b,c) = ()

Please note the use of commas to construct one parameter--a tuple--versus the spaces, which indicate three separate parameters.

By on 9/2/2009 7:34 AM ()

Thanks pblasucci,

You've helped claify something I didn't get before, plus you also helped fix it. Again, thanks. [:)]

Just needed to use...

let keyboardCallback(key : byte) x y =

// ... display callback code

I'll post the working code below for anyone else wishing to use Glut with F#.

[Corrected F# Code]

#light

open Tao.OpenGl

open Tao.FreeGlut


let displayCallback() =

Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f)
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)
Gl.glLoadIdentity()
Glut.glutSwapBuffers()

let keyboardCallback(key : byte) x y =

// '27' is the decimal ASCII code for the ESCAPE key.
// 'byte' prefix is used to convert the '27' int literal to a byte.
// 'uy' byte suffix as in '27uy' works just as well though.

if key = byte 27
then Glut.glutLeaveGameMode() |> ignore

// Main Program

Glut.glutInit()

Glut.glutGameModeString("1440x900:32@60")

Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE)

Glut.glutEnterGameMode() |> ignore

Glut.glutDisplayFunc(new Glut.DisplayCallback(displayCallback))
Glut.glutKeyboardFunc(new Glut.KeyboardCallback(keyboardCallback))

By on 9/2/2009 9:18 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper