textprintf - how to blit it?

This is a discussion on textprintf - how to blit it? within the Game Programming forums, part of the General Programming Boards category; Hi! When I use functions blit and draw_sprite in Allegro everything works fine. But I just can't figure what to ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question textprintf - how to blit it?

    Hi!

    When I use functions blit and draw_sprite in Allegro everything works fine. But I just can't figure what to do that the blit function will be working with the textprintf function. Everytime I use textprintf it gets deleted right away so the text is seen only for a milisecond.
    Here's the code:
    Code:
    .
    .
    .
    while (Loop)
    	{
    		// keyboard
    		if (key[KEY_UP])
    		{
    			key[KEY_UP] = FALSE;
    			i--;
    			if (i < 0) i = 1;
    		}
    		else if (key[KEY_DOWN])
    		{
    			key[KEY_DOWN] = FALSE;
    			i++;
    			if (i > 1) i = 0;
    		}
    		else if ( (key[KEY_ENTER]) && (i == 0) )
    		{
    			key[KEY_ENTER] = FALSE;
    			textprintf (ScreenBuffer, font, 10, 10, makecol (255,100,100), "new game - enter pressed");
    		}
    		else if ( (key[KEY_ENTER]) && (i == 1) )
    		{
    			key[KEY_ENTER] = FALSE;
    			textprintf (ScreenBuffer, font, 10, 10, makecol (255,100,100), "exit - enter pressed");
    			Loop = FALSE;
    		}
    		// blittering
    		acquire_screen ();
    		draw_sprite (ScreenBuffer, NewGame01, 100, 100);
    		draw_sprite (ScreenBuffer, Exit01, 100, 200);
    		draw_sprite (ScreenBuffer, MenuHL[i], MenuX[i], MenuY[i]);
    		blit (ScreenBuffer, screen, 0, 0, 0, 0, 640, 480);
    		clear (ScreenBuffer);
    		release_screen ();
    	}
    .
    .
    .
    Help!
    Last edited by GaPe; 05-03-2003 at 09:54 AM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Instead of using the screen as the BITMAP* in the textprintf function, use ScreenBuffer.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Now I've changed screen into ScreenBuffer and the text still disappears.

    What should I do now?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    It disappears because you only blit it once enter is pressed. After it's released, (or even after it was pressed once, I don't know how allegro handles keys) you're not blitting it anymore.

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    It's how you have your loop setup. If Enter is pressed then text is going to be blitted to the buffer. Then at the end of the loop the buffer is cleared, however, the text still appears on the screen, because the screen has not been cleared, only the buffer. If Enter is not pressed again, then there will be no text blitted to the buffer before the buffer is blitted to the screen, which will delete the previous text on the screen. A possible solution is to change your code to this...

    Code:
    BITMAP *TEXT_BMP; 
    TEXT_BMP = create_bitmap(200, 200); //any size you would like
    
    while (Loop)
    {
    // keyboard
    if (key[KEY_UP])
    {
    key[KEY_UP] = FALSE;
    i--;
    if (i < 0) i = 1;
    }
    else if (key[KEY_DOWN])
    {
    key[KEY_DOWN] = FALSE;
    i++;
    if (i > 1) i = 0;
    }
    else if ( (key[KEY_ENTER]) && (i == 0) )
    {
    key[KEY_ENTER] = FALSE;
    clear (TEXT_BMP);  //to let new text appear clearly
    textprintf (TEXT_BMP, font, 10, 10, makecol (255,100,100), "new game - enter pressed");
    }
    else if ( (key[KEY_ENTER]) && (i == 1) )
    {
    key[KEY_ENTER] = FALSE;
    clear (TEXT_BMP);  //to let new text appear clearly
    textprintf (TEXT_BMP, font, 10, 10, makecol (255,100,100), "exit - enter pressed");
    Loop = FALSE;
    }
    // blittering
    acquire_screen ();
    draw_sprite (ScreenBuffer, NewGame01, 100, 100);
    draw_sprite (ScreenBuffer, Exit01, 100, 200);
    draw_sprite (ScreenBuffer, MenuHL[i], MenuX[i], MenuY[i]);
    blit(TEXT_BMP, ScreenBuffer, 0, 0, 10, 10, 640, 480)
    blit (ScreenBuffer, screen, 0, 0, 0, 0, 640, 480);
    clear (ScreenBuffer);
    release_screen ();
    }
    This is going to make sure that the text will always stay on the screen once it first appears, and when new text needs to be written the TEXT_BMP will be cleared, so the text won't overlap.

    Btw, usually you don't need to use acquire_screen() and release_screen() unless you're going to be using video memory and not virtual memory. At least that's what I do.


    ps If you have any questions regarding Allegro feel free to send me a PM at anytime.

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Cooll, it's working now.

    Thank you very much!!!!
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alegro help with rest, varibles, and textprintf
    By campsoup1988 in forum C++ Programming
    Replies: 0
    Last Post: 02-06-2006, 05:48 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  3. Help with blit
    By boontune in forum Game Programming
    Replies: 1
    Last Post: 01-17-2005, 02:35 PM
  4. Allegro and blit()
    By Paninaro in forum Game Programming
    Replies: 1
    Last Post: 07-06-2002, 04:52 PM
  5. My Allegro Program will not run...
    By Vicious in forum Game Programming
    Replies: 17
    Last Post: 06-14-2002, 12:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21