• Advertisement
Sign in to follow this  

Beginning allegro

This topic is 3577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am a beginner at programming games. I started learning from the book "game programming all in one, 2nd edition". This is one of the pieces of code i was trying to make work. The textprintf() function seems to be the main issue here. I have put both the code as well as the compile log below.Any solutions will be appreciated. Thanks!
#include <conio.h>
#include <stdlib.h>
#include <allegro.h>

int main()
{
//initialize Allegro
allegro_init();

//initialize the keyboard
install_keyboard();

//initialize video mode to 640x480
int ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (ret != 0) {
allegro_message(allegro_error);
return -1;
}

//------------problem part---------------
//display screen resolution
textprintf(screen, font, 0, 0, makecol(255, 255, 255),
“%dx %d”, SCREEN_W, SCREEN_H);
//------------problem part---------------

//wait for keypress
while(!key[KEY_ESC]);

//end program
allegro_exit();

return 0;
}
END_OF_MAIN();
Compile Log: Building Makefile: "C:\Dev-Cpp\Makefile.win" Executing make... make.exe -f "C:\Dev-Cpp\Makefile.win" all g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" main.cpp: In function `int _mangled_main()': main.cpp:20: warning: `textprintf' is deprecated (declared at C:/Dev-Cpp/include/allegro/alcompat.h:177) main.cpp:20: error: stray '\147' in program main.cpp:20: error: expected primary-expression before '%' token main.cpp:20: error: `dx' undeclared (first use this function) main.cpp:20: error: (Each undeclared identifier is reported only once for each function it appears in.) main.cpp:20: error: stray '\148' in program main.cpp:20: error: `d' undeclared (first use this function) make.exe: *** [main.o] Error 1 Execution terminated

Share this post


Link to post
Share on other sites
Advertisement
The quotation marks in “%dx %d” look weird. Try deleting them and retyping the ". I think I had a similar error once, because I pasted some code and apparently the " were different.

Share this post


Link to post
Share on other sites
Whoa..that was quick..thanks! worked like a breeze...
Another question,
As sumone interested in programming...
what does " func() is deprecated" mean?? what are deprecated functions in general??

Share this post


Link to post
Share on other sites
Quote:
Original post by incrediblesuvir
what does " func() is deprecated" mean?? what are deprecated functions in general??


Deprecation.

After some googling, it looks like you should use textprintf_ex() instead.

Share this post


Link to post
Share on other sites
umm..it worked by retyping the qoute marks...
but as far as the issue about the "deprecated func()" warning is concernedm i tried using textprintf_ex(...) but instead it threw up errors.

Compile log is as follows:

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

main.cpp: In function `int _mangled_main()':
main.cpp:23: error: invalid conversion from `const char*' to `int'
main.cpp:23: error: initializing argument 6 of `void textprintf_ex(BITMAP*, const FONT*, int, int, int, int, const char*, ...)'
main.cpp:23: error: invalid conversion from `int' to `const char*'
main.cpp:23: error: initializing argument 7 of `void textprintf_ex(BITMAP*, const FONT*, int, int, int, int, const char*, ...)'

make.exe: *** [main.o] Error 1

Execution terminated

Any ideas?

Share this post


Link to post
Share on other sites
You can download the source code for the 3rd edition of the book from the author which is updated for newer editions of Allegro and uses the newer textprintf_ex() function.
At least that's what I did since I just read the 2nd edition book myself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement