![]() |
|
al_draw_text problem |
William Labbett
Member #4,486
March 2004
![]() |
Hi, 1#include <stdio.h>
2#include <stdlib.h>
3#include <time.h>
4
5#include <allegro5/allegro.h>
6
7#include <allegro5/allegro_image.h>
8#include <allegro5/allegro_font.h>
9#include <allegro5/allegro_ttf.h>
10#define WRITE(string) fprintf(output, string)
11
12
13
14int initialise_allegro(void);
15
16
17int main()
18{
19 FILE *output = NULL;
20 ALLEGRO_FONT *font;
21 ALLEGRO_BITMAP *bitmap = NULL;
22 ALLEGRO_DISPLAY *display = NULL;
23 ALLEGRO_COLOR colour;
24
25 const char *text = "783";
26
27 output = fopen("output.txt", "w");
28
29 srand(time(NULL));
30
31 if(initialise_allegro() == 1)
32 {
33 printf("Initialise allegro failed.\n");
34 return 1;
35 }
36
37 display = al_create_display(640, 480);
38 if(display == NULL)
39 {
40 printf("Couldn't create display.\n");
41 return 1;
42 }
43 printf("10\n");
44
45 colour = al_map_rgba(255, 255, 255, 255);
46
47 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
48 al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA);
49 bitmap = al_create_bitmap(72, 12);
50 if(bitmap == NULL)
51 {
52 printf("Couldn't create a bitmap.");
53 return 0;
54 }
55 else
56 {
57 printf("20\n");
58 }
59 al_set_target_bitmap(bitmap);
60 printf("30\n");
61 al_clear_to_color(colour);
62 printf("40\n");
63 if(bitmap == NULL)
64 {
65 printf("bitmap NULL.\n");
66 return 1;
67 }
68 else
69 {
70 printf("45\n");
71 }
72
73
74 font = al_load_ttf_font("SimpleRonde-Regular.ttf", 12, 0);
75 if(font == NULL)
76 {
77 printf("Couldn't load font.");
78 return 1;
79 }
80 else
81 {
82 printf("Loaded font.\n");
83 }
84
85
86
87 if(font == NULL)
88 {
89 printf("Font pointer NULL\n");
90 return 1;
91 }
92 else
93 {
94 printf("font pointer not null.\n");
95 }
96 al_set_target_bitmap(bitmap);
97 if(font == NULL)
98 {
99 printf("Font pointer NULL\n");
100 return 1;
101 }
102 else
103 {
104 printf("font pointer not null.\n");
105 }
106 if(bitmap == NULL)
107 {
108 printf("bitmap NULL.\n");
109 return 1;
110 }
111 else
112 {
113 printf("bitmap not NULL\n");
114 }
115 al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, "222");
116 printf("50\n");
117 if(bitmap == NULL)
118 {
119 printf("Can't save bitmap.\n");
120 return 1;
121 }
122 printf("bitmap width = %d", al_get_bitmap_width(bitmap));
123 if(al_save_bitmap("bitmap.bmp", bitmap) == false)
124 {
125 printf("Failed to save bitmap.\n");
126 return 1;
127 }
128 else
129 {
130 printf("Saved bitmap.\n");
131 }
132
133 printf("30\n");
134
135 if(output == NULL)
136 {
137 printf("file pointer \"output\" is NULL. Couldn't open file.");
138 return 1;
139 }
140
141 fprintf(output, "\\documentclass(article)\n");
142
143 fprintf(output, "\\title(Arithmetic Practice)");
144
145 WRITE("\n\\includepackage(graphicx)");
146 WRITE("\n\\usepackage(amsmath)");
147 WRITE("\n\\begin(document)");
148
149
150
151 fclose(output);
152 return 0;
153}
154
155
156int initialise_allegro()
157{
158 al_install_system(ALLEGRO_VERSION_INT, atexit);
159
160
161
162 if(al_init_image_addon() == false)
163 {
164 printf("Couldn't initialise image addon.");
165 return 1;
166 }
167
168
169 al_init_font_addon();
170 if(al_init_ttf_addon() == false)
171 {
172 printf("Couldn't initialise truetype font addon\n");
173 return 1;
174 }
175
176
177 return 0;
178}
|
Frank Drebin
Member #2,987
December 2002
![]() |
I tried using the font Arial and it seemed to work fine: Maybe there's something wrong with your font file? |
William Labbett
Member #4,486
March 2004
![]() |
Hi, not wanting to be a pain but I've swapped the code to load arial.ttf and it still does what it used to on my computer. It obviously doesn't do the same on my computer as it does on your computer. I've got liballegro-5.0.10-monolith-md.a as the linker options. Could it be that my PATH variable isn't set up properly so the program can find the files it needs. I'm using Windows 8 and code::blocks
|
Frank Drebin
Member #2,987
December 2002
![]() |
I'm using Allegro 5.2.4. Why don't you switch to a more recent version of Allegro? What is the output on your computer? |
William Labbett
Member #4,486
March 2004
![]() |
The console prints out : 10 Process returned -1073741819 (0xC0000005) execution time : 2.007 s I'll try the version your using and see how that goes.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You're not checking the return value of al_install_system. It's probably failing due to runtime problems. Ie. mixed versions of dll and headers. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|