flat assembler
Message board for the users of flat assembler.
Index
> Linux > GLFW example |
| Author |
|
|
stefano 29 Feb 2020, 14:05
I just wrote my first ELF64 file that uses GLFW to create a window
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 Edit by revolution: Fix documentation link |
|||
|
|
april.asm 10 Nov 2025, 18:46
This is pretty cool
|
|||
|
|
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);
|
||||||||||
|
||||||||||
|
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.
|
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.