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

  • SEARCH
  • Home
  • 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 7859547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:55:52+00:00 2026-06-02T21:55:52+00:00

hello what I’m currently dealing with is the ability to get input from a

  • 0

hello what I’m currently dealing with is the ability to get input from a text file and then convert it into a bitmap and save it to a file.

the input looks like this:

########
#      #
########

and I want to draw it using allegro and instead of # there would be pixels of specified size. Each # should represent a tile (10×10 pixel). So the final result would look like this

link to an image

I’ve actually drawn it using this code:

 for (int i = 0; i < 80; i++){
        for (int j = 0; j < 10; j++){
            al_draw_pixel(i, j, al_map_rgb(0, 0, 0));
        }
    }
    for (int i = 0; i < 10; i++){
        for (int j = 10; j < 20; j++){
            al_draw_pixel(i, j, al_map_rgb(0, 0, 0));
        }
    }
    for (int i = 70; i < 80; i++){
        for (int j = 10; j < 20; j++){
            al_draw_pixel(i, j, al_map_rgb(0, 0, 0));
        }
    }
    for (int i = 0; i < 80; i++){
        for (int j = 20; j < 30; j++){
            al_draw_pixel(i, j, al_map_rgb(0, 0, 0));
        }
    }

yeah that’s pretty bad, so how do I achieve something like that but with a common procedure which would be independent on the text file? thanks for any advice.

note: the only allowed headers are allegro5/allegro.h and allegro5/allegro_image.h

  • 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-02T21:55:53+00:00Added an answer on June 2, 2026 at 9:55 pm

    To draw to an image with Allegro 5, you need to do something like:

    ALLEGRO_BITMAP *bmp = al_create_bitmap(640, 480);
    al_set_target_bitmap(bmp);
    

    Now all of your drawing operations will happen on the image. To later save it:

    al_save_bitmap("somefile.bmp", bmp);
    

    You can also use png and jpg as extensions if your image library has support for it enabled.

    Use these functions to read the text file:

    • al_fopen
    • al_fgetc
    • al_feof
    • al_fclose

    Set int x and y to zero. You’ll be looping over until the end of the file. On every iteration increment x by one. If you reach a new line character (\n) increment y by one and set x to zero. (You should ignore \r characters.)

    Now, depending on the character read, draw a tile:

    ALLEGRO_BITAMP *tile_to_draw = NULL;
    if (c == '#')
       tile_to_draw = bmp1;
    else if (c == ' ')
       tile_to_draw = bmp2;
    
    if (tile_to_draw)
       al_draw_bitmap(tile_to_draw, x * 10, y * 10, 0);
    

    Of course there’s better ways to map characters to tiles than a series of ifs, but the above works and should be enough to help you finish your homework.

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

Sidebar

Related Questions

Hello I want to convert a PDF file to text file. I am converting
Hello i´m trying to set info from a post method into a variable that
Hello guys i have set background image on my input text and text area
hello i wanted to build I get $date and $date1 from form xxx. I
Hello I am trying to pass different urls from my site into a template.
Hello I have this query... if (isset($_REQUEST['deletePost'])) { $q = $dbc -> prepare(DELETE FROM
Hello I'm trying to take backup from mysql command line client. I'm using mysqldump
Hello everyone i am trying to format the input number range with php number_format
hello friends i am trying to get a list of user id and want
Hello ever one I want to ask a question about file opening.I want to

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.