Hi, what I need to do is to save the part of the backbuffer (because I need to save complex multisampled primitive that I don't want to draw everytime the screen refreshes again, because it is very slow...). Now I now that HW accelerated multisampling can be used only when drawing to backbuffer, so this is probably what I need to do.

- display is valid and properly initialized variable- it maybe confusing why there are "2 displays", actually both pointers point to the same object, it's just "forward thinking".- it always crashed with "access violation" when calling al_draw_bitmap_region.

Am I missing something? I don't insist on doing this this way, I just need to make it as fast as possible...

Is it supposed to crash? It doesn't here on MacOS X. If you're running Windows, can you try putting a "al_set_new_display_flags(ALLEGRO_OPENGL);" before creating your display? See if that works. Also, are you sure that the png is found and loaded? Try drawing it to the screen to make sure?

Ok then it's a bug in the D3D driver. The code for drawing from the backbuffer to other bitmaps I was never really sure of and am still not sure what's the best way to do it. It's always been pretty slow but a crash is not good. Problem is I've got stuff to do. Maybe tonight I can look at it and try to fix it. If you want to look at it the code is in src/win/d3d_bmp.cpp around line 661 and calling into some functions from there.

Thank's a lot for Your time. Well I could look at the code but I doubt that would be of any good. The thing is that I have a basic knowledge of OpenGL (univerzity course scope), but I know almost nothing about DirectX...

Could you please upload the image you're using? I tried your example on Win7 x64 and it doesn't crash with the image I tried. It could also be something fixed in 5.1, so I'm attaching my compiled example which I'd like you to try:

If you could also go to http://www.kludx.com and run the binary from there and submit the info and give me the link, or find info on your graphics card that is already on the site, that would be most helpful.

Now this is interesting... The example you posted works fine (after downloading all the additional dependencies...) - no crash. My system is also Win7 x64.

I ran kluDX but I don't exactly know how am I suppose to send you the link when everything I got from the program is "Data sent to server. Thank You!". And I can't find the Graphics card on the site niether. But it's GTX 460 (1GB version).

I attach the image I tried to render in the simple example I posted. But I don't think that matters, because I can render it with no problems. It's just that I cannot draw from backbuffer...

//edit: I found another interesting thing. When I use Allegro 5.0.5 instead of 5.0.1 in this simple example, then the line:

al_draw_bitmap_region(backbufferImage, 200, 200, 400, 100, 0, 0, 0);

...does not crash but it doesn't do, what it should (meaning it does nothing), which is again fixed when i set OpenGL rendering...

By "it does nothing", I mean exactly that it does nothing :-) . The bitmap that I draw to stays the same as it was before executing this line. This happens with 5.0.5 with 5.0.1 it crashes with "access violation" as I mentioned before.

Well, the only way this is going to get resolved is in the 5.1 branch before it's backported to 5.0.x. So if you want a fix, first try 5.1 (you'll likely have to compile it yourself). If it doesn't work there, then I will try and fix it.

So basically I need to use OpenGL, or I have to drop multisampling... Do I get it? Or what is the problem with "locking" as you mention?

//edit: What am I actually trying to acomplish is, that I need to render a graph, function of which is very difficult (time consuming) to evaluate. This graph, however, does not refresh very often so my idea was to render it to the image which can then be drawn immediately without the need to calculate the function (as long as it is up to date...). But I can't render to an image when using multisampling (actually I can but it would not be multisampled...). So that's why I wanted to copy the content of the backbuffer. Anyway, can you think of some alternate way to do this? (well, I know that I can store the values of the function in some array, but that would have to be dynamically allocated and thus not as fast as saving the whole graph as an image in video memory).

You either have to find an alternative to locking that allows drawing parts of the backbuffer to bitmaps when multisampling is on, use OpenGL, or don't use multisampling. But I'm not really sure why you need to draw the backbuffer to a bitmap. Maybe if you tell me your use case I could figure something out.

Well I just updated the post above before reading your answer, so the reason is there...

Thanks a lot.

//edit: I found this outline on StackOverflow (thread). It seems helpful, but it is of course not clear to me whether that would solve the problem...

rt = get render target surface (this can be surface of the texture, or backbuffer, etc.)

if rt is multisampled (GetDesc, check D3DSURFACE_DESC.MultiSampleType), then: a) create another render target surface of same size, same format but without multisampling; b) StretchRect from rt into this new surface; c) rt = this new surface (i.e. proceed on this new surface).

Well that means to build Allegro on my own I guess... All right I'll do it when I wake up (it's 2 o'clock am here...).

Thank's.

P.S. I tried doing this with ALLEGRO_OPENGL. But when I render the graph from the image in memory (region that I copied from backbuffer to ALLEGRO_BITMAP), it does not look exactly the same as the original result. It seems to be more aliased even though some multisampling is obviously there... Almost like there was some post-processing when flipping buffers :-) But I will try the DX version before going further.

Thank's again.

//edit: I'm just not able to build it even without doing the change... The CMake configuration and generating works fine as well as doing "BUILD ALL". But INSTALL gives some strange error...

I don't want to bother you with that, because that is of course not even related to the discussed problem. That's just to let you know that I'm not able to test it... It's just that I can't build Allegro.

//edit2: One more question... When I copy anything (using al_draw_bitmap_region(backbufferImage, region.origin.x, region.origin.y, region.size.x, region.size.y, 0, 0, 0);), does this include aplha channel*? If so, can I do it such a way, that the resulting image is 100% opaque? Maybe using this function is not even a good idea and I should use blit or something like that. I just don't really know...

*Normally it would but when the source image is backbuffer I don't really understand what would the alpha channel be good for...

//edit3: Yeah, the image copied from the backbuffer is definitely diferent from the original. I just can't explain that. When I copy the backbuffer to the ALLEGRO_BITMAP and then render it again, it's different. To be more specific, the multisampled line is different. The rest stays the same... (see attachements). This concerns OpenGL case. I was not able to run corrected DX version so far...