CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Posts
    5

    Newbie - simple image display

    Hi
    i am new here.
    I dont know much about programming (just basic stuff).
    I would like to make an excecutable which simply displays a tiny graphic in the center of the screen, and should always be shown ontop of everything.
    I think its easy.. But no idea how to apoach it
    A developed idea would be that it identifies an name of a file eg "image" and uses that, so i would be able to change the image without reprograming )
    Any ideas/sample script would be veeeeeerryyyyyy much apretiated.

    thanks so much in advanced!!!
    Last edited by Mosaka; April 16th, 2008 at 12:11 PM.

  2. #2
    Join Date
    Oct 2008
    Posts
    47

    Re: Newbie - image always ontop

    well if its a web application or page you need to define the z index as constant and 0


    Hope this helps,
    Larry D

  3. #3
    Join Date
    Feb 2009
    Posts
    6

    Re: Newbie - image always ontop

    you'd draw the image after you do everything else, always.

    the way you'd do this is load all the images/files/sounds.

    then enter a loop that the logic of your program is carried out in.

    the last thing you should do in your loop is update your screen.

    if you want your image to always be on top, draw that to the screen last.

    example, allegro probly has the easiest way to load images and a screen to draw on
    that's why I chose it for this example:

    Code:
    #include <allegro.h>
    BITMAP* buffer = NULL;
    BITMAP* interface = NULL;
    BITMAP* your_little_pic = NULL;
    
    int main(){
    allegro_init();
    set_color_depth(16);
    set_gfx_mode(640,480,0,0);
    buffer = create_bitmap(640,480);
    interface = load_bitmap("interface.bmp", NULL);
    your_little_pic = load_bitmap("pic_i_always_want_on_top.bmp", NULL);
    
    while (1){
    //do whatever needs to be done in your program
    //then draw whatever needs to be drawn to a buffer
    //then the screen
    draw_sprite(buffer, interface,0,0)
    draw_sprite(buffer, your_little_pic,(SCREEN_W/2) + (your_little_pic->w/2), (SCREEN_H/2) + (your_little_pic->h/2)) 
    draw_sprite(screen, buffer, 0,0)
    
    }
    
    destroy_bitmap(buffer);
    destroy_bitmap(your_little_pic);
    destroy_bitmap(buffer);
    
    return 0;
    }
    END_OF_MAIN()
    you'd want to separate things into functions obviously but that's how you'd set a picture in the middle of the screen and make sure its always drawn on top of everything else. Hope you find that useful, check out allegro if you want to get into low level graphics programming. It's probly the easiest and best 2d library there is.

    edit: lawl I just noticed how old this post is
    Last edited by PerksPlusPlus; February 2nd, 2009 at 01:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured