flat assembler
Message board for the users of flat assembler.

Index > Linux > GLFW example

Author
Thread Post new topic Reply to topic
stefano



Joined: 27 Feb 2020
Posts: 1
stefano 29 Feb 2020, 14:05
I just wrote my first ELF64 file that uses GLFW to create a window Smile
I used as a template the example included with fasm located at './examples/elfexe/dynamic/hello64.asm' and used as reference the example code available at https://www.glfw.org/documentation.html.

Code:
format ELF64 executable 3
entry start

include 'import64.inc'

interpreter '/lib64/ld-linux-x86-64.so.2'
needed 'libc.so.6'
needed 'libGL.so'
needed 'libglfw.so'
import printf,exit,glfwInit,glfwCreateWindow,glfwTerminate,glfwMakeContextCurrent,glfwWindowShouldClose,glClear,glfwSwapBuffers,glfwPollEvents

segment readable executable

start:
        call    [glfwInit]
        cmp     rax,1
        jne     error
        mov     r8,0
        mov     rcx,0
        lea     rdx,[msg]
        mov     rsi,480
        mov     rdi,640
        call    [glfwCreateWindow]
        cmp     rax,0
        je      error
        mov     [window], rax   
        mov     rdi,[window]
        call    [glfwMakeContextCurrent]
waitforclose:
        mov     rdi,[window] ;when using "lea" glfwWindowShouldClose always returned 0
        call    [glfwWindowShouldClose]
        cmp     rax,0
        jne     terminate
        mov     rdi,16384 ;GL_COLOR_BUFFER_BIT
        call    [glClear]
        mov     rdi,[window]
        call    [glfwSwapBuffers]
        call    [glfwPollEvents]
        jmp     waitforclose
error:
        lea     rdi,[emsg]
        xor     eax,eax
        call    [printf]
terminate:
        call    [glfwTerminate] 
quit:
        call    [exit]

segment readable writeable

msg db 'a window',0
emsg db 'error',0xa,0
window dq ?
    


I tried the X11 examples available in the forum but I was getting "segmentation fault" related to 'libxcb.so' and I couldn't identify the issue. That's why I decided to try with that example once I understood what I had to do.

Thanks to the videos that Tomasz uploaded to Youtube I've been able to understand a lot of things that I hadn't until now. I hope he keeps uploading new content!

Any feedback about the code is appreciated. It helps me to learn something new and understand better what's going on Laughing

Edit by revolution: Fix documentation link
Post 29 Feb 2020, 14:05
View user's profile Send private message Reply with quote
april.asm



Joined: 10 Nov 2025
Posts: 3
Location: Hell
april.asm 10 Nov 2025, 18:46
This is pretty cool
Post 10 Nov 2025, 18:46
View user's profile Send private message Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 360
Location: Poland
macgub 11 Nov 2025, 17:25
I compile and try execute above. I get failed when I run it.Gdb tells me: error while loading shared libraries: libglfw.so: cannot open shared object file: No such file or directory. I tried install missing files but get troubles with correctly specifying appropriate libs. This time Software manager wasn't helpful.
I search for best way to supply libs which are needed. I use Mint Mint 22 Wilma.
Post 11 Nov 2025, 17:25
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1199
Location: Russia
macomics 11 Nov 2025, 20:46
I also tried this example on Calculate Linux. I needed to add media-libs/glfw via emerge and everything worked.

The green background is not a mistake. I just added glClearColor(0.0f, 1.0f, 0.0f, 1.0f);


Description:
Filesize: 74.77 KB
Viewed: 123 Time(s)

Снимок экрана_20251112_004408.png


Post 11 Nov 2025, 20:46
View user's profile Send private message Reply with quote
chastitywhiterose



Joined: 13 Oct 2025
Posts: 27
chastitywhiterose 13 Nov 2025, 04:16
I have done a little bit of OpenGL from the C interface. I could do legacy OpenGL but not the modern core stuff. But seeing your post led me to the idea that theoretically when using something open source like GLFW, the Assembly code would be mostly portable between Linux and Windows as long as they were both running on Intel CPUs.
Post 13 Nov 2025, 04:16
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.