SDL .png problem
I use alot of .png's in my game with transparency, up till now it has not caused a issue.
but when I put the surface I made from part of a sprite sheet (the sheet, uncut, works fine) it seams to need a surface behind it with non transparent pixels, it seams to act like the image behind it is a alpha channel, if I put a dot in the middle of the image behind it that only within that dot will the top image show.
and yes this was as much of a bitch to figure out as it sounds
what i am doing is setting the three surfaes I am getting from my sprite sheet first equal to a white square, then puting the image from the sprite sheet on them, if I dont do that then I cant see the images at all
the corret surface is then passed out of the function and blit, but that part works fine and is long so I did not put it here
[Edited by - JoshPike on November 29, 2009 12:59:33 PM]
SDL_Surface *spriteSheet = NULL;SDL_Surface *icon_Right = NULL;SDL_Surface *icon_Left = NULL;SDL_Surface *icon_Mid = NULL;string clearSquareTxt = "debug/Images/Map/Clear_Square.png";SDL_Rect spriteCut[ 3 ]; SDL_Surface *playerIcon = NULL;SDL_Surface *iconNorth_Mid = NULL;SDL_Surface *iconNorth_Right = NULL;SDL_Surface *iconNorth_Left = NULL;SDL_Surface *iconNorthEast_Mid = NULL;SDL_Surface *iconNorthEast_Right = NULL;SDL_Surface *iconNorthEast_Left = NULL;SDL_Surface *iconEast_Mid = NULL;SDL_Surface *iconEast_Right = NULL;SDL_Surface *iconEast_Left = NULL;SDL_Surface *iconSouthEast_Mid = NULL;SDL_Surface *iconSouthEast_Right = NULL;SDL_Surface *iconSouthEast_Left = NULL;SDL_Surface *iconSouth_Mid = NULL;SDL_Surface *iconSouth_Right = NULL;SDL_Surface *iconSouth_Left = NULL;SDL_Surface *iconSouthWest_Mid = NULL;SDL_Surface *iconSouthWest_Right = NULL;SDL_Surface *iconSouthWest_Left = NULL;SDL_Surface *iconWest_Mid = NULL;SDL_Surface *iconWest_Right = NULL;SDL_Surface *iconWest_Left = NULL;SDL_Surface *iconNorthWest_Mid = NULL;SDL_Surface *iconNorthWest_Right = NULL;SDL_Surface *iconNorthWest_Left = NULL;------------------icon_Right = IMG_Load( clearSquareTxt.c_str() );icon_Left = IMG_Load( clearSquareTxt.c_str() );icon_Mid = IMG_Load( clearSquareTxt.c_str() );------------------SDL_Surface *testImg = NULL;//first time this funtinon has been usedif (firstUse){//loads up correct sprite sheet if (playerRace == "Gnome"){ spriteSheet = gnomeSpriteSheetImg;}else if (playerRace == "Human"){ spriteSheet = humanSpriteSheetImg;}else if (playerRace == "Orc"){ spriteSheet = orcSpriteSheetImg;}else if (playerRace == "Elf"){ spriteSheet = elfSpriteSheetImg;}//loads 3 base spritesint spriteCutWidth = 32;int spriteFirstSquareX = 70;int spriteSecondSquareX = 129;int spriteThirdSquareX = 191;int spriteFinalY = 0;int spriteFirstSquareY = 3;int spriteSecondSquareY = 67;int spriteThirdSquareY = 135;int spriteFourthSquareY = 197;if (playerClass == "Mage"){ spriteFinalY = spriteFirstSquareY;}else if (playerClass == "Cleric"){ spriteFinalY = spriteSecondSquareY;}else if (playerClass == "Warrior"){ spriteFinalY = spriteThirdSquareY;}else if (playerClass == "Thief"){ spriteFinalY = spriteFourthSquareY;}spriteCut[ 0 ].x = spriteFirstSquareX; spriteCut[ 0 ].y = spriteFinalY; spriteCut[ 0 ].w = spriteCutWidth; spriteCut[ 0 ].h = spriteCutWidth; spriteCut[ 1 ].x = spriteSecondSquareX; spriteCut[ 1 ].y = spriteFinalY; spriteCut[ 1 ].w = spriteCutWidth; spriteCut[ 1 ].h = spriteCutWidth; spriteCut[ 2 ].x = spriteThirdSquareX; spriteCut[ 2 ].y = spriteFinalY; spriteCut[ 2 ].w = spriteCutWidth; spriteCut[ 2 ].h = spriteCutWidth; blit.ApplySurface( 0, 0, spriteSheet, icon_Right,&spriteCut[ 0 ] );blit.ApplySurface( 0, 0, spriteSheet, icon_Mid,&spriteCut[ 1 ] );blit.ApplySurface( 0, 0, spriteSheet, icon_Left,&spriteCut[ 2 ] );//rotation icon and setting up class image vars//midiconEast_Mid = rotozoomSurface(icon_Mid, 0, 1, 1); iconSouthEast_Mid = rotozoomSurface(icon_Mid, 45, 1, 1);iconSouth_Mid = rotozoomSurface(icon_Mid, 90, 0, 1);iconSouthWest_Mid = rotozoomSurface(icon_Mid, 135, 1, 1);iconWest_Mid = rotozoomSurface(icon_Mid, 180, 1, 1);iconNorthWest_Mid = rotozoomSurface(icon_Mid, 225, 1, 1);iconNorth_Mid = rotozoomSurface(icon_Mid, 270, 1, 1);iconNorthEast_Mid = rotozoomSurface(icon_Mid, 315, 1, 1);//righticonEast_Right = rotozoomSurface(icon_Right, 0, 1, 1);iconSouthEast_Right = rotozoomSurface(icon_Right, 45, 1, 1);iconSouth_Right = rotozoomSurface(icon_Right, 90, 0, 1);iconSouthWest_Right = rotozoomSurface(icon_Right, 135, 1, 1);iconWest_Right = rotozoomSurface(icon_Right, 180, 1, 1);iconNorthWest_Right = rotozoomSurface(icon_Right, 225, 1, 1);iconNorth_Right = rotozoomSurface(icon_Right, 270, 1, 1);iconNorthEast_Right = rotozoomSurface(icon_Right, 315, 1, 1);//LefticonEast_Left = rotozoomSurface(icon_Left, 0, 1, 1);iconSouthEast_Left = rotozoomSurface(icon_Left, 45, 1, 1);iconSouth_Left = rotozoomSurface(icon_Left, 90, 0, 1);iconSouthWest_Left = rotozoomSurface(icon_Left, 135, 1, 1);iconWest_Left = rotozoomSurface(icon_Left, 180, 1, 1);iconNorthWest_Left = rotozoomSurface(icon_Left, 225, 1, 1);iconNorth_Left = rotozoomSurface(icon_Left, 270, 1, 1);iconNorthEast_Left = rotozoomSurface(icon_Left, 315, 1, 1);
the corret surface is then passed out of the function and blit, but that part works fine and is long so I did not put it here
[Edited by - JoshPike on November 29, 2009 12:59:33 PM]
I have been working on it and the problem definitly happens when I cut the image from the sprite sheet, when I try to do anything with the alpla or with color keying after that it gives a error
"Unhandled exception at 0x0040c67d in Pikeville.exe: 0xC0000005: Access violation reading location 0x00000004."
anyone have any idea's? I cant find anything on google, and I am stumped, if i cant get this fixed I wont be able to use sprite sheets at all.
it just boggles the mind why sdl would act like the surface that is being used underneithe my cut one is a mask, or why it wont let me do anything to the alpha of my image
[Edited by - JoshPike on November 29, 2009 12:29:08 PM]
"Unhandled exception at 0x0040c67d in Pikeville.exe: 0xC0000005: Access violation reading location 0x00000004."
anyone have any idea's? I cant find anything on google, and I am stumped, if i cant get this fixed I wont be able to use sprite sheets at all.
it just boggles the mind why sdl would act like the surface that is being used underneithe my cut one is a mask, or why it wont let me do anything to the alpha of my image
[Edited by - JoshPike on November 29, 2009 12:29:08 PM]
Quote:Original post by JoshPike
I have been working on it and the problem definitly happens when I cut the image from the sprite sheet, when I try to do anything with the alpla or with color keying after that it gives a error
"Unhandled exception at 0x0040c67d in Pikeville.exe: 0xC0000005: Access violation reading location 0x00000004."
anyone have any idea's? I cant find anything on google, and I am stumped, if i cant get this fixed I wont be able to use sprite sheets at all.
it just boggles the mind why sdl would act like the surface that is being used underneithe my cut one is a mask, or why it wont let me do anything to the alpha of my image
Are you using SDL_DisplayFormat or SDL_DisplayFormatAlpha? I had a similar problem, which was solved by removing it.
no I am using SDL_SetVideoMode for all my main surfaces, but now that you mention it SDL_SWSURFACE might be worth looking at, or changing
in my constructor for my surface class
in my constructor for my surface class
const int SCREEN_WIDTH = 1050;const int SCREEN_HEIGHT = 750;const int SCREEN_BPP = 32; TTF_Init(); SDL_Init( SDL_INIT_EVERYTHING ); screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); backgroundScreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); combatLogScreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); hpBarScreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); combatView = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); cooldown = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); dotScreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); vitalityOverlay = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); mapScreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
Ok, it looks like you've misunderstood what SDL_SetVideoMode is. You are supposed to call it just once, and it returns the back buffer which you draw to in future. You draw everything to that buffer, whatever game mode you're in. The stuff you draw to it, you need to create via different methods.
What you've done there is to just set up the same screen 9 times, so those pointers probably all point at the same place.
Usually you use SDL_LoadBMP or IMG_Load to load an image, and then convert it with SDL_DisplayFormat or SDL_DisplayFormatAlpha.
This 'applySurface' code comes up a lot on this forum these days. Is that a LazyFoo thing? What's the code for it?
What you've done there is to just set up the same screen 9 times, so those pointers probably all point at the same place.
Usually you use SDL_LoadBMP or IMG_Load to load an image, and then convert it with SDL_DisplayFormat or SDL_DisplayFormatAlpha.
This 'applySurface' code comes up a lot on this forum these days. Is that a LazyFoo thing? What's the code for it?
ya its from lazy foo.
so what your saying is that I make say
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
do that once, then write to that surface, flip it, clear it, repeat?
[Edited by - JoshPike on December 1, 2009 10:28:19 AM]
void Surface::ApplySurface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip){ SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface( source, clip, destination, &offset );}
so what your saying is that I make say
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
do that once, then write to that surface, flip it, clear it, repeat?
[Edited by - JoshPike on December 1, 2009 10:28:19 AM]
Pretty much.
SetVideoMode on back buffer.
Back to here.
Game logic.
Blit everything onto surface.
Flip screen.
Clear it.
Repeat.
SetVideoMode on back buffer.
Back to here.
Game logic.
Blit everything onto surface.
Flip screen.
Clear it.
Repeat.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement