![]() |
|
Is this me or Allegro?!? |
Don Freeman
Member #5,110
October 2004
![]() |
I'm trying to scale images to a temp buffer and then draw that image to the screen. The base image is a huge image of sprites that are 16x32. I'm using the following code to draw the individual sprites, but the destination is not correct and seems to be based on the scale factor. I'm sure I'm just missing something stupid but can't seem to see it at the moment. Any help would be appreciated. I'm using allegro-5.0.10 if that helps at all... 1bool DrawTerrainImage( ALLEGRO_BITMAP *terrainImage, float x, float y,
2 int terrainID, unsigned char scaleFactor )
3{
4 // TODO: add bounds handlers for known end points.
5 int dw = 16*scaleFactor;
6 int dh = 32*scaleFactor;
7 ALLEGRO_BITMAP *temp = al_create_bitmap(dw,dh);
8 if ( !temp )
9 return false;
10 ALLEGRO_STATE state;
11 al_store_state(&state,ALLEGRO_STATE_TARGET_BITMAP);
12 al_set_target_bitmap(temp);
13 // image, sx, sy, sw, sh, dx, dy,dw,dh, flags
14 al_draw_scaled_bitmap(terrainImage,16*terrainID, 0, 16, 32, 0, 0, dw, dh,0);
15 al_restore_state(&state);
16 al_draw_bitmap(temp,x,y,0);
17 al_destroy_bitmap(temp);
18 temp = NULL;
19 return true;
20}
21///////////////////////////////////////////////////////////////////////////////
-- |
#00JMP00
Member #14,740
November 2012
|
Does this compute?? unsigned char scaleFactor // I think the char should at least be converted to int or double int dw = 16*scaleFactor; |
Don Freeman
Member #5,110
October 2004
![]() |
Why? Could you imagine a case where you'd want to scale a 16x32 pixel sprite more than 255 times!? DrawTerrainImage(terrain,10,10,5,10); DrawTerrainImage(terrain,200,200,16,5);
{"name":"609380","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/1\/d1fb89476a9b8f2e340ca30bbf83da14.jpg","w":400,"h":400,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/1\/d1fb89476a9b8f2e340ca30bbf83da14"} Edit: -- |
Chris Katko
Member #1,881
January 2002
![]() |
For one, I would do some input validation to be sure the problem is actually located in your function. Is this C or C++? I would check to verify in a debugger or with printf, that the values you're giving are all correct before they hit an Allegro function. Then, I'd make sure all of my Allegro/OpenGL transformations are set up correctly. Actually, that most definitely sounds like the problem if you're scaling AND THEN translating, obviously you won't get what you intend. It could also be a bug in that function, and I would check an Allegro 5 example that uses the function to see if it exhibits the same behavior. [edit] Don Freeman said:
Edit: Ah. -----sig: |
Don Freeman
Member #5,110
October 2004
![]() |
Yeah, I'm gonna clear the image to black during testing so I can see the edges of the images so something stupid like this doesn't happen again. -- |
|