Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Is this me or Allegro?!?

This thread is locked; no one can reply to it. rss feed Print
Is this me or Allegro?!?
Don Freeman
Member #5,110
October 2004
avatar

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...

#SelectExpand
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///////////////////////////////////////////////////////////////////////////////

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

#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
avatar

Why? Could you imagine a case where you'd want to scale a 16x32 pixel sprite more than 255 times!?
Edit:
As an example, here is the command to draw and then the output...

   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"}609380

Edit:
Nevermind. ::) I feel dumb hahaha. I forgot that half y of the image is transparent on most of the sprites, so it just looked off by that much. I'll probably store these all in a structure during loading so I don't have to do stretching every draw cycle. Thanks all.

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Chris Katko
Member #1,881
January 2002
avatar

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]

Edit:
Nevermind. ::) I feel dumb hahaha. I forgot that half y of the image is transparent on most of the sprites, so it just looked off by that much. I'll probably store these all in a structure during loading so I don't have to do stretching every draw cycle. Thanks all.

Ah.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Don Freeman
Member #5,110
October 2004
avatar

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. ;)

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Go to: