Weird Display Troubles


PokeParadox

Founder of Pirate Games - Penjin Coder
Staff member
Joined
Dec 8, 2005
Messages
6,603
Age
41
Location
UK
Website
pokeparadox.itch.io
WEBSITE
https://github.com/pokeparadox
YOUTUBE
pokeparadox
OK I'm not sure what I changed, but now things are rendering properly in mygame :S
Anyone know what sort of things might cause this?
(This being the circle sprites and now rectangular :S)
cromobug.PNG
 
Line thickness?

(Total guess, I don't use SDL rendering .. but perhaps if you set a line width or something, it could do that?)

jeff
 
Well, what should it look like? And what does the rendering code look like?
 
ok... sorry... It should look like in this earlier build here
And the code is a bit tricky to show... :S I was hoping there was an obvious silly problem that people knew about...
In the main render function in the main game state:
CODE
// draw all snakes
uint numSnakes = (uint)snakes.size();
//text.print(screen,"NumSnakes: ");
for(uint i = 0; i < numSnakes; i++)
snakes->render(screen,redSprite,greenSprite,blueSprite);


Calls this:

CODE
void Snake::render(SDL_Surface* screen, Sprite& red, Sprite& green, Sprite& blue)
{
uint iMax = (uint)nodes.size();
for(uint i=0; i < iMax; i++)
{
nodes.render(screen,red,green,blue);
}
}

then this:
CODE
void render(SDL_Surface* screen, Sprite& red, Sprite& green,Sprite& blue)
{
if(colour == RED_NODE)
{
red.setXY(pos.getX(), pos.getY());
red.render(screen);
}
else if(colour == GREEN_NODE)
{
green.setXY(pos.getX(), pos.getY());
green.render(screen);
}
else if(colour == BLUE_NODE)
{
blue.setXY(pos.getX(), pos.getY());
blue.render(screen);
}
}


then this:
CODE
void Sprite::render(SDL_Surface* screen)
{
image.renderImage(screen,getX(),getY());
}


and finally this:
CODE
void Image::renderImage(uint i,SDL_Surface *dstimg, int destx, int desty)
{
// Don't render if invisible or if there is no image!
if((!images || alpha == 0))
{
return;
}

// Set up blitting area
SDL_Rect src, dst;
src.x = images->clip_rect.x;
src.y = images->clip_rect.y;
src.w = images->w;
src.h = images->h;
dst.x = destx;
dst.y = desty;
dst.w = src.w;
dst.h = src.h;

// Check if we need to alpha blend
if(alpha != 255)
{
SDL_SetAlpha(images, SDL_SRCALPHA, alpha);
}
if(useRotation)
{
SDL_Surface* tempImage = NULL;
if(angle)
{
tempImage = rotozoomSurface(images, angle, scaleX, SMOOTHING_OFF);
}
else if(scaleX || scaleY)
{
tempImage = zoomSurface(images,scaleX, scaleY, SMOOTHING_OFF);
}
// Blit the image onto the display surface
SDL_BlitSurface(tempImage, &src, dstimg, &dst);
SDL_FreeSurface(tempImage);
}
// Check for if we should use a HW Surface
else if(useHardware)
{
SDL_Surface* tempImage = NULL;
tempImage = SDL_ConvertSurface(images, dstimg->format, SDL_HWSURFACE);
// Blit the image onto the display surface
SDL_BlitSurface(tempImage, &src, dstimg, &dst);
SDL_FreeSurface(tempImage);
}
else
{
// Blit the image onto the display surface
SDL_BlitSurface(images, &src, dstimg, &dst);
}
}


And while we are looking at this render function, can anyone think of a better way of structuring the facility to rotozoom/use HW surfaces?
 
OK, seem to have sorted it myself. So it looks like a problem with alpha using HW surfaces? Also my default contructor for my Image object was set to use HW surfaces, so when I removed the redSprite.useHardware(true); call with a comment it was still using hardware >_>
 
Back
Top