[AD] D3D bitmap drawing off

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


A lot has changed recently and I'm guilty of not keeping up
with the changes. Michael Swiger reported to me that the D3D
driver is not drawing correctly and I investigated and found
that it is now using the exact coordinates given by the user.
The public interface uses OpenGL coordinates, but D3D's
coordinates are different: 0,0 in D3D (as a point in space,
not a texture coordinate) is the middle of the first pixel,
while in OpenGL it's the top left of that pixel. So 0.5 needs
to be subtraced from coordinates that the user passes in or
you get messed up drawing. This patch fixes it but I want to
make sure, especially with Paul, that this is not going to
cause problems for him. I don't think it should. Also I've
attached the programs I used to test the drawing to make sure
it's exactly like in OpenGL. test.cpp will write out 3 bitmaps.
Run it under OpenGL, change PREFIX, then run under D3D. You'll
get 6 bitmaps which you can compare with compare.cpp. No output
means they're the same. I don't get any output here.

Trent :{)>

Attachment: zero_point_five.diff
Description: Binary data

#include <cmath>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_image.h>

#define PREFIX "ogl-"

int main(void)
{
	al_init();
	al_init_image_addon();

	ALLEGRO_DISPLAY *d = al_create_display(640, 480);

	ALLEGRO_BITMAP *b = al_load_bitmap("b.png");
	ALLEGRO_BITMAP *rect = al_load_bitmap("r.png");

	int w = al_get_bitmap_width(b);
	int h = al_get_bitmap_height(b);

	ALLEGRO_BITMAP *b2 = al_create_bitmap(w, h);

	al_set_target_bitmap(b2);
	al_draw_bitmap(b, 0, 0, 0);
	al_save_bitmap(PREFIX "1.png", b2);

	al_set_target_bitmap(al_get_backbuffer());
	al_clear_to_color(al_map_rgb(0, 0, 0));
	al_draw_scaled_bitmap(rect, 0, 0, 50, 50, 0, 0, 640, 480, 0);
	al_flip_display();
	al_rest(2);
	al_save_bitmap(PREFIX "2.png", al_get_backbuffer());

	al_set_target_bitmap(al_get_backbuffer());
	al_clear_to_color(al_map_rgb(0, 0, 0));
	al_draw_rotated_bitmap(b, w/2, h/2, 320, 240, M_PI/4, ALLEGRO_FLIP_VERTICAL | ALLEGRO_FLIP_HORIZONTAL);
	al_flip_display();
	al_rest(2);
	al_save_bitmap(PREFIX "3.png", al_get_backbuffer());
}
#include <cstdio>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_image.h>

int main(int argc, char **argv)
{
	al_init();
	al_init_image_addon();

	ALLEGRO_DISPLAY *d = al_create_display(640, 480);

	ALLEGRO_BITMAP *b1 = al_load_bitmap(argv[1]);
	ALLEGRO_BITMAP *b2 = al_load_bitmap(argv[2]);

	int w = al_get_bitmap_width(b1);
	int h = al_get_bitmap_width(b2);

	al_lock_bitmap(b1, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
	al_lock_bitmap(b2, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			ALLEGRO_COLOR c1, c2;
			c1 = al_get_pixel(b1, x, y);
			c2 = al_get_pixel(b2, x, y);
			unsigned char r1, g1, b1, a1;
			unsigned char r2, g2, b2, a2;
			al_unmap_rgba(c1, &r1, &g1, &b1, &a1);
			al_unmap_rgba(c2, &r2, &g2, &b2, &a2);
			if (r1 != r2 || g1 != g2 || b1 != b2 || a1 != a2) {
				printf("%d %d differs\n", x, y);
			}
		}
	}
}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/