Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to print the coordinates of a drawn square upon movement. The problem is that the x value doesn't get refreshed on screen.

This is the code I have:

#include <allegro.h>

BITMAP *buffer;

void update_screen(void)
    blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); // blit the buffer to the screen

int init_double_buffering()
    // create the memory buffer
    buffer = create_bitmap(SCREEN_W, SCREEN_H);

        return FALSE;

    return TRUE;

int main()
    int x, y;

    // install allegro, set graphics mode, etc

    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,480, 0,0))
        allegro_message("Unable to set graphics mode.\n");
        return 1;

    // initialize page flipping
    if (!init_double_buffering())
        allegro_message("Unable to initialize page flipping.\n");
        return 1;

    // default coordinates for the rectangle
    x = SCREEN_W / 2 - 5;
    y = SCREEN_H / 2 - 5;

    // main game loop
    while (!key[KEY_ESC])
        // game logic
        if (key[KEY_LEFT] && x) --x;
        if (key[KEY_RIGHT] && x < SCREEN_W-10) ++x;
        if (key[KEY_UP] && y) --y;
        if (key[KEY_DOWN] && y < SCREEN_H-10) ++y;

        // you draw everything to buffer
        rect(buffer, x,y, x+9,y+9, makecol(255,255,255));
        textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H/2,
               makecol(255, 255, 255), -1,
               "X value is %d!",

        // show the offscreen page

    return 0;
share|improve this question
up vote 5 down vote accepted

The Problem is that you draw your text on the screen and then blit the doublebuffer over that.

Simply change the first argument to textprintf_centre_ex from screen to buffer and it works like a charm.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.