Patrick’s development blog

Drawing rectangles SDL

Posted in SDL / OpenGL by Patrick on June 24, 2009

Drawing rectangles can become such a pain in the ass after drawing them a couple of times. I made a helper function that makes this easier.

void FillRect(int x, int y, int w, int h, int color) {
SDL_Rect rect = {x,y,w,h};
SDL_FillRect(screen, &rect, color);
}

I want to add a 100×150 rectangle at the position (25,25) with the color white.

FillRect(25,25,100,150,0xFFFFFF);

Great, no more headache and code memorizing.

Advertisements

Getting mouse state in SDL

Posted in SDL / OpenGL by Patrick on June 23, 2009

I’ve decided to finally start a programming project after a very long break. I found the need to use mouse states when creating a Level editor for my RPG because regular events doesn’t really do what I want.

I want to add tiles fast and be able to hold the mouse key down, instead of clicking every time I want to add a tile.

Mouse states

int cx,cy;
Uint8 ms = SDL_GetMouseState(&cx, &cy);
if (ms & SDL_BUTTON(SDL_BUTTON_LEFT)) {
// the left mouse key is pressed
} else if (ms & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
// the right mouse key is pressed
}

Using the OpenBSD package system

Posted in BSD by Patrick on June 15, 2009

The package system in OpenBSD consists of pre-compiled programs that can be managed with the pkg tool. The packages may not necessarily contain the same kind of security and realibility as the base system, but pkg is useful for installing “third party” software.

1. Create the environment variabel PKG_PATH with the value of the right directory to fetch the packages.
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.5/packages/i386/

2. Add this line into the startup file, ~/.profiles so we don’t have to export it every time we use pkg.

Installing a package
pkg_add -i firefox

Removing a package
pkg_delete firefox

Information about installed packages
pkg_info