ZenGL Tutorial/es: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: ZenGL Tutorial/es
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Descarga | |
| 2 | + | ||
| 3 | + | Puedes obtener [[ZenGL/es|ZenGL]] para Linux, Windows y Mac. [Descargar ZenGL](http://zengl.org/download.html). | |
| 4 | + | ||
| 5 | + | ## Instalacion | |
| 6 | + | ||
| 7 | + | Descomprimir el archivo descargado con un gestor de archivos comprimidos como 7-Zip en la carpeta que desees. | |
| 8 | + | ||
| 9 | + | ### Ruta de las Fuentes | |
| 10 | + | ||
| 11 | + | Antes de usar los modulos no olvides establecer la ruta a las fuentes de ZenGL. | |
| 12 | + | ||
| 13 | + | Ve a "*Proyecto \> Opciones del Proyecto*". En "*Opciones del compilador \> Rutas*" debes añadir lo siguiente en "*Otros archivos de unidad*": | |
| 14 | + | ||
| 15 | + | ```text | |
| 16 | + | headers | |
| 17 | + | extra | |
| 18 | + | src | |
| 19 | + | src\Direct3D | |
| 20 | + | lib\jpeg\$(TargetCPU)-$(TargetOS) | |
| 21 | + | lib\msvcrt\$(TargetCPU) | |
| 22 | + | lib\ogg\$(TargetCPU)-$(TargetOS) | |
| 23 | + | lib\zlib\$(TargetCPU)-$(TargetOS) | |
| 24 | + | ``` | |
| 25 | + | ||
| 26 | + | ## Compilacion | |
| 27 | + | ||
| 28 | + | Las aplicaciones pueden ser compiladas con ZenGL estáticamente o usando so/dll/dylib. | |
| 29 | + | ||
| 30 | + | Lee mas acerca de la [compilación](http://zengl.org/wiki/doku.php?id=compilation) en la [Wiki de ZenGL](http://zengl.org/wiki/). | |
| 31 | + | ||
| 32 | + | ### ZenGL estaticamente | |
| 33 | + | ||
| 34 | + | La ventaja de la compilación estática es que genera una aplicación de menor tamaño, pero requiere incluir todas las unidades. | |
| 35 | + | ||
| 36 | + | Además la compilación estática requiere seguir los términos de la licencia-[[LGPL]], particularmente debes hacer de código abierto (*open source*) tu aplicación si usa código fuente de ZenGL. | |
| 37 | + | ||
| 38 | + | ``` pascal | |
| 39 | + | {$DEFINE STATIC} | |
| 40 | + | ``` | |
| 41 | + | ||
| 42 | + | ### ZenGL usando so/dll/dylib | |
| 43 | + | ||
| 44 | + | Usando so/dll/dylib no requiere hacer de código abierto tu aplicación. Para hacer esto comenta el *\$DEFINE STATIC*. También necesitarás compilar la librería ZenGL. | |
| 45 | + | ||
| 46 | + | ``` pascal | |
| 47 | + | //{$DEFINE STATIC} | |
| 48 | + | ``` | |
| 49 | + | ||
| 50 | + | #### Windows dll | |
| 51 | + | ||
| 52 | + | Abre "*src\Lazarus\ZenGL.lpi*" y luego ve a "*Ejecutar \> Compilar (Ctrl + F9)*". | |
| 53 | + | ||
| 54 | + | Luego en el directorio "*src\*" puedes ver el archivo "*ZenGL.dll*", copia y pegalo en la carpeta "*bin\i386*" donde todos los binarios de los demos son compilados. Siempre debes copiar las librerías en el directorio de salida de tu aplicación si usas dll. | |
| 55 | + | ||
| 56 | + | Ahora puedes compilar los demos comentando *\$DEFINE STATIC*. | |
| 57 | + | ||
| 58 | + | Otros archivos dll en la carpeta "*bin\*" que puedes usar son: `chipmunk.dll ; libogg-0.dll ; libvorbis-0.dll ; libvorbis-3.dll` | |
| 59 | + | ||
| 60 | + | ## Primer programa | |
| 61 | + | ||
| 62 | + | Este es el primer programa demo incluido con ZenGL, primero crea un nuevo "Programa Pascal". Agrega las rutas al código fuente como fue descrito anteriormente. | |
| 63 | + | ||
| 64 | + | También debes cambiar el modo de sintáxis en *Proyecto \> Opciones del Proyecto \> Opciones del Compilador \> Procesando* a *Delphi (-Mdelphi)*. | |
| 65 | + | ||
| 66 | + | Recuerda, si estás usando so/dll/dylib copia los binarios de las librerías al directorio de salida de tu programa. | |
| 67 | + | ||
| 68 | + | Título del programa, agregar recursos: | |
| 69 | + | ||
| 70 | + | ``` pascal | |
| 71 | + | program demo01; | |
| 72 | + | ||
| 73 | + | {$R *.res} | |
| 74 | + | ``` | |
| 75 | + | ||
| 76 | + | Define el modo de compilación (comentalo para usar so/dll/dylib): | |
| 77 | + | ||
| 78 | + | ``` pascal | |
| 79 | + | {$DEFINE STATIC} | |
| 80 | + | ``` | |
| 81 | + | ||
| 82 | + | Agrega las unidades de ZenGL. | |
| 83 | + | ||
| 84 | + | ``` pascal | |
| 85 | + | uses | |
| 86 | + | {$IFNDEF STATIC} | |
| 87 | + | zglHeader | |
| 88 | + | {$ELSE} | |
| 89 | + | zgl_main, | |
| 90 | + | zgl_screen, | |
| 91 | + | zgl_window, | |
| 92 | + | zgl_timers, | |
| 93 | + | zgl_utils | |
| 94 | + | {$ENDIF} | |
| 95 | + | ; | |
| 96 | + | ``` | |
| 97 | + | ||
| 98 | + | Variables como en un programa estándar de pascal: | |
| 99 | + | ||
| 100 | + | ``` pascal | |
| 101 | + | var | |
| 102 | + | DirApp : String; | |
| 103 | + | DirHome : String; | |
| 104 | + | ``` | |
| 105 | + | ||
| 106 | + | Procedimientos para agregar código: | |
| 107 | + | ||
| 108 | + | ``` pascal | |
| 109 | + | procedure Init; | |
| 110 | + | begin | |
| 111 | + | // Aquí se puede realizar la carga de los recursos principales. | |
| 112 | + | end; | |
| 113 | + | ||
| 114 | + | procedure Draw; | |
| 115 | + | begin | |
| 116 | + | // Aquí dibuja cualquier cosa. | |
| 117 | + | end; | |
| 118 | + | ||
| 119 | + | procedure Update( dt : Double ); | |
| 120 | + | begin | |
| 121 | + | // Esta función es la mejor manera para implementar movimiento suavizado de algo, porque los temporizadores son restringidos por FPS. | |
| 122 | + | end; | |
| 123 | + | ||
| 124 | + | procedure Timer; | |
| 125 | + | begin | |
| 126 | + | // El título mostrará los cuadros por segundo. | |
| 127 | + | wnd_SetCaption( '01 - Initialization[ FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) ) + ' ]' ); | |
| 128 | + | end; | |
| 129 | + | ||
| 130 | + | procedure Quit; | |
| 131 | + | begin | |
| 132 | + | // | |
| 133 | + | end; | |
| 134 | + | ``` | |
| 135 | + | ||
| 136 | + | Aquí comienza el programa: | |
| 137 | + | ||
| 138 | + | ``` pascal | |
| 139 | + | Begin | |
| 140 | + | {$IFNDEF STATIC} | |
| 141 | + | zglLoad( libZenGL ); | |
| 142 | + | {$ENDIF} | |
| 143 | + | // For loading/creating your own options/profiles/etc. you can get path to user home | |
| 144 | + | // directory, or to executable file(not works for GNU/Linux). | |
| 145 | + | DirApp := u_CopyStr( PChar( zgl_Get( DIRECTORY_APPLICATION ) ) ); | |
| 146 | + | DirHome := u_CopyStr( PChar( zgl_Get( DIRECTORY_HOME ) ) ); | |
| 147 | + | ||
| 148 | + | //Crea un temporizador con un intervalo de 1000ms. | |
| 149 | + | timer_Add( @Timer, 1000 ); | |
| 150 | + | ||
| 151 | + | // Register the procedure, that will be executed after ZenGL initialization. | |
| 152 | + | zgl_Reg( SYS_LOAD, @Init ); | |
| 153 | + | // Register the render procedure. | |
| 154 | + | zgl_Reg( SYS_DRAW, @Draw ); | |
| 155 | + | // Register the procedure, that will get delta time between the frames. | |
| 156 | + | zgl_Reg( SYS_UPDATE, @Update ); | |
| 157 | + | // Register the procedure, that will be executed after ZenGL shutdown. | |
| 158 | + | zgl_Reg( SYS_EXIT, @Quit ); | |
| 159 | + | ||
| 160 | + | // Enable using of UTF-8, because this unit saved in UTF-8 encoding and here used | |
| 161 | + | // string variables. | |
| 162 | + | zgl_Enable( APP_USE_UTF8 ); | |
| 163 | + | ||
| 164 | + | // Establece el título de la ventana. | |
| 165 | + | wnd_SetCaption( '01 - Initialization' ); | |
| 166 | + | ||
| 167 | + | // Permite mostrar el cursor. | |
| 168 | + | wnd_ShowCursor( TRUE ); | |
| 169 | + | ||
| 170 | + | // Establece opciones de pantalla. | |
| 171 | + | scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE ); | |
| 172 | + | ||
| 173 | + | // Iniciar ZenGL. | |
| 174 | + | zgl_Init(); | |
| 175 | + | End. | |
| 176 | + | ``` | |
| 177 | + | ||
| 178 | + | ### Codigo Resultante | |
| 179 | + | ||
| 180 | + | El resultado es una *plantilla* para los proyectos de ZenGL: | |
| 181 | + | ||
| 182 | + | ``` pascal | |
| 183 | + | program template; | |
| 184 | + | ||
| 185 | + | {$DEFINE STATIC} | |
| 186 | + | ||
| 187 | + | {$R *.res} | |
| 188 | + | ||
| 189 | + | uses | |
| 190 | + | {$IFNDEF STATIC} | |
| 191 | + | zglHeader | |
| 192 | + | {$ELSE} | |
| 193 | + | zgl_main, | |
| 194 | + | zgl_screen, | |
| 195 | + | zgl_window, | |
| 196 | + | zgl_timers, | |
| 197 | + | zgl_utils | |
| 198 | + | {$ENDIF} | |
| 199 | + | ; | |
| 200 | + | ||
| 201 | + | var | |
| 202 | + | DirApp : String; DirHome : String; | |
| 203 | + | ||
| 204 | + | procedure Init; | |
| 205 | + | begin | |
| 206 | + | end; | |
| 207 | + | ||
| 208 | + | procedure Draw; | |
| 209 | + | begin | |
| 210 | + | end; | |
| 211 | + | ||
| 212 | + | procedure Update( dt : Double ); | |
| 213 | + | begin | |
| 214 | + | end; | |
| 215 | + | ||
| 216 | + | procedure Timer; | |
| 217 | + | begin | |
| 218 | + | wnd_SetCaption( '01 - Initialization[ FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) ) + ' ]' ); | |
| 219 | + | end; | |
| 220 | + | ||
| 221 | + | procedure Quit; | |
| 222 | + | begin | |
| 223 | + | end; | |
| 224 | + | ||
| 225 | + | Begin | |
| 226 | + | {$IFNDEF STATIC} | |
| 227 | + | zglLoad( libZenGL ); | |
| 228 | + | {$ENDIF} | |
| 229 | + | DirApp := u_CopyStr( PChar( zgl_Get( DIRECTORY_APPLICATION ) ) ); | |
| 230 | + | DirHome := u_CopyStr( PChar( zgl_Get( DIRECTORY_HOME ) ) ); | |
| 231 | + | timer_Add( @Timer, 1000 ); | |
| 232 | + | zgl_Reg( SYS_LOAD, @Init ); | |
| 233 | + | zgl_Reg( SYS_DRAW, @Draw ); | |
| 234 | + | zgl_Reg( SYS_UPDATE, @Update ); | |
| 235 | + | zgl_Reg( SYS_EXIT, @Quit ); | |
| 236 | + | zgl_Enable( APP_USE_UTF8 ); | |
| 237 | + | wnd_SetCaption( '01 - Initialization' ); | |
| 238 | + | wnd_ShowCursor( TRUE ); | |
| 239 | + | scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE ); | |
| 240 | + | zgl_Init(); | |
| 241 | + | End. | |
| 242 | + | ``` | |
| 243 | + | ||
| 244 | + | --- | |
| 245 | + | *From the Free Pascal wiki, page "ZenGL Tutorial/es", as it stood on 2020-03-03 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
