-
Notifications
You must be signed in to change notification settings - Fork 0
/
bspGLUT.asm
148 lines (114 loc) · 4.51 KB
/
bspGLUT.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
;
; Basic OS X calls to GLUT and OpenGL
;
; Example by Waitsnake
;
; compile with:
; nasm -g -f macho32 bspGLUT.asm
; xcrun gcc -framework GLUT -framework OpenGL -m32 -o bspGLUT.out bspGLUT.o
;
%include "gl.inc"
%include "glut.inc"
; static data
segment .data
window_name: db "OpenGL on OSX with nasm", 10, 0
fl_one: dd 1.0
fl_neg_one: dd -1.0
fl_zero: dd 0.0
fl_half: dd 0.5
fl_neg_half: dd -0.5
; code
segment .text
global _main
; the main function that init OpenGL and install the gl draw function (_display_func)
_main:
;alignment = 0
lea ecx, [esp+4] ;load adress of argc in stack to ecx
lea edx, [esp+8] ;load adress of argv in stack to edx
push ebp ; setup the frame ;alignment => 4
mov ebp, esp
push edx ;alignment => 8
push ecx ;alignment => 12
call _glutInit ;alignment => 16 -> alignment <= 12 (after backjump with "ret")
add esp, 8 ;alignment <= 4 (caller has to clean call paras (8 byte))
sub esp, 4 ;alignment => 8 (correction need to get to 16 at next call !)
mov eax, GLUT_RGB
or eax, GLUT_SINGLE
push eax ;alignment => 12
call _glutInitDisplayMode ;alignment => 16 -> alignment <= 12
add esp, 4 ;alignment <= 8 (caller has to clean call paras (4 byte))
add esp, 4 ;alignment <= 4 (clean last the allignment correction)
push dword 80 ;alignment => 8
push dword 80 ;alignment => 12
call _glutInitWindowPosition ;alignment => 16 -> alignment <= 12
add esp, 8 ;alignment <= 4 (caller has to clean call paras (8 byte))
push dword 300 ;alignment => 8
push dword 400 ;alignment => 12
call _glutInitWindowSize ;alignment => 16 -> alignment <= 12
add esp, 8 ;alignment <= 4 (caller has to clean call paras (8 byte))
sub esp, 4 ;alignment => 8 (correction need to get to 16 at next call !)
mov eax, dword window_name
push eax ;alignment => 12
call _glutCreateWindow ;alignment => 16 -> alignment <= 12
add esp, 4 ;alignment <= 8 (caller has to clean call paras (4 byte))
add esp, 4 ;alignment <= 4 (clean last the allignment correction)
sub esp, 4 ;alignment => 8 (correction need to get to 16 at next call !)
push dword _display_func ;alignment => 12
call _glutDisplayFunc ;alignment => 16 -> alignment <= 12
add esp, 4 ;alignment <= 8 (caller has to clean call paras (4 byte))
add esp, 4 ;alignment <= 4 (clean last the allignment correction)
sub esp, 8 ;alignment => 12 (correction need to get to 16 at next call !)
call _glutMainLoop ;alignment => 16 -> alignment <= 12
add esp, 8 ;alignment <= 4 (caller has to clean call paras (8 byte))
_pass_exit:
pop ebp ;alignment <= 0
ret
; the gl draw function (here is the content of OpenGL
_display_func:
pusha
sub esp,8
push dword GL_COLOR_BUFFER_BIT
call _glClear
add esp,12
sub esp,8
push dword GL_POLYGON
call _glBegin
add esp,12
push dword 0
push dword 0
push dword [fl_one]
call _glColor3f
add esp,12
push dword 0
push dword [fl_neg_half]
push dword [fl_neg_half]
call _glVertex3f
add esp,12
push dword 0
push dword [fl_one]
push dword 0
call _glColor3f
add esp,12
push dword 0
push dword [fl_neg_half]
push dword [fl_half]
call _glVertex3f
add esp,12
push dword [fl_one]
push dword 0
push dword 0
call _glColor3f
add esp,12
push dword 0
push dword [fl_half]
push dword 0
call _glVertex3f
add esp,12
sub esp,12
call _glEnd
add esp,12
sub esp,12
call _glFlush
add esp,12
popa
ret