Okay the thing is that, as I stated earlier, I use SDL in OpeGL projects. So in fact, the SDL_Surface was just used as a temporary stocking space for the bitmap data before I generate a texture with the glTexImage2D() function. So nope, no blitting at all.
I was originally using SDL_LoadBMP and SDL_Surface because I''m doing multiplatform projects ()Windows/Linux) and I knew these ones were portable, but now I guess I''ll juste use my own function and see if it works under Linux as it does under Windows (really hope it does ).
Btw I could also have just inverted the texture coordinates'' up and down sides to get it correctly mapped.
Blitting using SDL
I don't remember where I snagged this little code snippet, but it may help your problem
[edited by - yspotua on January 13, 2004 5:46:33 PM]
//This function returns a OpenGl compaitble texture from an SDL SurfaceGLuint loadTexture(const char *path){ SDL_Surface *surface = SDL_LoadBMP(path); if( !surface ) return 0; if((surface->format->BytesPerPixel != 3) && (surface->format->BytesPerPixel != 4)) return 0; GLuint texture = 0; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); int retVal = gluBuild2DMipmaps(GL_TEXTURE_2D, surface->format->BytesPerPixel, surface->w, surface->h, surface->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); return texture;}
[edited by - yspotua on January 13, 2004 5:46:33 PM]
It sounds to me like you need to use SDL_Flip(surface);
If you can''t do that then make it so you can All data that you load into memory is stored upside down (for optimization reasons) and when you just blit it straight to the screen that is how it shows it.
If you can''t do that then make it so you can All data that you load into memory is stored upside down (for optimization reasons) and when you just blit it straight to the screen that is how it shows it.
first of all i wud like to ask if it is better to make a texture or do it the way i am doing it (performance wise)......i did it using SDL_BlitSurface cus i personally thought that it wud be faster than making a texture and mapping it on a quad .......
anyways thanx for the tips ppl .... really appreciate that but i was looking if there was some way to invert the screen in SDL .... i have looked around documentation, mail list archives etc but can''t seem to find that ...... maybe someone cud help ....
Sir_Brizz:
SDL_Flip doesn''t Flip/Invert the screen .... it is like GL SwapBuffers .... to be used with double buffering .... so basically it swaps the front and back buffer .......
enygmyx.
anyways thanx for the tips ppl .... really appreciate that but i was looking if there was some way to invert the screen in SDL .... i have looked around documentation, mail list archives etc but can''t seem to find that ...... maybe someone cud help ....
Sir_Brizz:
SDL_Flip doesn''t Flip/Invert the screen .... it is like GL SwapBuffers .... to be used with double buffering .... so basically it swaps the front and back buffer .......
enygmyx.
This creates a new SDL_Surface which is a flipped version of the one passed in:
Hope it formats right.
EDIT: Close enough.
[edited by - TravisWells on January 14, 2004 8:52:33 PM]
SDL_Surface *FlipSurfaceV(SDL_Surface *bitmap){ if(!bitmap)return NULL; SDL_Surface *temp=SDL_CreateRGBSurface(0,bitmap->w,bitmap->h, bitmap->format->BitsPerPixel,bitmap->format->Rmask,bitmap->format->Gmask, bitmap->format->Bmask,bitmap->format->Amask); if(!temp)return NULL; SDL_Rect src,dest; src.w=bitmap->w; src.h=1; src.x=0; dest.x=0; int origh=bitmap->h; for(int i=0;i<origh;i++){ src.y=i; dest.y=(origh-1)-i; SDL_BlitSurface(bitmap,&src,temp,&dest); } return temp;}
Hope it formats right.
EDIT: Close enough.
[edited by - TravisWells on January 14, 2004 8:52:33 PM]
Okay, the reason SDL reads from top down is because the coordinate system starts in the upper-left corner of your screen; positive-y is downward so when the image is blitted, it is blitting correctly; all you have to do is redefine how your image rects are defined: top-left of your image is (x,y) and bottom right is (x+width, y+height).
HTH
HTH
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement