Page 1 of 1

datatypes, I give up.

PostPosted: Thu Mar 11, 2010 3:23 pm
by fictiveLaark
I have the following openGL code translated from C#. To run it you need to reference OpenTK.dll which you can get from http://www.opentk.com. I seem to be spinning my wheels at GL.rotate, no matter what I do cobra says I'm not passing the right data type, I even think that at one point I managed to do what cobra asked and it started asking for a different datatype. Here is the error from the following code.

C:\Cobra\HowTo>cobra -library-directory:C:\opentk\bin -reference:OpenTK.dll TK.c
obra
TK.cobra(1): warning: The using directive for "System" appeared previously in th
is namespace
TK.cobra(44): error: The best overloaded method match for "OpenTK.Graphics.OpenG
L.GL.Rotate(float, OpenTK.Vector3)" has some invalid arguments
TK.cobra(44): error: Argument "1": cannot convert from "double" to "float"
TK.cobra(47): error: The best overloaded method match for "OpenTK.Graphics.OpenG
L.GL.Vertex2(double, double)" has some invalid arguments
TK.cobra(47): error: Argument "1": cannot convert from "decimal" to "double"
TK.cobra(47): error: Argument "2": cannot convert from "decimal" to "double"
TK.cobra(48): error: The best overloaded method match for "OpenTK.Graphics.OpenG
L.GL.Vertex2(double, double)" has some invalid arguments
TK.cobra(48): error: Argument "1": cannot convert from "decimal" to "double"
TK.cobra(48): error: Argument "2": cannot convert from "decimal" to "double"
TK.cobra(49): error: The best overloaded method match for "OpenTK.Graphics.OpenG
L.GL.Vertex2(double, double)" has some invalid arguments
TK.cobra(49): error: Argument "1": cannot convert from "decimal" to "double"
TK.cobra(49): error: Argument "2": cannot convert from "decimal" to "double"
TK.cobra(50): error: The best overloaded method match for "OpenTK.Graphics.OpenG
L.GL.Vertex2(double, double)" has some invalid arguments
TK.cobra(50): error: Argument "1": cannot convert from "decimal" to "double"
TK.cobra(50): error: Argument "2": cannot convert from "decimal" to "double"
Compilation failed - 14 errors, 1 warning
Not running due to errors above.

Code: Select all
use System
use OpenTK
use OpenTK.Graphics.OpenGL
use OpenTK.Graphics

class Test
   def main is shared
      window = TestWindow()
      window.run

class TestWindow
   inherits GameWindow
   var _rotation as float

   cue init
      base.init(800, 800, GraphicsMode(ColorFormat(32)), "Test")
   
   def onLoad(e as EventArgs) is protected, override
      GL.shadeModel(ShadingModel.Smooth)
      GL.clearColor(0, 0, 0, 1)
      GL.clearDepth(1)
      GL.enable(EnableCap.DepthTest)
      GL.depthFunc(DepthFunction.Lequal)
      GL.hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest)
         
      GL.viewport(0, 0, 800, 800)
      GL.matrixMode(MatrixMode.Projection)
        GL.loadIdentity
      GL.ortho(0, 10, 10, 0, -10, 10)
         
      GL.matrixMode(MatrixMode.Modelview)
      GL.loadIdentity
      
   def onUpdateFrame(e as FrameEventArgs) is protected, override
      _rotation += 50*e.time
      
   def onRenderFrame(e as FrameEventArgs) is protected, override
      GL.clear(ClearBufferMask.ColorBufferBit)
      GL.clear(ClearBufferMask.DepthBufferBit)
         
      GL.matrixMode(MatrixMode.Modelview)
      GL.loadIdentity
      GL.translate(Vector3(5, 5, 0))
      GL.rotate(_rotation, Vector3(0, 1, 1))
      GL.begin(BeginMode.Quads)
      GL.color3(Vector3(0, 0, 1))
      GL.vertex2(-2.5, -2.5)
      GL.vertex2(-2.5, 2.5)
      GL.vertex2(2.5, 2.5)
      GL.vertex2(2.5, -2.5)
      GL.end
         
      .context.swapBuffers

Re: datatypes, I give up.

PostPosted: Thu Mar 11, 2010 7:01 pm
by Charles
Sorry for the frustration. Fortunately, the fixes are fairly easy once you know what they are.

The primary thing is to tell Cobra to use float64 as the default numeric type--Cobra defaults to decimal. Put this at the top:

@number float64

Also, I had to change "Vector3" to "Vector3d" in response to one of the compilation errors:

GL.rotate(_rotation, Vector3d(0, 1, 1))

Also, if you use the latest Cobra source, it will complain that the EventArgs parameters need to be nilable (e.g. EventArgs?) since they are nilable in the base methods being overridden.

The last two errors were easy fixes, but clearly there is no good help nor hint for the first problem. I'll think more about how to make it clear. Here is the complete source that I got to compile:
@number float64  # <-- added

use OpenTK
use OpenTK.Graphics.OpenGL
use OpenTK.Graphics

class Test

def main
window = TestWindow()
window.run

class TestWindow inherits GameWindow

var _rotation as float

cue init
base.init(800, 800, GraphicsMode(ColorFormat(32)), "Test")

def onLoad(e as EventArgs?) is protected, override
GL.shadeModel(ShadingModel.Smooth)
GL.clearColor(0, 0, 0, 1)
GL.clearDepth(1)
GL.enable(EnableCap.DepthTest)
GL.depthFunc(DepthFunction.Lequal)
GL.hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest)

GL.viewport(0, 0, 800, 800)
GL.matrixMode(MatrixMode.Projection)
GL.loadIdentity
GL.ortho(0, 10, 10, 0, -10, 10)

GL.matrixMode(MatrixMode.Modelview)
GL.loadIdentity

def onUpdateFrame(e as FrameEventArgs?) is protected, override
_rotation += 50*e.time

def onRenderFrame(e as FrameEventArgs?) is protected, override
GL.clear(ClearBufferMask.ColorBufferBit)
GL.clear(ClearBufferMask.DepthBufferBit)

GL.matrixMode(MatrixMode.Modelview)
GL.loadIdentity
GL.translate(Vector3(5, 5, 0))
GL.rotate(_rotation, Vector3d(0, 1, 1)) # <-- changed to Vector3d
GL.begin(BeginMode.Quads)
GL.color3(Vector3(0, 0, 1))
GL.vertex2(-2.5, -2.5)
GL.vertex2(-2.5, 2.5)
GL.vertex2(2.5, 2.5)
GL.vertex2(2.5, -2.5)
GL.end

.context.swapBuffers

Re: datatypes, I give up.

PostPosted: Fri Mar 12, 2010 2:29 am
by Charles
I have enhanced the Cobra compiler to detect the situation you ran into and make the @number suggestion via a warning. It would now say:

warning: An above error about numeric types indicates that you may want to set the default numeric type with "@number float" in a source file or "cobra -number:float" at the command line.

Re: datatypes, I give up.

PostPosted: Sat Mar 13, 2010 8:41 pm
by Charles
fictiveLaark, are you good now?

The code I reposted compiles and even runs on Mac+Mono.

Re: datatypes, I give up.

PostPosted: Tue Mar 16, 2010 3:16 am
by fictiveLaark
Yes, I'm good, although I found my own solution in the time it took my post to be approved. But it looks like my post may have lead to some improvement in the compiler.=)

Code: Select all
use System
use OpenTK
use OpenTK.Graphics.OpenGL
use OpenTK.Graphics

class Test
   def main is shared
      window = TestWindow()
      window.run

class TestWindow
   inherits GameWindow
   var _rotation as float32

   cue init
      base.init(800, 800, GraphicsMode(ColorFormat(32)), "Test")
   
   def onLoad(e as EventArgs) is protected, override
      GL.shadeModel(ShadingModel.Smooth)
      GL.clearColor(0, 0, 0, 1)
      GL.clearDepth(1)
      GL.enable(EnableCap.DepthTest)
      GL.depthFunc(DepthFunction.Lequal)
      GL.hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest)
         
      GL.viewport(0, 0, 800, 800)
      GL.matrixMode(MatrixMode.Projection)
        GL.loadIdentity
      GL.ortho(0, 10, 10, 0, -10, 10)
         
      GL.matrixMode(MatrixMode.Modelview)
      GL.loadIdentity
      
   def onUpdateFrame(e as FrameEventArgs) is protected, override
      _rotation += 50*(e.time to float32)
      
   def onRenderFrame(e as FrameEventArgs) is protected, override
      GL.clear(ClearBufferMask.ColorBufferBit)
      GL.clear(ClearBufferMask.DepthBufferBit)
         
      GL.matrixMode(MatrixMode.Modelview)
      GL.loadIdentity
      GL.translate(Vector3(5, 5, 0))
      GL.rotate(_rotation, Vector3(0, 1, 1))
      GL.begin(BeginMode.Quads)
      GL.color3(Vector3(0, 0, 1))
      GL.vertex2(-2.5 to float, -2.5 to float)
      GL.vertex2(-2.5 to float, 2.5 to float)
      GL.vertex2(2.5 to float, 2.5 to float)
      GL.vertex2(2.5 to float, -2.5 to float)
      GL.end
         
      .context.swapBuffers

Re: datatypes, I give up.

PostPosted: Tue Mar 16, 2010 3:33 am
by Charles
Cool.

FYI only the first post by a user is held for approval. All your subsequent posts will go straight through. We need this due to spammers.