delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/31/13:30:21

Message-Id: <199810311830.SAA11189@relay.clara.net>
From: "Arthur" <arfa AT clara DOT net>
To: <djgpp AT delorie DOT com>
Subject: RE: helpppp allegroooo
Date: Sat, 31 Oct 1998 18:25:17 -0000
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Importance: Normal
In-Reply-To: <71f2u2$4dt$1@news.kornet.nm.kr>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp AT delorie DOT com

> first, i allocate on memory which of the picture, size of 800 * 600.
> next i want to see on the monitor of the size of 640 * 480.
> to see the last parts of the picture, i'd like to use keyboard.
> but i can't work...;;

Here we go then...

> my source are..
>
> #include <allegro.h>
>
> typedef unsigned char BYTE;
> typedef unsigned int UINT;

:-)

> BITMAP *back;
> BITMAP *vback;
> PALLETE pal;

Don't need pal. See below.

>
> void init()
> {
>     allegro_init();
>     install_keyboard();
>     set_color_depth(24);

You may like to set_color_conversion(COLORCONV_TOTAL); - depends on what
colour depth and PCX version your file is saved in.

>     set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
>     vback = create_bitmap(800,600);

vback only needs to be the same size as the screen - 640x480

>     clear(vback);
>
>     back=load_pcx("db.pcx",pal);
>     set_pallete(pal);

Not necessary for true colour! Delete the PALETTE statement near the top,
the line above, and change the line above that to
"back=load_pcx("db.pcx",NULL)". Make sure you #include <stdlib.h> too.

> }
>
> void close()
> {
>     destroy_bitmap(vback);
>     destroy_bitmap(back);
> }
>
>
> main()

main() always returns an int: "int main(void)" in C or "int main()" in C++
(strictly speaking).

> {
>     UINT x=0, y=0;

:-)

> init();
>
>     while(1)
>     {
>         if(key[KEY_LEFT])  { x-=5; if(x < 0) x = 0;}
>         // x is move to minus. i dont want.

x will never be negative since you assigned it to a UINT - an unsigned int!

>         if(key[KEY_RIGHT]) { x+=10; if(x > 160) x = 160;}
>         // this is OK
>         if(key[KEY_UP])    { y-=5; if(y < 0) y = 0;}
>         // y is move to minus. i dont want.

Same here!

>         if(key[KEY_DOWN])  { y+=10; if(y > 120) y = 120;}
>         // OK, too
>         if(key[KEY_ESC]) {remove_keyboard(); break;}

remove_keyboard() isn't necessary here since allegro will do it when you
exit.

>         blit(back, vback, x, y, 0, 0, 800, 600);
>         blit(vback, screen, 0, 0, 0, 0, 640, 480);
>       clear(vback);

For flicker-free scrolling, add a vsync() after you blit to the screen (and
install the timer handlers).

>     }
>     close();

return 0;

> }
>
> thanks.

No problem.

James Arthur
jaa AT arfa DOT clara DOT net
ICQ#15054819


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019