Thread: clearing the screen

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    clearing the screen

    umm... i want to animate a bitmap according to what key the user is pressing. But when I use no clear screen functions the old bitmap is left behind. When I use a clear screen function then it is really sketchy. I used man different types of clear screen such as clear_to_color etc. I am not sure what I am doing wrong. Oh and I am using the allegro library with Dev C++ and windows 98 (if that matters)

    Code:
    #include <allegro.h>
    
    
    int main()
    { 
    
     allegro_init();      
    
    
     set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
     set_color_depth(16); // Set the color depth
    
     install_keyboard();
    
     BITMAP *pic;
     pic = load_bitmap("plane.bmp", NULL); // Load our picture
    
     int x=0, y=0;
    acquire_screen();
    
    while(!key[KEY_ESC])
    {if (key[KEY_UP])
      {y++;}
     if (key[KEY_DOWN])
      {y--;}
     clear_bitmap(screen);
     for (int i=0 ; i < 1; i++) { clear_bitmap(screen);
     vsync();
     blit(pic, screen, x, y, 0, 0, 640, 480);
      }
    }
    
    release_screen(); 
    destroy_bitmap(pic);//Release the bitmap data
     allegro_exit();
     return 0;     
    }     
    
    
    END_OF_MAIN();

  2. #2
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    try this clear screen function:
    Code:
    void cls()
    {
      union REGS i,o;
    
      i.h.ah = 6;
      i.h.bh = 7;
      i.h.ch = 0;
      i.h.dh = 24;
      i.h.al = 0;
      i.h.cl = 0;
      i.h.dl = 79;
    
      int86(16,&i,&o);
      gotoxy(1,1);
    }
    if your compiler doesn't have gotoxy(x,y) then add this function too:
    Code:
    void gotoxy(int x, int y)
    { 
    	HANDLE hConsoleOutput;
    	COORD dwCursorPosition;
    
    	dwCursorPosition.X = x;
    	dwCursorPosition.Y = y;
    	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    	SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
    }
    dont forget to include windows.h for the gotoxy function
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  3. #3
    Registered User Octorok101's Avatar
    Join Date
    May 2002
    Posts
    22
    will that code work for clearing text too?

  4. #4
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    i belive it clears the whole screen doesn't matter whats on it. (i hope )
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. clearing the screen
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 02-01-2005, 09:00 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Clearing the screen
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 05-23-2002, 01:40 PM