- Online Community Forums » Programming Questions » polygon3d_f errors

Credits go to Kitty Cat for helping out!
This thread is locked; no one can reply to it. rss feed Print
polygon3d_f errors
Member #7,075
March 2006

Hi, I'm trying to write a portable image viewer, so I thought Allegro would be a good basis for doing this.

But I am having problems drawing the zoomed image with the polygon3d_f function. When I do the image comes out all garbled, with blank spaces between lines, then the program locks up.

I can do much the same thing fine when using the stretch_blit function, but stretch_blit only allows integer coordinates for the source region, so it isn't sufficient.

I am using Allegro 4.2 with MinGW on Windows XP.

Heres the code for stretch_blit which works fine:

void rect_image(BITMAP *const src, const rect_t src_rect, BITMAP *const dest, const rect_t dest_rect)
   stretch_blit(src, dest, src_rect.x1, src_rect.y1,
      src_rect.x2 - src_rect.x1, src_rect.y2 - src_rect.y1,
      dest_rect.x1, dest_rect.y1,
      dest_rect.x2 - dest_rect.x1, dest_rect.y2 - dest_rect.y1);

Heres the code for polygon3d_f which is problematic:

void rect_image(BITMAP *const src, const rect_t src_rect, BITMAP *const dest, const rect_t dest_rect)
   V3D_f vertices[4] = {
      {dest_rect.x1, dest_rect.y1, 0, src_rect.x1, src_rect.y1, 0},
      {dest_rect.x2, dest_rect.y1, 0, src_rect.x2, src_rect.y1, 0},
      {dest_rect.x2, dest_rect.y2, 0, src_rect.x2, src_rect.y2, 0},
      {dest_rect.x1, dest_rect.y2, 0, src_rect.x1, src_rect.y2, 0}
   V3D_f *vertex_pointers[4] = {
      &(vertices[0]), &(vertices[1]),
      &(vertices[2]), &(vertices[3])};
   polygon3d_f(dest, POLYTYPE_ATEX, src, 4, vertex_pointers);

And the rect struct:

typedef struct {
   float x1, y1,
         x2, y2;
} rect_t;

Full test code is attached.

Can anyone tell me what I'm doing wrong here?

Also could someone explain why polygon3d_f takes an array of pointers to V3D_f rather than just an array of V3D_f?

Kitty Cat
Member #2,815
October 2002

What's the size of the source bitmap? Is the width and height powers of two?

As a side note, you should probably also pass the rectangles as pointers to rect_image. That'll keep you from making extra copies of the variables on the stack.

"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Member #7,075
March 2006

Arg! That is probably it. I thought it may be something like that, but when looking in the manual my eyes missed it.

The problem is that power of two BITMAPs isn't really feasible for my purposes (loading very large, think gigabytes, partitioned images) as expanding the bitmaps to fit will waste a lot of memory which is at a premium.

I guess I'll have to write my own drawing function. Maybe modify stretch_blit to take float source geometry.

Thanks Kitty Cat.

Arthur Kalliokoski
Second in Command
February 2005

You mean the destination bitmap needs to span only part of a huge pixel? You could stretch blit to a huge memory bitmap, then blit from that to the screen. In other words, the huge pixels would be "splittable" with integer coords.

They all watch too much MSNBC... they get ideas.

Go to: