• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

How to call native GLFW functions? [SOLVED]

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
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?.

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:
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:
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.

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:
Back
Top Bottom