I'm probably the worst person to be giving advice on this topic since I haven't updated to 64-bit systems and I tend to avoid game/graphics programming... however, from what I've read on the subject, you need to make sure that there is enough space on the stack for all 4 registers (even if you don't use them) for compatibility with "unprototyped functions" and vararg C/C++ functions. My modified version of your code simply provides this space... I don't have a 64-bit system to try this on, so let me know if it works.
; ----------------------------------------------------------------------------
; triangle.asm
;
; A very simple *Linux* opengl application using the glut library. it
; draws a nicely colored triangle in a top-level application window.
; Version of numit_or: numit_or@cantv.net
;
; Compile with:
; nasm -felf triangle.asm -o triangle.o
; gcc triangle.o -o triangle -L/usr/X11R6/lib -lGL -lglut -lglu
;
; you can find nasm in:
; http://nasm.sourceforge.net/
;
; ----------------------------------------------------------------------------
;
; libGL is in
; libMesaGL1 pack (Mandrake)
; mesag3 - mesag-dev - mesa-common-dev packs (Debian)
; libglut and libGLU are in:
; libMesaglut pack (Mandrake)
; freeglut3 - freeglut3-dev - libglut3 - libglut3-dev (Debian)
;
; ----------------------------------------------------------------------------
global main
extern glClear
extern glBegin
extern glEnd
extern glColor3f
extern glVertex3f
extern glFlush
extern glutInit
extern glutInitDisplayMode
extern glutInitWindowPosition
extern glutInitWindowSize
extern glutCreateWindow
extern glutDisplayFunc
extern glutMainLoop
GL_COLOR_BUFFER_BIT equ 16384
GL_POLYGON equ 9
section .data
title db 'A Simple Triangle', 0
zero dd 0.0
one dd 1.0
half dd 0.5
neghalf dd -0.5
section .text
display:
sub rsp, 32h
mov rdi, GL_COLOR_BUFFER_BIT
call glClear ; glClear(GL_COLOR_BUFFER_BIT)
mov rdi, GL_POLYGON
call glBegin ; glBegin(GL_POLYGON)
movss xmm0, [zero]
movss xmm1, [zero]
movss xmm2, [one]
call glColor3f ; glColor3f(1, 0, 0)
movss xmm0, [zero]
movss xmm1, [neghalf]
movss xmm2, [neghalf]
call glVertex3f ; glVertex(-.5, -.5, 0)
movss xmm0, [zero]
movss xmm1, [one]
movss xmm2, [zero]
call glColor3f ; glColor3f(0, 1, 0)
movss xmm0, [zero]
movss xmm1, [neghalf]
movss xmm2, [half]
call glVertex3f ; glVertex(.5, -.5, 0)
movss xmm0, [one]
movss xmm1, [zero]
movss xmm2, [zero]
call glColor3f ; glColor3f(0, 0, 1)
movss xmm0, [zero]
movss xmm1, [half]
movss xmm2, [zero]
call glVertex3f ; glVertex(0, .5, 0)
call glEnd ; glEnd()
call glFlush ; glFlush()
add rsp, 32h
ret
main:
sub rsp, 32h
mov rsi, rcx
call glutInit
mov rsi, 0
call glutInitDisplayMode
mov rsi, 100
mov rdi, 100
call glutInitWindowPosition
mov rdi, 400
mov rsi, 300
call glutInitWindowSize
mov rdi, title
call glutCreateWindow
mov rdi, display
call glutDisplayFunc
call glutMainLoop
add rsp, 32h
leave ;;;< is this even needed anymore?
ret