Placage de relief
A propos du code
Projecteur
 
				 
				
		#define SCREEN_WIDTH    640
		#define SCREEN_HEIGHT   480
		int main(int argc, char* argv[])
		{
			// init the window
			gfx.init("Bump", SCREEN_WIDTH, SCREEN_HEIGHT);
			gfx.init2D();
			gfx.clearScreen(Color(0, 0, 0, SDL_ALPHA_OPAQUE));
			int width, height;
			Color* background = tga.load("background.tga", &width, &height);
			Color* lightImage = tga.load("light.tga", &width, &height);
				
			while (sys.isQuitRequested() == false)
			{
				// draw the image
				for (int y = 0; y < SCREEN_HEIGHT; ++y)
					for (int x = 0; x < SCREEN_WIDTH; ++x)
					{
						// compute the light intensity
						int light = lightImage[y * SCREEN_WIDTH + x].r;
				
						// get the background color
						Color col = background[y * SCREEN_WIDTH + x];
						// modulate the color by the light intensity
						col.r = col.r * light / 255;
						col.g = col.g * light / 255;
						col.b = col.b * light / 255;
						gfx.setPixel(x, y, col);
					}
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				
 
				
Faire bouger la lumière
		int lightPosX, lightPosY;
		float angle = 0.0f;
				
		// move the light
		lightPosX = 160 * sin(angle);
		lightPosY = 120 * sin(2.0f * angle);
		angle += 0.02f;
				
		int light = 0;
		int lightX = x + lightPosX;
		int lightY = y + lightPosY;
		if (lightX >= 0 && lightX < SCREEN_WIDTH &&
		    lightY >= 0 && lightY < SCREEN_HEIGHT)
		{
			light = lightImage[lightY * SCREEN_WIDTH + lightX].r;
		}
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				
L'effet de relief
 
				
		Color* bump       = tga.load("bump.tga", &width, &height);
				
		// compute the bump disturbance
		int deltaX = 0;
		int deltaY = 0;
		if (x < SCREEN_WIDTH - 1 && y < SCREEN_HEIGHT - 1)
		{
			int current = bump[ y      * SCREEN_WIDTH +  x     ].r;
			int right   = bump[ y      * SCREEN_WIDTH + (x + 1)].r;
			int down    = bump[(y + 1) * SCREEN_WIDTH +  x     ].r;
			deltaX = right - current;
			deltaY = down  - current;
		}
				
		int lightX = x + lightPosX + deltaX;
		int lightY = y + lightPosY + deltaY;
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				
 
				
Gravure sur bois
		int lightX = x + lightPosX - deltaX;
		int lightY = y + lightPosY - deltaY;
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				
 
				
		int lightX = x + lightPosX - deltaX * 2;
		int lightY = y + lightPosY - deltaY * 2;
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				
