Added stuff
This commit is contained in:
95
loki_sample/alpha-example/alpha-sdl.c
Normal file
95
loki_sample/alpha-example/alpha-sdl.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/* Example of alpha blending with SDL. */
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Surface *background;
|
||||
SDL_Surface *image_with_alpha;
|
||||
SDL_Surface *image_without_alpha;
|
||||
SDL_Rect src, dest;
|
||||
|
||||
/* init sdl and check for erro */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
printf("Unable to init SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
screen = SDL_SetVideoMode(800, 600, 16, 0);
|
||||
if (screen == NULL) {
|
||||
printf("Unable to set video mode: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Load image file */
|
||||
image_with_alpha = IMG_Load("with-alpha.png");
|
||||
if (image_with_alpha == NULL) {
|
||||
printf("Unable to load image. \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
image_without_alpha = IMG_Load("without-alpha.png");
|
||||
if (image_without_alpha == NULL) {
|
||||
printf("Unable to load image\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
background = IMG_Load("background.png");
|
||||
if (background == NULL) {
|
||||
printf("Unable to load background.png.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Draw background. */
|
||||
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
src.w = background->w;
|
||||
src.h = background->h;
|
||||
dest.x = 0;
|
||||
dest.y = 0;
|
||||
dest.w = background->w;
|
||||
dest.h = background->h;
|
||||
SDL_BlitSurface(background, &src, screen, &dest);
|
||||
|
||||
/* draw first image with alpha */
|
||||
|
||||
SDL_SetAlpha(image_with_alpha, SDL_SRCALPHA, 0);
|
||||
src.w = image_with_alpha->w;
|
||||
src.h = image_with_alpha->h;
|
||||
dest.w = src.w;
|
||||
dest.h = src.h;
|
||||
dest.x = 40;
|
||||
dest.y = 50;
|
||||
SDL_BlitSurface(image_with_alpha, &src, screen, &dest);
|
||||
|
||||
/* Draw second image without alpha. Set to 50% transparence for entire surface.
|
||||
*/
|
||||
SDL_SetAlpha(image_without_alpha, SDL_SRCALPHA, 128);
|
||||
src.w = image_without_alpha->w;
|
||||
src.h = image_without_alpha->h;
|
||||
dest.w = src.w;
|
||||
dest.h = src.h;
|
||||
dest.x = 180;
|
||||
dest.y = 50;
|
||||
SDL_BlitSurface(image_without_alpha, &src, screen, &dest);
|
||||
|
||||
/* Ask SDL to update entire screen */
|
||||
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
||||
|
||||
SDL_Delay(10000);
|
||||
|
||||
/* Free memory */
|
||||
SDL_FreeSurface(background);
|
||||
SDL_FreeSurface(image_with_alpha);
|
||||
SDL_FreeSurface(image_without_alpha);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
BIN
loki_sample/alpha-example/background.png
Normal file
BIN
loki_sample/alpha-example/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
loki_sample/alpha-example/with-alpha.png
Normal file
BIN
loki_sample/alpha-example/with-alpha.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
loki_sample/alpha-example/without-alpha.png
Normal file
BIN
loki_sample/alpha-example/without-alpha.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
62
loki_sample/simple_blit_example/blitting-surface-sdl.c
Normal file
62
loki_sample/simple_blit_example/blitting-surface-sdl.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/* Example of simple blitting with SD>. */
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Surface *image;
|
||||
SDL_Rect src, dest;
|
||||
|
||||
/* init and check for errors*/
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
printf("Unable to init SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
/* 256x256 hicolor (16-bit) */
|
||||
|
||||
screen = SDL_SetVideoMode(512, 512, 32, 0); // finding BMPs is hard // Doesn't work anyway...
|
||||
//I seem to remem ber having htis problem before
|
||||
if (screen == NULL) {
|
||||
printf("Setting video mode failed: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Load bitmap file. SDL_LoadBMP returns a pointer to a new surface containing
|
||||
* the loaded image. */
|
||||
image = SDL_LoadBMP("test-image.bmp");
|
||||
if (image == NULL) {
|
||||
printf("Unable to load bitmap.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The SDL blitting function needs to know how much data
|
||||
* to copy. We provide this with SDL_Rect structures, which
|
||||
* define the source and destination rectangles. The areas
|
||||
* shoul be the same; SDL does not currently handle image
|
||||
* stretching. */
|
||||
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
src.w = image->w; /* copy entire image */
|
||||
src.h = image->h;
|
||||
|
||||
/* Draw the bitmap to the screen. It is not necessary to lock surfaces
|
||||
* before blitting; SDL will handle that. */
|
||||
|
||||
SDL_BlitSurface(image, &src, screen, &dest);
|
||||
|
||||
SDL_Delay(3000);
|
||||
|
||||
/* Free memory allocated to the bitmap. */
|
||||
SDL_FreeSurface(image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
BIN
loki_sample/simple_blit_example/test-image.bmp
Normal file
BIN
loki_sample/simple_blit_example/test-image.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 KiB |
BIN
loki_sample/simple_blit_example/test-image.png
Normal file
BIN
loki_sample/simple_blit_example/test-image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
Reference in New Issue
Block a user