Clear Background
hi, i do not use sdl but i have started a simple project and i want to finish it. i just want to know are there any function in sdl like: glclearcolor(0,0,0) ??? i want to clear all screen to a simple color. i can do it with a bitmap but it is slow. thank you..
+-+-+-+-+-STR
Try to use SDL_CreateRGBSurface on the screen surface. Maybe it works :)
// right after the screen = SDL_SetVideoMode function.screen = SDL_CreateRGBSurface(SDL_HWSURFACE, 640, 480, 32, 255, 0, 0, 255);
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
it does not work. makes it slower, after some seconds.
any ideas? should i have to make another suface for background? arent there a clear_surface function _?
i am still looking up the manual..
thank you.
any ideas? should i have to make another suface for background? arent there a clear_surface function _?
i am still looking up the manual..
thank you.
+-+-+-+-+-STR
Quote:
Original post by stroma
hi,
i do not use sdl but i have started a simple project and i want to finish it. i just want to know are there any function in sdl like: glclearcolor(0,0,0) ??? i want to clear all screen to a simple color. i can do it with a bitmap but it is slow.
thank you..
This is what you need to do:
if you are using SDL only, no OpenGL Rendering then make this call:
SDL_FillRect(Screen,NULL,0x000000);
Screen represents your main SDL_Surface*, NULL means clear the whole screen, and 0x000000 represents the hex color.
0x000000 is black, 0xFFFFFF is white, 0xFF0000 is red, 0x00FF00 is green, and 0x0000FF is blue. You can use a html color generator for custom colors or a program such as Paint Shop Pro, or Photoshop to get custom colors.
If you are using an OpenGL Rendering context, than you will need to do this:
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);SDL_FillRect(Screen,NULL,0x000000);
THe parameter list for glClearColor is Red,Green,Blue,Alpha, where each can have a value from 0.0f - 1.0f. Hope this helps!
thank you very much, now i am going to add time based movement with SDLGetTicks..
+-+-+-+-+-STR
Quote:
If you are using an OpenGL Rendering context, than you will need to do this:
You're not quite accurate - one probably would use it when writing normal SDL application where the only thing OpenGL changes, is blitting mode - when it's done using SDL_OPENGLBLIT. Though I've never used it and to be honest, twice clearing screen using 2 different functions looks to me a bit redundant...
And if you're doing all your rendering in OpenGL and SDL is only nice wrapper for window, input etc. stuff then I'm absolutely sure that glClear will do the job -> at least, it's working for me.
Quote:
Original post by Koshmaar Quote:
If you are using an OpenGL Rendering context, than you will need to do this:
You're not quite accurate - one probably would use it when writing normal SDL application where the only thing OpenGL changes, is blitting mode - when it's done using SDL_OPENGLBLIT. Though I've never used it and to be honest, twice clearing screen using 2 different functions looks to me a bit redundant...
And if you're doing all your rendering in OpenGL and SDL is only nice wrapper for window, input etc. stuff then I'm absolutely sure that glClear will do the job -> at least, it's working for me.
This is the way it works - if you are only using OpenGL functions, ie, no SDL blits, you just have to call clearcolor. However, once you start using sdl blits w/ opengl, then you have to clear color and fill the surface, so if you move sdl images around, they will be cleared properly and you won't have a non updated screen. All this is tested and does work, its the stuff I'm doing in my engine right now. However, if you get the function call order just right, you could prob get away with just clearcolor ,since you would be call SDL first then OGL, but in my case, SDL comes last b/c it is more of gui elements. [WINK]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement