How to call native GLFW functions? [SOLVED]

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
GLFW is not my strong side here as a webdeveloper, and this gives me a "TRANS FAILED: Error executing 'xcodebuild -configuration Release', return code=16640".

Note that this is not about *what* it's doing (there might be simpler ways) it's about me trying to practice on how to do native things with Cerberus Desktop, having some fun learning new things.

What am I doing wrong here? I use Mojo1 for a while here for an exprimental thing, but Mojo2 gives me the same results.
It complains "TRANS FAILED: Error executing 'xcodebuild -configuration Release', return code=16640", and I get the exact same message in debg and release mode?.

code_language.cerberus:
Strict
#GLFW_WINDOW_TITLE = "my dynamic game title"

Import mojo

Extern
    Function UpdateGlfwWindowTitle:Void() = "glfwSetWindowTitle(_STRINGIZE(CFG_GLFW_WINDOW_TITLE));"
Public

Function Main:Int()
    New MojoApp
    Return 0
End

Class MojoApp Extends App

    Method OnCreate:Int()
        SetUpdateRate 0
        UpdateGlfwWindowTitle()
        Return 0
    End

    Method OnUpdate:Int()
        If KeyHit(KEY_ESCAPE) Then EndApp
        Return 0
    End

    Method OnRender:Int()
        Cls
        Return 0
    End
End
 
Last edited:

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
795
You are trying to bind C++ code as a function. You'll need to create a wrapper in C++ to set the window title and then define the Cerberus function prototype like:
UpdateGlfwWindowTitle:Void( title:String ) = "UpdateGlfwWindowTitle( String title )"

The definition for the GLFW glfwSetWindowTitle is
void glfwSetWindowTitle( GLFWwindow* window, cost char* title )

This means that the first parameter requires a pointer to a GLFW window object, i.e. the main applications window.
The second parameter requires that the string to be passed is a pointer to a string of type char. Usually a string literal or constant character array.

If you go through the build log. You will see an error like this:

error: cannot convert ‘const char*’ to ‘GLFWwindow*’

Caution: If I remember the pointer to the GLFW window implementation in Cerebeus is a private data member.
 
Last edited:

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
Thanks! This got me going. I tried with window position for starters
I think I found the private data member : BBGlfwGame::GlfwGame()->GetGLFWwindow()

This example works, at least it's a step in the right direction, kinda fun to be able to have this amazing language on one end, and then still have everything that exists in the "professional" programming world, I have to say. I'm not sure If I need to use this a lot but its nice to know it's there, 5 minutes away.

code_language.cerberus:
Strict
Import mojo2

' -------------------------------------------------
' NATIVE CODE EXAMPLE

Import "commands.cpp"
Extern

Function SetWindowPosition:Void(X:Int, Y:Int) = "commands::setWindowPosition"
Public
' -------------------------------------------------

Function Main:Int()
    New Application()
    Return 0
End

Class Application Extends App Final
  
  
    Field canvas:Canvas
  
    Method OnCreate:Int()
        canvas = New Canvas()
        SetUpdateRate 0
        SetWindowPosition(128,128)
        Return 0
    End
  
    Method OnUpdate:Int()
        If KeyHit(KEY_ESCAPE) Then
            OnClose()  
            Return 0
        Endif      
      
        Return 0
    End
  
    Method OnRender:Int()
        canvas.Clear
        canvas.DrawText "We've just executed a native command that we'd defined for ourselves!",0,0
        canvas.Flush
        Return 0
    End
End

[CODE lang="cpp" title="commands.cpp"]namespace commands
{
// ------------------------------------------------------------------
void setWindowPosition(int X, int Y)
{
glfwSetWindowPos(BBGlfwGame::GlfwGame()->GetGLFWwindow(), X, Y);
return;
}
// ------------------------------------------------------------------
}[/CODE]
 
Last edited:
Top Bottom