| << home >> | Nesúvislé fragmenty z objavovania OS Linux | 
| <<- ->> | |
|  | |
| 
 | SDLNie, toto nie je prešmyčka na hodine slovenského jazyka, kde úlohou žiakov je posledné písmeno vložiť pred prvé písmeno. A aj ten jazyk by sa tam hodil. Je to ďalšia grafická knižnica (Simple DirectMedia Layer). Domovská stránka na http://www.libsdl.org/index.php poskytne bližšie informácie, download zdrojového paklíka (v marci 2003 verzia 1.2.5) a tiež množstva aplikácií vyžadujúcich túto knižnicu.Zaujímavé sú najmä dva súbory: 
 Inštalácia SDLSkopírujeme a štandardne rozbalíme paklíky niekde v domovskom adresári. $ tar xfz mano_paklika.tar.gz Vhupneme do podadresára SDL-1.2.5 a štandardne nainštalujeme knižnicu (./configure, make, (root) make install). Použitie SDL#include <SDL/SDL.h>$ gcc -o Priklad_1 Priklad_1.cc `sdl-config --libs` Príklad_1.cc/** Priklad_1 pre vyuzitie * kniznice SDL */ #include <SDL/SDL.h> #include <stdio.h> int main() { SDL_Surface *screen; SDL_Color colors[256]; SDL_Rect *obluda; Uint32 farba; int i; printf("Inicializacia SDL\n"); /* defaultne nastavenie grafiky, zvuku a casovaca */ if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)==-1)) { printf("Mam problem s inicializaciou SDL: %s\n", SDL_GetError()); return(-1); } printf("SDL je inicializovana\n"); /* nastavenie grafickeho modu 640x480x8 */ screen=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE|SDL_ANYFORMAT); if(!screen){ printf("Mam problem s nastavenim video modu: %s\n", SDL_GetError()); return(-1); } for(i=0;i<256;i++){ colors[i].r=i; colors[i].g=i; colors[i].b=i; } farba=SDL_MapRGB(screen->format, 0x00, 0xff, 0x00); SDL_SetColors(screen, colors, 0, 256); SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); SDL_FillRect(screen, obluda, farba); SDL_UpdateRect(screen, 160, 120, 320, 240); SDL_Delay(2000); printf("Koncime ...\n"); SDL_Quit(); printf("Skoncili sme\n"); return(0); } $ gcc -o Priklad_1 Priklad_1.cc `sdl-config --libs` Podrobnejšie viď. manuálové stránky, napríklad: SDL_GetVideoSurface - returns a pointer to the
current display surfaceSDL_GetVideoInfo - returns a pointer to
information about the video hardwareSDL_VideoDriverName - Obtain the name of the video
driverSDL_ListModes - Returns a pointer to an array
of available screen dimensions for the given format and video flagsSDL_VideoModeOK - Check to see if a particular
video mode is supported.SDL_SetVideoMode - Set up a video mode with the
specified width, height and bits-per-pixel.SDL_UpdateRect - Makes sure the given area is
updated on the given screen.SDL_UpdateRects - Makes sure the given list of
rectangles is updated on the given screen.SDL_Flip  Swaps screen buffersSDL_SetColors - Sets a portion of the colormap
for the given 8-bit surface.SDL_SetPalette - Sets the colors in the palette
of an 8-bit surface.SDL_SetGamma - Sets the color gamma function
for the displaySDL_GetGammaRamp - Gets the color gamma lookup
tables for the displaySDL_SetGammaRamp - Sets the color gamma lookup
tables for the displaySDL_MapRGB - Map a RGB color value to a
pixel format.SDL_MapRGBA - Map a RGBA color value to a
pixel format.SDL_GetRGB - Get RGB values from a pixel in
the specified pixel format.SDL_GetRGBA - Get RGBA values from a pixel in
the specified pixel format.SDL_CreateRGBSurface - Create an empty SDL_SurfaceSDL_CreateRGBSurfaceFrom - Create an SDL_Surface from
pixel dataSDL_FreeSurface - Frees (deletes) a SDL_SurfaceSDL_LockSurface - Lock a surface for directly
access.SDL_UnlockSurface - Unlocks a previously locked
surface.SDL_LoadBMP - Load a Windows BMP file into an
SDL_Surface.SDL_SaveBMP - Save an SDL_Surface as a
Windows BMP file.SDL_SetColorKey - Sets the color key (transparent
pixel) in a blittable surface and RLE acceleration.SDL_SetAlpha - Adjust the alpha properties of
a surfaceSDL_SetClipRect - Sets the clipping rectangle for
a surface.SDL_GetClipRect - Gets the clipping rectangle for
a surface.SDL_ConvertSurface - Converts a surface to the same
format as another surface.SDL_BlitSurface - This performs a fast blit from
the source surface to the destination surface.SDL_FillRect - This function performs a fast
fill of the given rectangle with some colorSDL_DisplayFormat - Convert a surface to the
display formatSDL_DisplayFormatAlpha - Convert a surface to the
display formatSDL_WarpMouse - Set the position of the mouse
cursor.SDL_CreateCursor - Creates a new mouse cursor.SDL_FreeCursor - Frees a cursor created with
SDL_CreateCursor.SDL_SetCursor - Set the currently active mouse
cursor.SDL_GetCursor - Get the currently active mouse
cursor.SDL_ShowCursor - Toggle whether or not the
cursor is shown on the screen.SDL_GL_LoadLibrary - Specify an OpenGL librarySDL_GL_GetProcAddress - Get the address of a GL functionSDL_GL_GetAttribute - Get the value of a special
SDL/OpenGL attributeSDL_GL_SetAttribute - Set a special SDL/OpenGL
attributeSDL_GL_SwapBuffers - Swap OpenGL framebuffers/Update
DisplaySDL_CreateYUVOverlay - Create a YUV video overlaySDL_LockYUVOverlay - Lock an overlaySDL_UnlockYUVOverlay - Unlock an overlaySDL_DisplayYUVOverlay - Blit the overlay to the displaySDL_FreeYUVOverlay - Free a YUV video overlaySDL_GLattr - SDL GL AttributesSDL_Rect - Defines a rectangular areaSDL_Color - Format independent color
descriptionSDL_Palette - Color palette for 8-bit pixel
formatsSDL_PixelFormat - Stores surface format
informationSDL_Surface - Graphical Surface StructureSDL_VideoInfo - Video Target informationSDL_Overlay - YUV video overlay Je vhodné prezrieť si hlavičkáre v adresári /usr/include/SDL/ pred includnutím. <SDL/begin_code.h> <SDL/close_code.h> <SDL/SDL_active.h> <SDL/SDL_audio.h> <SDL/SDL_byteorder.h> <SDL/SDL_cdrom.h> <SDL/SDL_copying.h> <SDL/SDL_endian.h> <SDL/SDL_error.h> <SDL/SDL_events.h> <SDL/SDL_getenv.h> <SDL/SDL.h> <SDL/SDL_image.h> <SDL/SDL_joystick.h> <SDL/SDL_keyboard.h> <SDL/SDL_keysym.h> <SDL/SDL_main.h> <SDL/SDL_mixer.h> <SDL/SDL_mouse.h> <SDL/SDL_mutex.h> <SDL/SDL_net.h> <SDL/SDL_opengl.h> <SDL/SDL_quit.h> <SDL/SDL_rwops.h> <SDL/SDL_syswm.h> <SDL/SDL_thread.h> <SDL/SDL_timer.h> <SDL/SDL_types.h> <SDL/SDL_version.h> <SDL/SDL_video.h> | 
| <<- ->> | |
|  | |