Browse Source

Using fontconfig to fecth font filename

Yann Weber 5 years ago
parent
commit
cb0d5b7d33
3 changed files with 104 additions and 18 deletions
  1. 4
    4
      Makefile
  2. 14
    0
      sdl.asm
  3. 86
    14
      yaglitch.asm

+ 4
- 4
Makefile View File

@@ -5,18 +5,18 @@ NASM=nasm
5 5
 
6 6
 ifeq ($(DEBUG), 0)
7 7
 	ASFLAGS=-felf64
8
-	LDFLAGS=-s -melf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
8
+	LDFLAGS=-s -melf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lfontconfig
9 9
 	#LDFLAGS=-s -melf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lSDL2
10 10
 else
11 11
 	ASFLAGS=-felf64 -g -F dwarf -l $(TARGET).lst
12 12
 	#LDFLAGS=-g -melf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lSDL
13
-	LDFLAGS=-g -melf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
13
+	LDFLAGS=-g -melf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lfontconfig
14 14
 endif
15 15
 ifeq ($(SDL), 2)
16
-	LDFLAGS += -lSDL2
16
+	LDFLAGS += -lSDL2 -lSDL_ttf
17 17
 	ASFLAGS += -DSDL2=1
18 18
 else
19
-	LDFLAGS += -lSDL
19
+	LDFLAGS += -lSDL -lSDL_ttf
20 20
 	ASFLAGS += -DSDL1=1
21 21
 endif
22 22
 

+ 14
- 0
sdl.asm View File

@@ -11,6 +11,10 @@ Extern SDL_LockSurface
11 11
 Extern SDL_UnlockSurface
12 12
 Extern SDL_UpperBlit
13 13
 %define SDL_BlitSurface SDL_UpperBlit
14
+Extern TTF_OpenFont
15
+Extern TTF_RenderText_Solid
16
+Extern TTF_Init
17
+
14 18
 
15 19
 %ifdef SDL1
16 20
 	%define SDL_QUIT 0x0C
@@ -90,3 +94,13 @@ ENDSTRUC
90 94
 mov %1, [%2]
91 95
 mov %1, [%1 + 32]
92 96
 %endmacro
97
+
98
+
99
+;fontconfig
100
+Extern FcInitLoadConfigAndFonts
101
+Extern FcPatternCreate
102
+Extern FcObjectSetBuild
103
+Extern FcFontList
104
+Extern FcPatternGetString
105
+Extern FcPatternPrint
106
+

+ 86
- 14
yaglitch.asm View File

@@ -70,7 +70,12 @@ section .data
70 70
 	def_str bigline_error, {"Line with more than 16 tokens !", 0xA}
71 71
 	def_str nl_error, {"Character \n is not the last one", 0xA}
72 72
 	def_str badop_error, {"Bad OP", 0xA}
73
+
73 74
 	window_title: db "Yaglitch", 0x0
75
+	font_name: db "Sans.ttf", 0x0
76
+	FC_FILE: db "file", 0x0
77
+	FC_FAMILY: db "family", 0x0
78
+	FC_LANG: db "lang", 0x0
74 79
 
75 80
 section .bss
76 81
 
@@ -116,6 +121,18 @@ section .bss
116 121
 
117 122
 	visu_surf: resq 1
118 123
 
124
+	text_surf: resq 1
125
+
126
+	ttf_font: resq 1
127
+
128
+	sdl_color: resd 1
129
+
130
+	fc_config: resq 1
131
+	fc_pattern: resq 1
132
+	fc_object_set: resq 1
133
+	fc_font_set: resq 1
134
+	fc_font_file_ptr: resq 1
135
+
119 136
 section .text
120 137
 global _start
121 138
 _start:
@@ -371,13 +388,26 @@ sdl_init:
371 388
 	test rax, rax
372 389
 	jnz exit_fatal
373 390
 
391
+	; Init SDL
374 392
 	mov rdi, 0x0000FFFF
375 393
 	call SDL_Init
376 394
 
395
+	; Open Audio -> setting spec to 8bit etc. (see .data)
377 396
 	mov rdi, audiospec_wanted
378 397
 	mov rsi, audiospec_recv
379 398
 	call SDL_OpenAudio
380 399
 
400
+	%ifdef MIX_AUDIO
401
+		; init callback heap infos
402
+		mov rax, 0xc ; brk
403
+		xor rdi, rdi ; get heap start addr
404
+		mov [cllbck_heapsz], rdi
405
+		syscall
406
+		cmp rax, -1
407
+		je exit_fatal
408
+		mov [cllbck_heap], rax
409
+	%endif
410
+
381 411
 	; video init 256*256 window
382 412
 	; init visu_scr : *screen
383 413
 	%ifdef SDL1
@@ -447,22 +477,64 @@ sdl_init:
447 477
 
448 478
 	; RAZ surface & blit
449 479
 	;call clear_screen ;useless
480
+	; init fontconfig
481
+	call FcInitLoadConfigAndFonts
482
+	mov [fc_config], rax
483
+	call FcPatternCreate
484
+	mov [fc_pattern], rax
485
+
486
+	mov rdi, FC_FILE
487
+	;mov rsi, FC_FAMILY
488
+	;mov rdx, FC_LANG
489
+	xor rcx, rcx
490
+	xor r8, r8
491
+	call FcObjectSetBuild
492
+
493
+	mov [fc_object_set], rax
494
+	mov rdi, [fc_config]
495
+	mov rsi, [fc_pattern]
496
+	mov rdx, [fc_object_set]
497
+	call FcFontList
498
+	mov [fc_font_set], rax
499
+
500
+	mov rdi, [rax+8]
501
+	mov rdi, [rdi] ; 1st font in set
502
+	;mov rdi, [rdi+8] ; 2nd font in set
503
+	push rdi ; debug
504
+	call FcPatternPrint
505
+	pop rdi
506
+	mov rsi, FC_FILE
507
+	xor rdx, rdx
508
+	mov rcx, fc_font_file_ptr
509
+	call FcPatternGetString
510
+dbg:
511
+	; Init SDL_ttf
512
+	call TTF_Init
513
+	cmp rax, 0
514
+	jl sdl_error
515
+	; open font
516
+	mov rdi, [fc_font_file_ptr]
517
+	mov rsi, 18 ; 18 pts/inch
518
+	call TTF_OpenFont
519
+	test rax, rax
520
+	jz sdl_error
521
+	mov [ttf_font], rax
450 522
 
451
-	%ifdef MIX_AUDIO
452
-		; init callback heap infos
453
-		mov rax, 0xc ; brk
454
-		xor rdi, rdi ; get heap start addr
455
-		mov [cllbck_heapsz], rdi
456
-		syscall
457
-		cmp rax, -1
458
-		je exit_fatal
459
-		mov [cllbck_heap], rax
460
-	%endif
523
+	mov dword [sdl_color], 0xFFFFFFFF
524
+	mov rdi, [ttf_font]
525
+	mov rsi, glitch_name
526
+	mov rdx, sdl_color
527
+	call TTF_RenderText_Solid ; render text in surface
528
+
529
+	; blit & flip text surface
530
+	mov rdi, [ttf_font]
531
+	call blitflip_visu
461 532
 
462
-	audio_start:
463
-		;start audio
464
-		xor rdi, rdi
465
-		call SDL_PauseAudio
533
+
534
+audio_start:
535
+	;start audio
536
+	xor rdi, rdi
537
+	call SDL_PauseAudio
466 538
 
467 539
 loop_event:
468 540
 	xor rdi, rdi

Loading…
Cancel
Save