Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problem rotating a bitmap

This thread is locked; no one can reply to it. rss feed Print
Problem rotating a bitmap
GTP195
Member #13,916
January 2012

Hi everyone!
I'm writing a program using Allegro 5 in order to understand how works this new version of the library. My code draws half of a barable, the X axys and the Y axys at the centre of the screen. Now I have to rotate this parable and show on the screen the rotated version. I used al_draw_rotated_bitmap() but my program chrashes. Here is my code. What's wrong?

#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>

int x=10;
int y=-1;
int a,b,c,xassex,yassex,xassey,yassey,x2;
ALLEGRO_BITMAP *parabolaruotata, *display;
int main()
{

printf("Valore di a? ");
scanf("%d", &a);

printf("Valore di b? ");
scanf("%d", &b);

printf("Valore di c? ");
scanf("%d", &c);

al_init();
al_init_primitives_addon();

display=al_create_display(1024,768);
parabolaruotata=al_get_backbuffer(display);

al_set_target_bitmap(display);
while(EOF){


for(x=0;x<=500;x++){
y=a*x*x+b*x+c;
x2=x+1024/2; //sposta la parabola
al_put_pixel(x2,y,al_map_rgb(200,10,200)); //disegna la parabola
}

al_draw_line(0,768/2,1024,768/2,al_map_rgb(200,0,0),1); //disegna l'asse x centrato
al_draw_line(1024/2,0,1024/2,768,al_map_rgb(200,0,0),1); //disegna l'asse y centrato
al_set_target_bitmap(parabolaruotata);
al_draw_rotated_bitmap(display, 1024/2, 768/2, 0, 768, ALLEGRO_PI, 0);

al_flip_display(); //serve per passare dal buffer al backbuffer




}
al_destroy_bitmap(display);
al_destroy_bitmap(parabolaruotata);
return 0;
}

weapon_S
Member #7,859
October 2006
avatar

Lots of wrongs... Use <code></code> to format your forum post.

GTP195 said:

The display is not a bitmap. Use <code>al_get_backbuffer(display)</code> to get the backbuffer bitmap of the display, or <code>al_set_target_backbuffer(display)</code> to set the target bitmap to the backbuffer bitmap of the display.

Quote:

while(EOF)

What?

Quote:

al_draw_rotated_bitmap(display, 1024/2, 768/2, 0, 768, ALLEGRO_PI, 0);

You want to draw the display to... the display? Remember: the target is set with al_set_target_bitmap or al_set_target_backbuffer. The source you are drawing is given to this function. AND you can't have any part of the screen as a source.

Quote:

al_destroy_bitmap(display);

Again: the display is not a bitmap. It does have a backbuffer that is a bitmap.

Quote:

al_destroy_bitmap(display);

You don't need to destroy the backbuffer manually. It is even very wrong.

Turn on warnings of your compiler. With gcc you use the "-Wall" option to do that. (The option is case sensitive.)
By the way: 1 axis, 2 axes, parabola.

[Edit]
That use of "display" was really confusing... You need a 'display'[1]! The 'display' is everything you need for graphical output.

References

  1. An ALLEGRO_DISPLAY* to be specific.
Gabriel Campos
Member #12,034
June 2010
avatar

You dont create a display to show window....

ALLEGRO_BITMAP *display; // wrong

ALLEGRO_DISPLAY *display; // correct

al_draw_rotated_bitmap(display, 1024/2, 768/2, 0, 768, ALLEGRO_PI, 0); // as weapon_S said this is wrong...

al_draw_rotated_bitmap(parabolaruotata, 1024/2, 768/2, 0, 768, ALLEGRO_PI, 0); // the correct parameter is the bitmap you create

GTP195 said:

while(EOF)

Whaaaat??
;D

look this tutorial
http://wiki.allegro.cc/index.php?title=Allegro_5_API_Tutorials

Go to: