SDL - Alpha channel issues

Started by
50 comments, last by RuneLancer 20 years, 1 month ago
That looks really cool Rune. What kind of framerates you get from it?

It's prob too late to do any good but I figure this thread'll be referenced again so here's my PNG load code in case anyone is still unclear about the format surface funcs:
// load the imagem_pImage = IMG_Load(strFileName.c_str());if (!m_pImage){    // uh oh     return;}// convert the image into the current display formatif (m_pImage->format->alpha)    m_pImage = SDL_DisplayFormatAlpha(m_pImage);else    m_pImage = SDL_DisplayFormat(m_pImage);  


_________________________________________________________________

Drew Sikora
President, Lead Programmer - Blade Edge Software
Staff Writer, Newsletter Editor - GameDev.net
Community Relations - Game Institute

Drew Sikora
Executive Producer
GameDev.net

Advertisement
The title screen is prerendered, yeah. I might try having something animated though; my original intent was to have some wavy smoke-like effect with light filtering though (y''know what I mean, right?)

As for the framerate, I actually don''t really know. Gimme a second to test something... Few things though.

    The text is blinking every 500 ms. That should be "Press Enter!", though.
    HEAVILY unoptimized. For instance, I render the WHOLE background over again every frame. Still haven''t transformed the surface depths to match the display''s, either.
    My PC is crap. PIII 650, 196 megs of RAM, and an ATI RAGE 128.
    The game is coded with a fixed framerate. That is, I capped it because I''m using frame-based movement. Yes, I can hear you all groaning in pain there. To check my FPS though, I removed the capping.


And I get... 10 FPS roughly. :D Not bad, huh? Eh. I''ll optimize when I have something that works.
once you convert to the display surface i bet you will get around 30 fps or more
FTA, my 2D futuristic action MMORPG
Hrm, are SDL_DisplayFormat surfaces converted, or copied?

SDL_Label = SDL_DisplayFormat(SDL_CreateRGBSurface(SDL_HWSURFACE, W, H, 32, 0xFF, 0xFF00, 0xFF0000, 0x00));

With this, the surface SDL)CreateRGBSurface creates, is it lost or just converted and then thrown into SDL_Label?

I might have a leak otherwise

Edit: Huh... I cut out the display entirely and even then, when it's just my main loop, I get 24 FPS tops...

	while(1)	{		TickCount = SDL_GetTicks();		while(SDL_PollEvent(&SDL_Msg))			switch(SDL_Msg.type)			{				case SDL_QUIT: CleanUp(); return 0;			}		//if(!UpdateFrame()) { CleanUp(); return 0; }		//while(SDL_GetTicks() - TickCount < 15) Sleep(1);#if defined(DEBUG)		nFrame++;#endif	} 


Am I doing something wrong? :/

[edited by - RuneLancer on April 5, 2004 4:17:18 AM]
try this before your main() :

#include <time.h>#define FRAME_RATE_SAMPLES 100int FrameCount = 0;float FrameRate = 0;static void CalcFPS() {   static clock_t last=0;   clock_t now;   float delta;   if (++FrameCount >= FRAME_RATE_SAMPLES) {      now  = clock();      delta= (now - last) / (float) CLOCKS_PER_SEC;      last = now;      FrameRate = FRAME_RATE_SAMPLES / delta;      FrameCount = 0;   }}



Then at the end of your game loop, call

CalcFPS();

you can then look at the FrameRate variable to know what your current rate is over the last 100 frames (or less if you change it)

When using SDL_GetTicks(), it''s limited to 1000 per second, so it''s accuracy isn''t top notch. Also, you want to test over many frames. If you measure just one frame, you margin of error goes way up and it will look like your FPS is awefull.

------


SDL_DisplayFormat() copies a surface, so you''ll need to FreeSurface() your original one. That''s a mem leak just waiting to happen!

Ah, I thought so; I was pretty certain that surface wasn''t just magically being transformed into a new surface. No biggie.

I was testing over the course of ~20 seconds, though I''ll give your code a shot. It sounds a little hard to believe that a simple SDL "message pump" would run at 24 FPS...
Yes Rune, I get 22fps tops when I run my SDL engine in windowed mode. Haven''t gotten around to seeing how fast it runs in fullscreen mode tho.

Drew Sikora
Executive Producer
GameDev.net

its probably because your re-drawing the entire screen every frame.... why? i dont see any reason to.. just draw it one time in the begining... and thats it... if you have anything animated, just slice the background and draw it over the animated part.
FTA, my 2D futuristic action MMORPG
Ah, this is more like it. I''m hitting 20 FPS now. I''ve let it run a little while and it renders like a charm.

Granted, I''ve gotten to the "prelude" part, which is text/window only. Heh. That would explain the rise.

This leaves me to worry about a few things. When I''ll have a background and two tile layers (maybe I can cut it down to one, depends how good it looks), a couple of sprites, and need of decently fast player input, I might have a problem on my hands. I will have to redraw the background everytime the player moves, for obvious reasons... so my FPS are gonna plummet. Well, I''ll see how it looks when I get there. Premature optimization will lead this project to a standstill in no time at all, which is bad.

I''ll just have to wait and see.
I think that all just comes down to your hardware. Standard SDL doesn''t use your graphics card''s acceleration since it''s dealing with pixels not polys (at least it doesn''t use hardware on my system). So i think the framerate (with SDL at least) is limited by your CPU. I''m running an Athlon 2500 and i blit a 1024x768 background image (the whole thing), a few hundred 8x8 PNG particles, and do collision detection on a dozen objects, plus updating potentially thousands of particle objects and still get around ~40 FPS, and that''s a bit low.

This topic is closed to new replies.

Advertisement