Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » still al_draw_text() problem

This thread is locked; no one can reply to it. rss feed Print
still al_draw_text() problem
William Labbett
Member #4,486
March 2004
avatar

Thanks for the replies to https://www.allegro.cc/forums/thread/617920

I rewrote the code a bit so that it checks the return value of al_install_system()

#SelectExpand
1#include <stdio.h> 2#include <stdlib.h> 3#include <time.h> 4#include <allegro5/allegro.h> *** 5#include <allegro5/allegro5.h> 6#include <allegro5/allegro_image.h> 7#include <allegro5/allegro_font.h> 8#include <allegro5/allegro_ttf.h> 9 10 11 12#define WRITE(string) fprintf(output, string) 13 14 15 16int initialise_allegro(void); 17 18 19int main() 20{ 21 FILE *output = NULL; 22 ALLEGRO_FONT *font; 23 ALLEGRO_BITMAP *bitmap = NULL; 24 ALLEGRO_DISPLAY *display = NULL; 25 ALLEGRO_COLOR colour; 26 const char *text = "783"; 27 int init = 0; 28 29 output = fopen("output.txt", "w"); 30 31 srand(time(NULL)); 32 33 if((init = initialise_allegro()) == 1) 34 { 35 printf("al_init_font_addon() or al_install_image_addon() failed.\n"); 36 return 1; 37 } 38 else if(init == 2) 39 { 40 printf("al_install_system() failure."); 41 return 1; 42 } 43 44 45 display = al_create_display(640, 480); 46 if(display == NULL) 47 { 48 printf("Couldn't create display.\n"); 49 return 1; 50 } 51 printf("10\n"); 52 53 colour = al_map_rgba(255, 255, 255, 255); 54 55 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); 56 al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA); 57 bitmap = al_create_bitmap(72, 12); 58 if(bitmap == NULL) 59 { 60 printf("Couldn't create a bitmap."); 61 return 0; 62 } 63 else 64 { 65 printf("20\n"); 66 } 67 al_set_target_bitmap(bitmap); 68 printf("30\n"); 69 al_clear_to_color(colour); 70 printf("40\n"); 71 if(bitmap == NULL) 72 { 73 printf("bitmap NULL.\n"); 74 return 1; 75 } 76 else 77 { 78 printf("45\n"); 79 } 80 81 82 font = al_load_ttf_font("arial.ttf", 12, 0); 83 if(font == NULL) 84 { 85 printf("Couldn't load font."); 86 return 1; 87 } 88 else 89 { 90 printf("Loaded font.\n"); 91 } 92 93 94 95 if(font == NULL) 96 { 97 printf("Font pointer NULL\n"); 98 return 1; 99 } 100 else 101 { 102 printf("font pointer not null.\n"); 103 } 104 al_set_target_bitmap(bitmap); 105 if(font == NULL) 106 { 107 printf("Font pointer NULL\n"); 108 return 1; 109 } 110 else 111 { 112 printf("font pointer not null.\n"); 113 } 114 if(bitmap == NULL) 115 { 116 printf("bitmap NULL.\n"); 117 return 1; 118 } 119 else 120 { 121 printf("bitmap not NULL\n"); 122 } 123 al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, "222"); 124 printf("50\n"); 125 if(bitmap == NULL) 126 { 127 printf("Can't save bitmap.\n"); 128 return 1; 129 } 130 printf("bitmap width = %d", al_get_bitmap_width(bitmap)); 131 if(al_save_bitmap("bitmap.bmp", bitmap) == false) 132 { 133 printf("Failed to save bitmap.\n"); 134 return 1; 135 } 136 else 137 { 138 printf("Saved bitmap.\n"); 139 } 140 141 printf("30\n"); 142 143 if(output == NULL) 144 { 145 printf("file pointer \"output\" is NULL. Couldn't open file."); 146 return 1; 147 } 148 149 fprintf(output, "\\documentclass(article)\n"); 150 151 fprintf(output, "\\title(Arithmetic Practice)"); 152 153 WRITE("\n\\includepackage(graphicx)"); 154 WRITE("\n\\usepackage(amsmath)"); 155 WRITE("\n\\begin(document)"); 156 157 158 159 fclose(output); 160 return 0; 161} 162 163 164int initialise_allegro() 165{
166 if(al_init() != true)
167 { 168 printf("al_install_system() failed."); 169 return 2; 170 } 171 else 172 { 173 printf("al_install_system() success."); 174 } 175 176 177 if(al_init_image_addon() == false) 178 { 179 printf("Couldn't initialise image addon."); 180 return 1; 181 } 182 183 184 al_init_font_addon(); 185 if(al_init_ttf_addon() == false) 186 { 187 printf("Couldn't initialise truetype font addon\n"); 188 return 1; 189 } 190 191 192 return 0; 193}

The output was more or less the same as before :

al_install_system() success.10
20
30
40
45
Loaded font.
font pointer not null.
font pointer not null.
bitmap not NULL

Process returned -1073741819 (0xC0000005) execution time : 2.116 s
Press any key to continue.

Here's the dll's in the debug folder of code::blocks

{"name":"612154","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/2\/e2d14b08f5230d5a23532d1f6072d3f8.png","w":452,"h":180,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/2\/e2d14b08f5230d5a23532d1f6072d3f8"}612154

so I'm back to trying to install 5.2

from this page :

https://wiki.allegro.cc/index.php?title=Install_Allegro5_From_Git/Windows#ZLib

Currently getting

C:\devel\a5_sourcepack\zlib\build>cmake .. -DCMAKE_INSTALL_PREFIX=C:\MinGW -G "MinGW Makefiles"
'cmake' is not recognized as an internal or external command,
operable program or batch file.

and I have got CMake\bin in my path.

Any ideas?

/* edit should I be running cmake from the MSYS2 shell? */

DanielH
Member #934
January 2001
avatar

I don't see where you installed the font addon?

nvmd

I see at the end you have a function for init.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

William Labbett
Member #4,486
March 2004
avatar

Thanks very much Edgar. I got it working last night. al_draw_text worked.

Many thanks.

Go to: