Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Smooth Animation

This thread is locked; no one can reply to it. rss feed Print
Smooth Animation
miguel meza
Member #5,447
January 2005

Hi, i am doing the arkanoid game, an for the ball i am using a .bmp file.
I am using the double buffering tech, and for drawing the ball i am using the
draw_sprite(bmp, sprite, x, y) i draw the sprite to the buffer (for the double buffering) and then the buffer to the screen.
I am using acquire_screen and acquire_bitmap before drawing and then releasing them, but i the animation of the ball does not look smooth....
i read that i may have to activate the GFX_HW_VRAM_BLIT_MASKED in the gfx_capabilities.
Is that the answer to my problem?,
if yes, HOW do i activate it and where do i put it?
if not, what can i do?

(i am using winxp and have an nvidia geforce 440go 32ram, pentium4)....

thanks....

GullRaDriel
Member #3,861
September 2003
avatar

it's automagically activated if supported (or i'm thinking wrong)

You can just check if it is or not.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

miguel meza
Member #5,447
January 2005

if it is activated by default then that's not the solution :-/:-/
and how is the code to activate it?, and how do i check it?

thanks....

Tobias Dammers
Member #2,604
August 2002
avatar

You don't need to activate anything. Instead, to take advantage of hardware vram blitting, you must do the following:
1) Your back buffer must be a video bitmap. This is the case in all page flipping and triple buffering scenarios, but you can also implement a double buffer system with blit using a video back buffer.
2) Your sprites must be in VRAM. Allegro loads everything as memory bitmap by default, so you have to manually copy them to video bitmaps.

If your hardware supports it, all video-video blits are accelerated.

However, I don't think that this is your problem. Unless you're doing something horribly wrong (like loading bitmaps every frame), your machine should be perfectly capable of producing smooth output without hardware accel.
The problem can be:
- A timer issue. This is especially likely if you use allegro timers, which have a ~10ms granularity in windows, making them all but precise. Look into QueryPerformanceCounter() for windows, gettimeofday() for linux.
- It is also possible that your program layout isn't optimal. Your timing code may be generally off, you might be checking for input the wrong way, a thousand things can be wrong.
- You might have made a mistake implementing the double buffer.
- Maybe you are using game logic that produces glitches.

If it's not too large, I suggest you post your code here (use code tags).

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

miguel meza
Member #5,447
January 2005

Ok, this is some part of the code:
(i do use allegro timers)

this is my main:

int main(int argc , char *argv[])
{  
  srand(time(NULL));
  Init();      
  MainLoop();  
  return 0;
}
END_OF_MAIN();

this is the Init method

void Init()
{  
       // all the graphics and sound initialization
       // and TIMERS
  InitializeAllegro();      

      // load the bitmaps
  ball =load_bitmap("ball.bmp", NULL); 
  bar = load_bitmap("barra.bmp", NULL);    
  brick = load_bitmap("brick1.bmp", NULL);
  buffer = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT);  
       
      // OTHER STUFF.....
}

this is the mainLoop

1void MainLoop()
2{
3 g_EndGame = false;
4 
5 while ( !g_EndGame)
6 {
7 // for the TIMER
8 while( g_speed_counter > 0 )
9 {
10 if ( key[KEY_ESC] )
11 {
12 g_EndGame = true;
13 }
14
15 // all the logic, collisions and math of the game
16 DoGameLogic();
17 g_speed_counter--;
18 }
19 
20 // draw everything
21 RenderScene();
22 
23 if ( g_EndGame )
24 QuitGame(); // destroy sound and bitmaps
25 }
26}

and this is the MOST important method called in my RenderScene

1void Draw(float barX, float barY, float ballX, float ballY)
2{
3 //acquire_screen();
4 //acquire_bitmap(bar);
5 //acquire_bitmap(ball);
6 
7 // this will be draw to the buffer (for double buffering)
8 draw_sprite(buffer, bar, barX,barY);
9 PaintBricks();
10 draw_sprite(buffer, ball, ballX, ballY);
11
12 // Draw the buffer to the screen
13 blit(buffer, screen, 0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);//
14 clear_bitmap(buffer); // Clear the contents of the buffer bitmap
15
16 //release_bitmap(ball);
17 //release_bitmap(bar);
18 //release_screen();
19}

if i uncomment the the acquire and release bitmaps the result is the same.....
hope someone can help me....

Jonatan Hedborg
Member #4,886
July 2004
avatar

I cant see anything wrong with that code, at least now - the acquire_screen and acquire_bitmap are bad. don't use them. Only use acquire_screen if you make more than one consecutive blit to video memory.

Anyway, how about posting the logic code and the actual init code?

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

miguel meza
Member #5,447
January 2005

ok, here goes mi InitAllegro and Logic code.....

Here is the InitializeAllegro and the TIMER code called in "init()"

1volatile int g_speed_counter = 0;
2void InitializeAllegro()
3{
4 if(allegro_init() != 0)
5 return;
6
7 set_window_title( g_AppName );
8
9 if( install_keyboard() != 0 )
10 return;
11
12 if( install_mouse() <= 0 )
13 return;
14
15 // load sounds
16 if ( install_sound(DIGI_AUTODETECT ,MIDI_AUTODETECT, 0) == 0)
17 {
18 music = load_midi("LISZT2.mid");
19 sound = load_wav("bong.wav");
20 sound1 = load_wav("loss.wav");
21 sound2 = load_wav("gameover.wav");
22 }
23 
24 // get and set color depth
25 bpp = desktop_color_depth();
26 if( bpp != 0)
27 {
28 set_color_depth(bpp);
29 }
30 else
31 {
32 bpp = 16;
33 set_color_depth(bpp);
34 }
35 
36 SCREEN_WIDTH=800;
37 SCREEN_HEIGHT=600;
38
39 // set video mode
40 if( set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, SCREEN_WIDTH , SCREEN_HEIGHT , 0 , 0 ) != 0 )
41 return;
42 
43 install_timer();
44 
45 LOCK_VARIABLE(g_speed_counter);
46 LOCK_FUNCTION(CheckForSpeed);
47 install_int_ex(CheckForSpeed , BPS_TO_TIMER(60));
48 
49}
50 
51// this is for the timer
52void CheckForSpeed()
53{
54 g_speed_counter++;
55}
56END_OF_FUNCTION( CheckForSpeed );

and here is the "logic" code:

1void DoGameLogic()
2{
3 if ( key[KEY_SPACE] )
4 moveBall = true;
5 
6 if ( moveBall )
7 {
8 cBall.X += speedX;
9 cBall.Y += speedY;
10 }
11 
12 CheckCollision();
13 
14 if(keypressed());
15 CheckMovement();
16}

Jonatan Hedborg
Member #4,886
July 2004
avatar

And checkcollision? You could try and add a vsync(); before you blit to screen as well. just for fun...

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

miguel meza
Member #5,447
January 2005

my CheckCollision code is unclear, and i dont think that could be the problem because i only do simple math things there, so there is anything related with drawing....

i remove the acquire methods and added vsync() and the result is the same :-/
what can it be??? ???

Go to: