drawing to screen

This is a discussion on drawing to screen within the C++ Programming forums, part of the General Programming Boards category; I got the below code from a tutorial site somebody send me to, this seems to compile fine in Borland ...

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    drawing to screen

    I got the below code from a tutorial site somebody send me to, this seems to compile fine in Borland 5.02, but crashes when i try to run it.

    Code:
    #include <allegro.h>
    #define x 320 //defining the x coord for where the character bmp is going to be drawn 
    
    #define y 240 //same as above except for the y coord 
    
    void setup(); 
    
    void shutdown(); 
    
    BITMAP *character; 
    
    BITMAP *buffer; 
    
    int main() 
    
    { 
    
    setup(); 
    
    draw_sprite(buffer, character, x, y); //drawing the character bmp to the buffer 
    
    blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); //blitting the buffer to the screen so you can see everything 
    
    while(!key[KEY_ESC]); //while Esc key isn't pressed 
    
    ; 
    
    shutdown(); 
    
    return 0; 
    
    } 
    
    END_OF_MAIN();
    
    void setup() 
    
    { 
    
    allegro_init(); //initializes allegro 
    
    install_keyboard(); //installs the keyboard routines 
    
    set_color_depth(32); //this is setting the color depth to a true color mode 
    
    set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0); //setting the screen to 640, 480 resolution in fullscreen 
    
    buffer = create_bitmap(SCREEN_W, SCREEN_H); //creating the buffer as the same size as the screen 
    
    character = load_bitmap("name_of_bitmap.bmp", NULL); //loading the character bitmap 
    
    }
    
    void shutdown() 
    
    { 
    
    clear_keybuf(); 
    
    destroy_bitmap(buffer); 
    
    destroy_bitmap(character); 
    
    }
    ]
    AIM: MarderIII

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Is there actually a bitmap in your folder called name_of_bitmap.bmp?

  3. #3
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    no, ill see if that makes anything better
    AIM: MarderIII

  4. #4
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    it still crashes despite the addition of a .bmp of the proper name to the folder
    AIM: MarderIII

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    it still crashes despite the addition of a .bmp of the proper name to the folder

    Not sure what that mean...of the proper name to the folder? I'm guessing you mean you have a bitmap in the root folder that your prog is running from and you put the name of that bitmap in the code where it did read "name_of_bitmap.bmp"?

    Do you have allegro installed and set up right? I've never used it but as I understand it, there's more to it than just including the header file. Try PMing or emailing TechWins. I believe he's our resident Allegro Guru.

  6. #6
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    allegro? i dont know what allegro is. All im trying to do is use c++ to display a window, is c++ unable to do anything outside of DOS?
    AIM: MarderIII

  7. #7
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by Noobie
    allegro? i dont know what allegro is. All im trying to do is use c++ to display a window, is c++ unable to do anything outside of DOS?
    No, C++ is not unable to do it. But the way you're doing it is not correct. Allegro is a graphic's API. If by "display a window" you mean create your own GUI for a game using Allegro, then Allegro will work. If you mean write a Win32 app then no it won't work. For that you'll need to create a Win32 app (NOT a Win32 console app) and use the Window's API (or *shudder* MFC ).

  8. #8
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    I dont understand all these big words about API and all that nonsense, I just want code
    AIM: MarderIII

  9. #9
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You don't really want to learn anything do you?

    Go here and check out their Win32 section.

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    What's the

    Code:
    while(!key[KEY_ESC]); //while Esc key isn't pressed 
    
    ; 
    
    shutdown();
    ; doing there? Also all function return a boolean to see if there
    where any errors. I suggest you make an if to check on the
    key function set_graphics_mode and set_color_depth and
    load_bitmap.

  11. #11
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    1- There are no graphics in standard C++. Any graphics functions are "extra". Graphics is an advanced topic. You have to learn text based (console) C++ first.

    2- The graphics functions will be different for different graphics libraries, different compilers, different hardware, and different operating systems. So, you have to choose a particular graphics library that works with your compiler and learn to use it. Allegro seems to be very popular. Microsoft Visual C++ also includes lots of graphical functions that interface with the Windows API (Application Programming Interface). The Borland compiler can also make Windows GUI (Graphical User Interface) programs.

    3- Although it's easy to include simple graphics in a windows application, windows programs are NOT simple. (The "Hello Windows" program in Charles Petzold's book "Programming Windows" is about 50 lines of code.)

  12. #12
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    yah ive been to that site and their tutorials dont work, is there no site with tutorials for borland?
    AIM: MarderIII

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GDI - Drawing to the screen correctly
    By Tonto in forum Windows Programming
    Replies: 1
    Last Post: 06-24-2006, 10:53 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 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, 03:41 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 01:51 PM

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