Blitting using SDL

Started by
15 comments, last by enygmyx 20 years, 3 months ago
hi ppl, i was writing an AVI player (for playing AVI in cutscenes etc) ...... i have done alomost all the basic stuff .... now what i do is i read the bitmap(BITMAPHEADERINFO thingy) data and blit it on my screen (SDL Surface) .... but the problem i am facing is that the video is playing upside down ..... i dunno wat is the problem ..... but i think that i am not using SDL_BlitSurface properly ..... has ne1 else faced this problem ..... can anyone help me with this one ..... is it because of SDL blitting or sumthin else .... thanx in advance, enygmyx.
Advertisement
Try this link here

I''m pretty sure that it is the case that BMPs are stored upside down.
Another thing to note, is that direct3D surfaces are also upside down as compared with OpenGL textures.

So if you end up writing your BMP loader code to display images on Direct3D surfaces, you will need to bare that in mind.

www.wreckedgames.com
thanx for the quick response but i don't quite know how to do that in my case ...... since i am not actually creating a BMP .... this is how i do it ......
first get the frame data header .....
(LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);

get the actual raw data ....
pdata=(char *)lpbi+lpbi->biSize;

create a SDL surface using the data just read:
SDL_CreateRGBSurfaceFrom(pdata, info.dwWidth, info.dwHeight, sampleSize, info.dwWidth* (sampleSize/8),R_mask, G_mask, B_mask, A_mask);

finally blit the surface:
SDL_BlitSurface(frame, NULL, S, &dest);

now since i am not creating a texture and then mapping it on some surface hence cannot invert texture coords like it was said in the post pjcast reffered to ..... how can i inverse the bitmap data in my case (i do not want to use any brute force thing like reversing the data using a loop etc.)
thanx in advance,
enygmyx.

[edited by - enygmyx on January 12, 2004 2:33:53 AM]
I am not familiar with SDL, but if you don't want the brute force method, is it possible to map the texture to your quad so that it's upside down?

Or, possibly, just rotate your quad so that it's upside down, which would have no per frame speed penalty (like manually flipping the bitmap)

EDIT - Ahwww, I just saw that you are not mapping...

What are you doing with the bmp data?

[edited by - pjcast on January 12, 2004 2:58:32 AM]
Maybe someone with more specific knowledge of SDL fuctons can be of more help...

But, I suggest that you write the data to a texture, instead of using SDL_BlitSurface.

You can check out a NeHe tutorial here on AVIs
as pjcast said someone with good SDL knowledge cud help here .... someway that wud allow me to make the SDL surface correctly or blit the surfce inverted ....

well apart from the main question .... i wud also like to know if it is better the way in which i am doing it or is it better that i make texture from the data and map it on some quad?? .....

thanx in advance,
enygmyx.
Hi.

I''m using SDL in my OpenGL projects for a variety of things and up ''til now I''ve had the same problem, that is that anything I load into an SDL_Surface is turned upside/down. I was too lazy too try and isolate the problem and correct it but your question fired up my curiosity so I did some coding. Here''s what I did :
- tried to load a BMP into an SDL_Surface using the SDL_LoadBMP function. Result : texture turned upside/down
- tried to a BMP into an SDL_Surface using my own loading routine. Result : texture turned upside/down
- tried to load a BMP into my own ... err.. let''s call it a "texture structure" (though it is only an unsigned char array...). Result : texture correctly applied

So I guess that SDL_Surface displays it upside/down when the data is accessed, though I don''t understand why...

Hope this helped a bit.
"I have questions. Questions that need answering !" - Gandalf the gray, The fellowship of the ring
thanx Trexmaster ..... ur post was helpful in a way that it kinda confirmed that the problem is with SDL_Surfce/SDL bliting
.... but the problem still remains ..... how to rectify this problem .... are there any SDL gurus who can help us poor souls with this ... i just joined the SDL mailing list i will also post this question there and lets see wat happens .....
Trexmaster u said that u have had problems SDL_LoadBMP function ..... but i never had any problems using that ..... also i wud like to know whether u were blitting the surface after loading it or sumthin else ..... especially in the third case where u didn''t use a SDL surface .... did u use SDL_BlitSurface after that ..... cus maybe the problem occurs with SDL_BlitSurface .....
i loaded a BMP using SDL_LoadBMP ..... and then Blitted it on my main surface(window) .... and the texture turned up ok.
kinda confusing and frustating ....
enygmyx.
enygmyx here''s my best guess at your problem,

Since using SDL_LoadBMP worked correctly and since using your own data flipped the image, I suspect the problem lies with the image''s pixel line data order. As pjcast stated, a bitmap stores line data in bottom to top order (bottom most line comes first in the data). Assuming SDL_Surface has its pixel lines in top to bottom order (I don''t know this for certain, just a guess) and when you try:

SDL_CreateRGBSurfaceFrom(pdata, info.dwWidth, info.dwHeight, sampleSize, info.dwWidth* (sampleSize/8),R_mask, G_mask, B_mask, A_mask);

that this SDL function assumes pdata is in top to bottom order. Therefore the resulting image would be upside down and assuming this is what SDL is doing, it is not exactly a problem with SDL but a mixup between two formats. SDL_LoadBMP works correctly because it expects this issue and therefore resolves it by swapping the line order before creating the surface.

The obvious solution is swap the lines before calling SDL_CreateRGBSurfaceFrom but there may be a supported function in SDL for this. I tried looking briefly but did not find any.

Gnork

This topic is closed to new replies.

Advertisement