/usr/share/doc/libsdl-sge-dev/examples/alpha.cpp is in libsdl-sge-dev 030809dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | #include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "sge.h"
//Main
int main(int argc, char** argv)
{
/* Init SDL */
if ( SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't load SDL: %s\n", SDL_GetError());
exit(1);
}
/* Clean up on exit */
atexit(SDL_Quit);
/* Set window title */
SDL_WM_SetCaption("Alpha magic", "alpha");
/* Initialize the display */
SDL_Surface *screen;
screen = SDL_SetVideoMode(600, 300, 16, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
exit(1);
}
sge_FilledRect(screen,0,0, screen->w,screen->h/2, 255,255,255);
/* Open TT font file */
if(sge_TTF_Init()!=0){fprintf(stderr,"TT error: %s\n",SDL_GetError());exit(1);}
sge_TTFont *font;
font=sge_TTF_OpenFont("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", 55);
if(font==NULL){fprintf(stderr,"TT error: %s\n",SDL_GetError());exit(1);}
/* Ugly font rendering */
sge_TTF_AAOff();
sge_tt_textout(screen,font,"Linux", 10,167, 0,0,255, 255,255,255, SDL_ALPHA_OPAQUE);
/* AA rendering */
sge_TTF_AAOn();
sge_tt_textout(screen,font,"Linux", 210,167, 0,0,255, 255,255,255, SDL_ALPHA_OPAQUE);
/* AA with alpha rendering */
sge_TTF_AA_Alpha();
sge_tt_textout(screen,font,"Linux", 410,167, 0,0,255, 1,2,3, SDL_ALPHA_OPAQUE);
sge_TTF_SetFontSize(font, 25);
sge_tt_textout(screen,font,"Normal", 50,200, 0,255,0, 0,0,0, SDL_ALPHA_OPAQUE);
sge_tt_textout(screen,font,"Anti aliasing", 210,200, 0,255,0, 0,0,0, SDL_ALPHA_OPAQUE);
sge_tt_textout(screen,font,"Alpha", 460,200, 0,255,0, 0,0,0, SDL_ALPHA_OPAQUE);
sge_TTF_CloseFont(font);
/* Some alpha component magic */
SDL_Surface *img=sge_CreateAlphaSurface(SDL_SWSURFACE, 100, 100); //Alocate buffer
Uint32 ctab[101];
sge_AlphaFader(255,0,255,0, 0,0,255,230, ctab,0,100); //Make a nice alpha blended pallete
/* Paint the buffer */
for(int yy=0; yy<=100; yy++)
sge_HLine(img,0,100,yy,ctab[yy]);
SDL_UpdateRect(screen,0,0,0,0);
/* The buffer for the background */
SDL_Surface *buffer;
buffer=SDL_DisplayFormat(screen);
// If the delay between two PollEvent is greater than 100 and all events are added to the
// event queue, the queue will grow *fast*. You're program will have no change to catch
// up. You *must* try to avoid adding events unnecessarily - mousemotions for example.
SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE);
Sint32 x=50,y=190;
Sint32 oldx = 50, oldy = 190;
bool right=true, down=false;
sge_Update_OFF();
// Sets start time
Uint32 tstart=SDL_GetTicks();
int loops=0;
// Main loop
SDL_Event event;
do{
SDL_Delay(10);
//Check borders
if( (x+img->w) >= screen->w )
right = false;
else if( x <= 0 )
right = true;
if( (y+img->h) >= screen->h )
down = false;
else if( y <= 0)
down = true;
//Update pos
if(right)
x++;
else
x--;
if(down)
y++;
else
y--;
//Update last pos from buffer
sge_Blit(buffer,screen,oldx, oldy, oldx,oldy, img->w,img->h);
//Draw the alpha surface
sge_Blit(img,screen,0,0, x,y, img->w,img->h);
//Update screen
sge_Update_ON();
sge_UpdateRect(screen, x-1, y-1, img->w+2, img->h+2);
sge_Update_OFF();
oldx=x; oldy=y;
loops++;
// Check events
if(SDL_PollEvent(&event)==1){
if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_ESCAPE){break;}
if(event.type==SDL_QUIT){break;}
}
}while(true);
/* Print FPS */
printf("%.2f FPS (target: 100).\n",((double)loops*1000)/(SDL_GetTicks()-tstart));
/* Clean up */
SDL_FreeSurface(img);
SDL_FreeSurface(buffer);
return 0;
}
|