Filled Rectangles (SDL_FillRect)
SDL_FillRect is used to render color-filled rectangles.
int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
This function returns an int. If successful, the value returned will be 0. If it fails, the return value will be -1. There are three parameters. The first (dst) is a pointer to an SDL_Surface on which you are drawing the filled rectangle. The second (dstrect) is a pointer to an SDL_Rect that describes the rectangular area that you want to fill. The third (color) is a Uint32 that represents the color with which you want to fill the rectangle.
clip_rect
The clip_rect member is an SDL_Rect. The values stored here limit the area on the SDL_Surface on which you can blit. SDL supports only rectangular clipping areas and only one rectangle at a time.
Now you are ready to load and animate or move the loaded image on the SDL screen you have created.
#include <sdl/sdl.h>
SDL_Surface *screen=0;
SDL_Surface *bitmap=0;
void draw_surface(SDL_Surface *sur, int x, int y)
{
SDL_Rect pos={x,y};
SDL_BlitSurface(sur, 0, screen, &pos);
Saturday, July 9, 2011
Friday, July 8, 2011
Loading an image on the SDL screen
The knowledge of the following are required to some extent for loading an image on the screen.
SDL_Surface
It is a structure which acts as the stock and trade of SDL’s video subsystem. It abstracts a rectangular block of pixels. There is only one SDL_Surface that represents the actual display area. All of the other surfaces are buffers for storing pixel (such as images to be displayed) data that will eventually be shown on the main display.
SDL_Rect
The SDL video subsystem, being 2D in nature, deals primarily with copying rectangular blocks of pixels from one
SDL_Surface to another. This has been the way of dealing with raster displays since their initiation. It is The Way Things are done.
Thursday, July 7, 2011
Creating a window in SDL
You should know about some functions before you begin any sort of real work with SDL.
Initialize one or more SDL subsystems (SDL_Init )
The SDL_Init function should be the very first function that is called. If this function is not called, no other SDL function will operate. When you call this function, you specify which of the SDL subsystems you intend to use in the application. The identifiers for each of the subsystems are shown below.
Initialize one or more SDL subsystems (SDL_Init )
The SDL_Init function should be the very first function that is called. If this function is not called, no other SDL function will operate. When you call this function, you specify which of the SDL subsystems you intend to use in the application. The identifiers for each of the subsystems are shown below.
Wednesday, July 6, 2011
Setting up SDL in codeblocks
- First of all you've to download SDL headers and binaries. The download is available at http://www.mediafire.com/?ce02ii51rvoxezm
- After downloading, extract the zip file.
- Copy the contents of include folder and open ...\CodeBlocks\MinGW\include folder where your codeblocks has been installed ( such as C:\Program Files (x86)\CodeBlocks\MinGW\include). Create a new folder named SDL and paste the copied contents inside it.
- Copy the contents of bin folder and paste it inside C:\Windows\System32.
- Repeat the above step for lib folder. Paste the contents inside ...\CodeBlocks\MinGW\lib.
Tuesday, July 5, 2011
Collision detection in flash
Collision detection is an essential part in games. It ensures that the game physics are relatively realistic, so that an object does not cut through other objects or hovers when it should fall. How well a game can detect collisions is an integral part of the believability and enjoyment of the game.
Here is a simple concept in flash to test the collision detection.
- Create two objects in flash, here for demo say two rectangles with red and blue color.
- Right click both objects and convert them to symbol giving them names red and blue.
- If properties panel is off, go to window menu and turn it on.
- Select the respect objects and under properties panel give the instance names to both, say red and blue (these are the names we will be using to identify the them in action scripts).
Monday, July 4, 2011
Create your own character in flash-able to move
- Create a character ( may be a circle here just for demo)
- Right click the circle, convert to symbol, select movie clip and then give a name to the character finally pressing ok
Sunday, July 3, 2011
Make a Program Run at Startup
It sometimes require for us to make some programs run at startup. To accomplish this task, follow the steps as mentioned :
- Run registry editor ( run (win+R) and then type regedit)
- Then Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
- Edit\New\String Value
- Rename New Value #1 to the name of program to be run at startup
- Double click the name so renamed
Subscribe to:
Posts (Atom)