Jump to content
  • Advertisement
Sign in to follow this  
pnroach

new to SDL

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am new to STL and have some questions about it 1. I am planning on using tga textures in my projects and would like my screen objects to be transparent in parts. how do i do that? i assume it looks something like this: SDL_SetAlpha(surf,....) SDL_BlitSurface(surf,...) So what should i put in SDL_SetAlpha just to make sure that the object i draw has transparency in the same parts where the associated targa image has it. 2. is there any way to use SDL inside another app (like a map editor). Can we just pass in something like a window handle (like with Direct3D) and draw stuff just on that particular "surface". 3. Do i need to call SDL_SetAlpha rendering every sprite? Is there a way of just enabling alpha blending for the whole rendering routine? thanx

Share this post


Link to post
Share on other sites
Advertisement
1. If you use targa images, the image loader should automagically load the surface with the proper RGBA formats and alpha channel. (Assuming you use SDL_Image.)

2. I don't believe so, but I could be wrong.

3. No, you should just have to call it once per surface, but see above note about image loading.

Share this post


Link to post
Share on other sites
Thanx again SiCrane! Should i just address all of my questions to you? ;)

I have another one. Is this correct as for the rendering routine ?

void Render()
{
if( SDL_MUSTLOCK(screen) )
if( SDL_LockSurface(screen) < 0 )
return;

//draw everything here

if( SDL_MUSTLOCK(screen) )
SDL_UnlockSurface(screen);

SDL_Flip(screen);
}

Share this post


Link to post
Share on other sites
I am currently working on some SDL tutorials:
Lazy Foo's SDL tutorials

They're not finished yet, but I'm hoping to have all the non-OS/compiler specific stuff finished by the end of next week.

Most of the important tutorials are already up though.
</spam>

[Edited by - Lazy Foo on August 9, 2007 7:48:50 PM]

Share this post


Link to post
Share on other sites
You only need to lock the screen surface for direct pixel manipulation, if all you are doing is blitting images then you can do away with all the locking of the surface.

Share this post


Link to post
Share on other sites

void Render()
{
if( SDL_MUSTLOCK(screen) )
if( SDL_LockSurface(screen) < 0 )
return;

//draw everything here

if( SDL_MUSTLOCK(screen) )
SDL_UnlockSurface(screen);

SDL_Flip(screen);
}



What do you mean by "render". The thing you are doing here sets the surface up for individual pixel manipulation. This is only needed if you are working on each pixel.

If you use this when blitting images with SDL's various blit functions, you will get an error, however.

If you have any specific example, it will get you a better answer.

Share this post


Link to post
Share on other sites
Quote:

1. I am planning on using tga textures in my projects and would like my screen objects to be transparent in parts. how do i do that? i assume it looks something like this:


Unless you need partial transparency then alpha blending isn't what you want to use. In most cases you can specify a single color in an image to be transparent using a colorkey (SDL_SetColorKey). This gets done once when you load the image and will be the equivilent of specifying an alpha value of 0 to all pixels of that color.

Colorkeys will always be much faster in SDL than using alpha blending because the pixels relating to the colorkey are simply ignored and in some cases can be hardware accelerated whereas alpha blending in SDL will always be done via software rendering.

This is not to say alpha blending is impossibly slow via SDL, it depends on how often you use it and a few other things as well but it is by no means not an option for effects.

If on the other hand alpha blending is used heavily, most people here will recommend you use OpenGL or Direct3D for rendering 2D. On modern graphics cards you will see a noticeable speed increase with the down side of having to learn a 3d API or learn to use another 3rd party library.

Hope it helps

Share this post


Link to post
Share on other sites

hello there

thanx everyone who have posted replies here. your comments were very useful. i got things going. got a bit confused when i tried
using animation. it doesn't look like there's any "ClearDevice" type of routine in SDL so i couldn't get my app to clear screen
before each rendering loop and things looked messy. then i used the following :


SDL_FillRect(m_screen,NULL,0);

//draw all the pics using SDL_BlitSurface

SDL_Flip(m_screen);

it works but i have strong feeling that something is wrong. does this make any sense? if not, then how should it look?

and one more thing... how do you guys scale textures in SDL? in other words, how can i change the size of the surface that
holds loaded image?

Share this post


Link to post
Share on other sites
Quote:
Original post by pnroach
SDL_FillRect(m_screen,NULL,0);
//draw all the pics using SDL_BlitSurface
SDL_Flip(m_screen);

it works but i have strong feeling that something is wrong. does this make any sense? if not, then how should it look?

Looks good to me, but one thing though. If you draw one background image that covers the entire screen, then you do not even need to bother with the FillRect. Just think of it like by drawing the background (which is drawn 1st) it clears out everything already there, so you can save a lot of time by not calling clear.

Quote:

and one more thing... how do you guys scale textures in SDL?


SDL_gfx.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!