Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:16:12+00:00 2026-06-13T13:16:12+00:00

The above is a problem I am having. I am using Visual Studio 2010,

  • 0

The above is a problem I am having. I am using Visual Studio 2010, in C++, with the Allegro library for game development. I’m having an issue where my test program is always all-white, until I hit a button, in some cases. I don’t really understand how to fix this, nor what’s wrong. I know for a fact that it’s not related to the code being used, as this never used to happen with some example code from a website; now it seems to happen all the time with this project. If someone could point me to a possible error fix, it would be much appreciated.

Below is the code:

#include <allegro5\allegro.h>
#include <allegro5\allegro_primitives.h>                //Our primitive header file

int main(void)
{
    int width = 640;
    int height = 480;

    bool done = false;
    int pos_x = width / 2;
    int pos_y = height / 2;

    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;

    if(!al_init())                                      //initialize Allegro
        return -1;

    display = al_create_display(width, height);         //create our display object

    if(!display)                                        //test display object
        return -1;

    al_init_primitives_addon();
    al_install_keyboard();

    event_queue = al_create_event_queue();

    al_register_event_source(event_queue, al_get_keyboard_event_source());

    while(!done)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);

        if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
        {
            switch(ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_UP:
                    pos_y -= 10;
                    break;
                case ALLEGRO_KEY_DOWN:
                    pos_y += 10;
                    break;
                case ALLEGRO_KEY_RIGHT:
                    pos_x += 10;
                    break;
                case ALLEGRO_KEY_LEFT:
                    pos_x -= 10;
                    break;
            }
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_UP)
        {
            if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                done = true;
        }

        al_draw_filled_rectangle(pos_x, pos_y, pos_x + 30, pos_y + 30, al_map_rgb(255,0,255));
        al_flip_display();
        al_clear_to_color(al_map_rgb(0,0,0));
    }

    al_destroy_event_queue(event_queue);
    al_destroy_display(display);                        //destroy our display object

    return 0;
}

As I said, it is example code from an online tutorial.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:16:13+00:00Added an answer on June 13, 2026 at 1:16 pm

    The quick fix is exactly what @mythagel has mentioned in the comments.

    Generally with Allegro games, you will want to create a timer and have it tick at some fixed interval (e.g., 60 times per second) and attach it to your event queue. Every time it ticks, you advance your game’s logic by one frame, and then redraw the graphics (if there is nothing else to do).

    So instead of processing input directly during the key events, you simply mark that a key is down or up. So you may have a variable called key_left that represents moving left and set it to true in the keydown event and false in the keyup event.

    Then in your timer event (ALLEGRO_EVENT_TIMER), you can check if (key_left == true) pos_x -= 10; This will cause your game to run at the same speed on every computer, since you always processing input exactly X times per second.

    There are more advanced ways of handling input that don’t involve a fixed frame rate, but this is the easiest approach and usually works just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having an issue with Visual Studio 2010 that is driving me
http://code.google.com/p/tesseractdotnet/ I am having a problem getting Tesseract to work in my Visual Studio
I am using ASP.NET MVC2 in Visual Studio 2008. I believe the SQL Server
I'm having trouble using contentEditable in FireFox 3. I have a problem where the
i'm having a problem with dynamically loaded forms - instead of using the action
I'm having a problem using iModelBinder with url in the format of http://localhost/controller/action/id/value the
I am having a problem using the jQuery cycle plugin. On my page, I
I'm having a mind blowing problem using WCF 4.0 RESTful service. I am trying
I am having problem with IdTCPclient.connected function from Indy in Delphi. I am using
im having a problem regarding using background property with url('location') value with a div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.