flat assembler
Message board for the users of flat assembler.

Index > Linux > GLFW example

Thread Post new topic Reply to topic

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.

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

        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]
        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
        lea     rdi,[emsg]
        xor     eax,eax
        call    [printf]
        call    [glfwTerminate] 
        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
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.