Problems with ALLEGRO_FONT
Aleksa

I get two compile errors for ALLEGRO_FONT *fonts[FONT_MAX]; in graphics.h :
- syntax error: missing '{' before '*'
- identifier "ALLEGRO_FONT" is undefined

Strange thing is that ALLEGRO_BITMAP and ALLEGRO_DISPLAY work ok. If I include allegro_fonts in main or that exact .h file it works but that's not what i should do?
Any help?

graphics.h

#SelectExpand
1#pragma once 2 3enum { 4 IMAGE_BACKGROUND, 5 IMAGE_MAX 6}; 7 8enum { 9 FONT_PROGGYCLEANSZ_23, 10 FONT_MAX 11}; 12 13ALLEGRO_BITMAP *images[IMAGE_MAX]; 14ALLEGRO_FONT *fonts[FONT_MAX]; 15ALLEGRO_DISPLAY *display;

graphics.c

#SelectExpand
2#include <allegro5\allegro.h> 3#include <allegro5\allegro_native_dialog.h> 4#include <allegro5\allegro_image.h> 5#include <allegro5\allegro_font.h> 6#include <allegro5\allegro_ttf.h> 7#include <allegro5\allegro_primitives.h> 8 9#include "graphics.h" 10 11 12//LOADING STUFF

Edgar Reynaldo

You have to either include the allegro headers in your header file, or predeclare the types that you are using :

#include "allegro_font.h"

ALLEGRO_FONT* font;

Aleksa

Including header file works, predeclare does not.
Any idea why other types as ALLEGRO_BITMAP and ALLEGRO_DISPLAY work?

Edgar Reynaldo

Try typedef struct ALLEGRO_FONT instead.

The other types probably work because you've included other headers before including your graphics.h header.

You have to include the headers at some point.

Aleksa

With typedef i get: 'typedef ': ignored on left of 'ALLEGRO_FONT' when no variable is declared

These are only headers i include in main.c
Are ALLEGRO_BITMAP and ALLEGRO_DISPLAY defined in allegro.h?

main.c headers

#SelectExpand
1#include <stdbool.h> 2#include <stdio.h> 3 4#include <allegro5\allegro.h> 5#include <allegro5\allegro_native_dialog.h> 6 7#include "keyboard.h" 8#include "graphics.h"

edit: I just peeked at allegro.h and it includes bitmap.h that defines ALLEGRO_BITMAP. This solves my confusion :)
Thanks :)

Edgar Reynaldo

Since you're using C I think you need to include 'struct' anytime you declare a variable of that type, unless it is after it has been typedef'ed.

struct ALLEGRO_FONT* font[3];

#include "allegro5/allegro_font.h"
/** in allegro_font.h
typedef struct ALLEGRO_FONT {...};
*/


ALLEGRO_FONT* font;

Aleksa

That works!

#SelectExpand
1struct ALLEGRO_FONT *font[FONT_MAX];

Thread #616581. Printed from Allegro.cc