FFPlay4Laz2 is the SDL2 version of the older SDL 1.2 based (Win32 only) FFPlay4Laz FFmpeg Video and Media Player. FFPlay4Laz2 is extended to have more features than FFPlay4Laz and provide better performance. It is designed to be cross-platform by replacing Win-API calls by SDL2 calls. The project is open source and can be found on the official Lazarus forums.
Console menue of FFPlay4Laz2. (Image source: Captured from FFPlay4Laz2_Images.pdf, see link below; 28/12/2022)
This project has no official website and the author provides updates via the official Lazarus forums (see link below).
Project name: FFPlay4Laz2
Author: metis
Latest version: v2.5.2
First release date: Thread startet in Dec. 2014
Compiler and SDL version: Free Pascal / Lazarus / SDL2
Why did you decide to choose Pascal as a programming language and SDL as a library for your projects?
Kornel Kisielewicz: Pascal was my first language, and in those days C++ was quite messy. I liked the clean syntax of Pascal and it’s default strong type system. SDL was a no brainer, we wanted a platform independent layer for OpenGL context creation and Input handling, and SDL was the only reasonable choice in that regard at the time.
What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides your own, of course :-D)?
Kornel Kisielewicz: I have been out of touch with the Pascal scene for a long time now.
Are there any new projects planned?
Kornel Kisielewicz: We’re currently working on Jupiter Hell, a spiritual successor to DoomRL, but it’s in full 3d, and written in C++.
Could you please give a short description of Monsterland for those who have never heard of it?
Aleksey: Monsterland is a 2D realtime shooter portrayed entirely through ASCII characters. This includes blood, lighting, particles, etc. Its only gameplay mode is a 3-hour story campaign, which has voiceovers, triggers and scripted sequences. The gameplay of Monsterland was heavily influenced by original Doom games (1 and 2).
Why did you decide to choose Pascal as a programming language and SDL as a library for your projects?
Aleksey: Pascal is an underrated, well-rounded programming language. It has good diagnostics and strict syntax, which removes ambiguity from error messages. It also helps that I was first introduced to it in 1992.
SDL was chosen because I’ve also been writing an engine tied to DirectX, and given where Windows is heading, it was a mistake I didn’t want to repeat. SDL 1.2 didn’t have accelerated 2D though, so I had to do it via OpenGL manually.
What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides your own, of course :-D)?
Aleksey: If Dwarf Fortress still used Pascal, I’d name that. Otherwise, DoomRL I guess.
Are there any further steps planned for the Monsterland series? What will they be?
Aleksey: Aw, you flatter, but Monsterland will not be continued.
Are there any new projects planned?
Aleksey: I’m starting to work on a new type of IF (interactive fiction) game. I clearly have an obsession with text visuals.
There’s also the ambitious isometric RPG I’ve been writing in C for years, the “magnum opus”, but it’s too ambitious at the moment, even though a lot of work has been done. I wish I wrote it in Pascal instead – it would’ve been easier to debug.
GearHead 2, successor of GearHead: Arena, is a turn-based, rouge-like role-playing game where you can explore futuristic worlds with benign graphics.
Showcase and Basic Data
(no showcase screenshots provided)
Project name: GearHead 2
Author: Joseph Hewitt, plus the work of several contributors
Latest version: 0.628
Release date: The first public release was August 23 2005; the most recent was June 1 2010. After I’ve updated GearHead-1 to my satisfaction I plan to do some revisions to this one as well.
Pascal compiler: Free Pascal
SDL Version: 1.2
Further libraries: Only those that come with the FPC compiler
GearHead: Arena (also known as GearHead 1) is a turn-based, rouge-like role-playing game where you can explore futuristic worlds with benign graphics.
Showcase and Basic Data
Developer granted permission to use these screenshots.
GearHead 2
GearHead: Arena
GearHead: Arena
Project name: GearHead: Arena, also known as GearHead 1
Author: Joseph Hewitt, plus the work of several contributors
Latest version: 1.201
Release date: The first public release was May 10 2002; the most recent was March 3 2016. After version 1.100 I stopped development for nine years before returning to update the program earlier this year.
Pascal compiler: Free Pascal
SDL Version: 1.2
Further libraries: Only those that come with the FPC compiler
Developer granted permission to use these screenshots.
Colorful
Colorful
Project name: Colorful
Author: suve
Latest version: 1.2
First release date: 2012-12-16
Compiler: FPC 2.6.2
SDL Version: 1.2
Further libraries: Originally BASS for audio handling, later replaced with SDL_mixer as to move away from proprietary library; SDL_image; Sour could probably count, too; OpenGL
Could you please give a short description of Colorful for those who have never heard of it?
suve: Colorful is a simple game where the player moves freely around a 2D world, fighting multiple enemies and trying to retrieve colourful artefacts. Originally created in 48h for Ludum Dare, the game is heavily inspired by Hero Core, featuring simplistic graphics and sounds, and a no-game-over approach balancing the overall difficulty level.
Why did you decide to choose Pascal as a programming language and SDL/SDL2 as a library for your projects?
suve: I chose Pascal mostly as it’s the language I’m most proficient and comfortable with. As for SDL, after working with a few different libraries in the past, I’ve found SDL easy to use, but nonetheless really versatile and fitting my needs. The library itself doesn’t really enforce anything on you, so you don’t have to change your habits (much), and the seemingly simplistic API is greatly extended by the supplementary SDL_XYZ libraries.
What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides of your own, of course :-D)?
suve: Supraleiter seems the most awesome of them all, I think. Shame that quite probably I won’t be able to play sit, seeing as I only have an integrated GPU.
Are there any further steps for your projects or any new projects planned? What will they be?
suve: I have two projects underway right now, but one is too early in development and I don’t want to disclose it for fear of not delivering… and the other, for a change, is written in C instead of Pascal. 🙂
Developer granted permission to use these screenshots.
Alexland
Alexland
Alexland
Alexland
Alexland
Alexland
Alexland
Alexland
Project name: Alexland
Author: suve & ZbiXs
Latest version: 1.3
First release date: 2010-01-31
Compiler: Free Pascal 2.4.0 (for the 1.3 release)
SDL Version: 1.2
Further libraries: BASS for audio handling, SDL_image, SDL_ttf, SDL_net
License: Back then we didn’t really think about licensing, and seeing how the game contains assets ripped from plenty of places without even keeping track of source… I say it’d be hard for us to claim copyright to anything apart from code and some original graphics (+edits) we created.
Open source: Nope. Maybe if there’s a remake one day.
Could you please give a short description of Alexland for those who have never heard of it?
suve: Born of RPG Maker nostalgia and the hatred for its default graphics set, Alexland is a 2D shooter where the player controls a lone hero in a fight against never-ending hordes of monsters. Featuring 12 weapons to kick ass with, 11 bonuses to enhance the gameplay, 10 monster types to kill, and 60 achievements to unlock, Alexland can provide long hours of mindless, merciless fun. Available in English, Polish, French, German and Russian.
Why did you decide to choose Pascal as a programming language and SDL/SDL2 as a library for your projects?
suve: I chose Pascal mostly as it’s the language I’m most proficient and comfortable with. As for SDL, after working with a few different libraries in the past, I’ve found SDL easy to use, but nonetheless really versatile and fitting my needs. The library itself doesn’t really enforce anything on you, so you don’t have to change your habits (much), and the seemingly simplistic API is greatly extended by the supplementary SDL_XYZ libraries.
What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides of your own, of course :-D)?
suve: Supraleiter seems the most awesome of them all, I think. Shame that quite probably I won’t be able to play sit, seeing as I only have an integrated GPU.
Are there any further steps for your projects or any new projects planned? What will they be?
suve: I have two projects underway right now, but one is too early in development and I don’t want to disclose it for fear of not delivering… and the other, for a change, is written in C instead of Pascal. 🙂
A new page has been set up which gives an overview of projects done in SDL with Pascal (any dialect). The projects may be games, interpreters, libraries, anything. Of course SDL should play a key role and shouldn’t be just used to set up an OpenGL window (or similar). If possible I try to have an interview with the creator of the project.
The first project listed is the famous EGSL project and its successor Pulsar2D. Both have been created by Cybermonkey who kindly gave an interview and provided a lot of screenshots to me.
Feel free to contact me to let me know about other Pascal SDL projects.
Edit: As of 09/02/2016 I added suve’s Alexland and Colorful to the project page. Thanks for the interview and the screenshots.
Could you please give a short description of EGSL and Pulsard2D for those who have never heard of it?
Cybermonkey: EGSL (Easy Game Scripting with Lua) is a Lua interpreter which allows one to code 2D games in a simple way. I could say in a “classical way” because EGSL is inspired by old BASIC dialects. The main difference between EGSL and Pulsar2D is that Pulsar2D uses now the newer SDL2 libraries (which gives us the possibility to use multiple windows). It’s as easy as that: write 10 lines of Lua code and start the script and you’ll have already a small sprite moving example. Of course it is possible to use the framework with FreePascal. Apart from that I recently ported the Pulsar2D framework to FreeBASIC. So one can code Pulsar2D games/demos whatsoever in Lua, FreePascal or FreeBASIC.
Why did you decide to choose Pascal as a programming language and SDL/SDL2 as a library for these projects?
Cybermonkey: I started programming back in the 1980s with the Commodore 64 and BASIC. I learned Turbo Pascal in school and started programming with FreePascal a few years ago. It’s the language I have the most experience with. Not to mention that the FreePascal compiler is well maintained. I chose SDL/SDL2 because of its cross platform capabilities.
What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides of your own, of course :-D)?
Cybermonkey: Actually I don’t know of any other … But of course the most impressive Pascal project is Lazarus for me.
Are there any further steps for EGSL and/or Pulsar2D or any new projects planned? What will they be?
Cybermonkey: EGSL will not be developed any further. Pulsar2D wil be improved from time to time. My plans are to implement Box2D physics and easy handling of tiled based maps made with the Tiled editor. But this has no priority so it can take a long time…
At the moment I am developing a little BASIC interpreter called “AllegroBASIC”. It’s a C project, though. (The editor, however, is made with Lazarus…) Since I am using Allegro4 libs which are obsolete now, I am porting at the same time the project to SDL2 which will be named “RETROBASIC”. If there are people interested in AllegroBASIC, have a look at allegrobasic.pulsar2d.org.
If you experience troubles: First of all, make sure the problem is really caused by the 64 bit operating system you use. Does the program run without any problems if run it in a 32 bit operating system?
Make sure, that the Free Pascal compiler you use is the 64 bit version. There are different links on the download page of Free Pascal to different 64 bit operating systems for different architectures (Intel, AMD, PowerPC), so did you install the right 64 bit version of FPC?
If all this applies and you still get an error saying
sdlutils.pas Warning: Conversion between ordinals and pointers is not portable
and/or
sdlutils.pas Error: Typecast has different size (4 -> 8) in assignment
(or similar messages) then your problem clearly is related to 64 bit compatibility.
In the FPC reference is written about this type-checking error:
If you typecast a pointer to an ordinal type of a different size (or vice-versa), this can cause problems. This is a warning to help in finding the 32-bit specific code where cardinal/longint is used to typecast pointers to ordinals. A solution is to use the ptrint/ptruint types instead.
That is exactly what is done by sdlutils.pas and many other files and causes the errors and warnings!
In other words, the size of pointers and integers is different on 64 bit systems. They should be of same size to make conversion safe. To circumvent this problem you have to replace a conversion of UINT32(POINTER) by PTRUINT(POINTER) and INTEGER(POINTER) by PTRINT(POINTER). The PTRUINT and PTRINT integer types are always the same size as the pointer by definition. For FPC users both types are introduced since version 1.9.3. For other compilers (e.g. Delphi, Kylix, GPC, …) they are not and you have to define them yourself (see below).
Examples:
1) sdlutils.pas:
p := Pointer( Uint32( SrcSurface.pixels ) + UInt32( y ) * SrcSurface.pitch + UInt32( x ) * bpp );" gets "p := Pointer( PtrUInt( SrcSurface.pixels ) + UInt32( y ) * SrcSurface.pitch + UInt32( x ) * bpp );
Definition of PTRUINT and PTRINT for non-FPC compilers:
{$ifndef FPC}
type
PtrInt = LongInt;
PtrUInt = LongWord;
{$endif}
There is a patch which is replacing all the questionable parts of the JEDI-SDL package, so you wouldn’t have to do it manually. Furthermore it is introducing the definition of the new types for non-FPC compilers. Link: Patch for 64 bit support. Unfortunately it is only useful if you manage your JEDI-SDL files by CVS or SVN. Nevertheless you could download the patch and check what the patch is changing and how to do it properly (the examples are generated from the patch).
SDL is the abbreviation of Simple DirectMedia Layer. It is a software library written in C which provides a free, easy and platform-independent access to features needed for developing high performance games and applications. This includes easy access to graphic, sound and input device handling (keyboard, gamepad, mouse, joystick, touch screen, …)
The idea is, you create a program against SDL and it should compile on any supported platform (Linux, Windows, Mac, Android, iOS, Playstation, …) without or with minimal adaptions necessary.
Originally when referring to SDL, SDL version 1.2 was meant. It is the predecessor of SDL2 and modern SDL3. Nowadays, when refering to SDL, it depends on context if you really mean the old SDL 1.2, the successor SDL2 or the modern SDL3.
For the obsolete SDL versions and the modern SDL3 are sets of units available for Free Pascal and other Pascal dialects.
SDL was developed between 1998 and 2001 by Sam Lantinga, the chief programmer of the software company Loki Games. It should be a tool to convert successful Windows games to Linux. In 2002 the company got bankrupt though, but Lantinga went on developing SDL. So it got updated continuously until today. In August 2013 the successor SDL2 has been released.
On January the 21st in 2025 SDL3 has been released and introduces a lot of new features which allow development of high performance applications using up-to-date technologies.
Although the original library isn’t written in Pascal, fortunately the SDL3 headers got translated to Pascal, so the SDL3 library is usable for Pascal developers as well.
This page is made to help you to start with SDL3 (or the older SDL or SDL2) under Free Pascal (or other Pascal dialects) and to acquaint yourself with SDL’s concepts and commands.
Be aware though that my tutorials gives just a brief overview and introduction to SDL and are far from being all-embracing.
The tutorials aim at Pascal programmers knowing the basic concepts (loops, functions, pointers) of Pascal and now like to progress to SDL3 (or older SDL/SDL2).
This is an SDL 1.2 chapter. SDL 1.2 is obsolete since it has been replaced by SDL 2.0. Unless you have good reasons to stay here you may prefer to go for the modern SDL 2.0 :-).
It is highly recommended that you read the previous Chapter 8. The code from last chapter was used and modified to show how the conversion works. However, I won’t explain twice everything already introduced in Chapter 8. Also I’d like to express here that NeHe Productions’ OpenGL tutorial 06 “Texture Mapping” and the translated (by Dominique Louis) Jedi-SDL file was inspiring me a lot for this chapter.
You need this software:
Software
Version
Source
Description
OpenGL driver
–
–
Usually your graphic card provides the corresponding OpenGL driver and you don’t have to do anything. And if so it is very likely that version 1.1 is fully supported. However if you are one of the few poor people whose graphic card doesn’t support OpenGL, check the graphic card’s manufacturer’s homepage for OpenGL drivers.
Now following the whole code at once as usual. As you will notice many lines are exactly the same as in Chapter 8.
PROGRAM chap8a;
USES CRT, SDL, GL, GLU;
VAR
userkey:CHAR;
screen, picture:pSDL_SURFACE;
h,hh,th,thh:REAL;
ogl_texture:pGLUINT;
BEGIN
//some calculations needed for a regular tetrahedron with side length of 1
h:=SQRT(0.75); //height of equilateral triangle
hh:=h/2; //half height of equilateral triangle
th:=0.75; //height of tetrahedron
thh:=th/2; //half height of tetrahedron
SDL_INIT(SDL_INIT_VIDEO);
SDL_GL_SETATTRIBUTE(SDL_GL_RED_SIZE, 5);
SDL_GL_SETATTRIBUTE(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SETATTRIBUTE(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SETATTRIBUTE(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SETATTRIBUTE(SDL_GL_DOUBLEBUFFER, 1);
screen:=SDL_SETVIDEOMODE(640, 480, 0, SDL_OPENGL);
IF screen=NIL THEN HALT;
//preparing SDL image
picture:=SDL_LOADBMP('C:\fpsdl256.bmp');
IF picture=NIL THEN HALT;
//preparing OpenGL texture
NEW(ogl_texture);
glGENTEXTURES(1, ogl_texture);
glBINDTEXTURE(GL_TEXTURE_2D, ogl_texture^);
glTEXIMAGE2D(GL_TEXTURE_2D, 0, 3, picture^.w, picture^.h, 0,
GL_RGB, GL_UNSIGNED_BYTE, picture^.pixels);
glTEXPARAMETERi(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTEXPARAMETERi(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FREESURFACE(picture);
glCLEARCOLOR(0.0, 0.0, 1.0, 0.0);
glVIEWPORT(0,0,640,480);
glMATRIXMODE(GL_PROJECTION);
glLOADIDENTITY;
gluPERSPECTIVE(45.0, 640.0/480.0, 1.0, 3.0);
glMATRIXMODE(GL_MODELVIEW);
glLOADIDENTITY;
glCLEAR(GL_COLOR_BUFFER_BIT);
glENABLE(GL_CULL_FACE);
glTRANSLATEf(0.0, 0.0, -2.0);
REPEAT
SDL_DELAY(50);
glROTATEf(5, 0.0, 1.0, 0.0);
glCLEAR(GL_COLOR_BUFFER_BIT);
//drawing textured face of tetrahedron
glENABLE(GL_TEXTURE_2D);
glBEGIN(GL_TRIANGLES);
glTEXCOORD2f(2,2);
glVERTEX3f(thh, 0.0, 0.0);
glTEXCOORD2f(0,0);
glVERTEX3f(-thh, hh, 0.0);
glTEXCOORD2f(0,2);
glVERTEX3f(-thh, -hh, 0.5);
glEND;
glDISABLE(GL_TEXTURE_2D);
//drawing remaining three untextured faces
glBEGIN(GL_TRIANGLES);
glCOLOR3f(0.0, 1.0, 1.0);
glVERTEX3f(thh, 0.0, 0.0);
glVERTEX3f(-thh, -hh, -0.5);
glVERTEX3f(-thh, hh, 0.0);
glCOLOR3f(1.0, 0.0, 1.0);
glVERTEX3f(thh, 0.0, 0.0);
glVERTEX3f(-thh, -hh, 0.5);
glVERTEX3f(-thh, -hh, -0.5);
glCOLOR3f(1.0, 1.0, 1.0);
glVERTEX3f(-thh, -hh, 0.5);
glVERTEX3f(-thh, hh, 0.0);
glVERTEX3f(-thh, -hh, -0.5);
glEND;
SDL_GL_SWAPBUFFERS;
UNTIL keypressed;
glDELETETEXTURES(1, ogl_texture);
DISPOSE(ogl_texture);
SDL_QUIT;
END.
This code will again draw a tetrahedron which is spinning, as known from Chapter 8. However, this time one face is textured with the “Free Pascal meets SDL” image known from Chapter 3. Now lets go through the code step by step.
PROGRAM chap8a;
USES CRT, SDL, GL, GLU;
VAR
userkey:CHAR;
screen, picture:pSDL_SURFACE;
h,hh,th,thh:REAL;
ogl_texture:pGLUINT;
The program is called “chap8a”. Additionally to the variables defined in the previous chapter there are two new variables. The SDL surface “picture” which will store the SDL image before converting it to an OpenGL texture. ogl_texture is an integer pointer variable (provided by the OpenGL Uitility Library (GLU), so pGLUINT) which is needed to reference to the OpenGL texture we will create from the SDL image.
BEGIN
//some calculations needed for a regular tetrahedron with side length of 1
h:=SQRT(0.75); //height of equilateral triangle
hh:=h/2; //half height of equilateral triangle
th:=0.75; //height of tetrahedron
thh:=th/2; //half height of tetrahedron
SDL_INIT(SDL_INIT_VIDEO);
SDL_GL_SETATTRIBUTE(SDL_GL_RED_SIZE, 5);
SDL_GL_SETATTRIBUTE(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SETATTRIBUTE(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SETATTRIBUTE(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SETATTRIBUTE(SDL_GL_DOUBLEBUFFER, 1);
screen:=SDL_SETVIDEOMODE(640, 480, 0, SDL_OPENGL);
IF screen=NIL THEN HALT;
The code shown here is discussed in detail in Chapter 8. In short the tetrahedron parameters are calculated, some important OpenGL scene settings are applied and finally the SDL video subsystem is intilized.
//preparing SDL image
picture:=SDL_LOADBMP('C:\fpsdl256.bmp');
IF picture=NIL THEN HALT;
First we should load a simple BMP image to a SDL surface as known from Chapter 3. There are some limitations about the height and length of images if used as OpenGL textures. Their pixel height and pixel length has to be power of 2. So whatever image you use, its height and lengths should fulfill the following equation: f(n) = 2n. So appropriate values are: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,… The height and length don’t have to be of the same size, so an image with height 64 px and width 32 px is perfectly acceptable. This means the image of Chapter 3 with height and length of 200 x 200 px is not acceptable. A new image with 256 x 256 dimensions is therefore provided now:
Free Pascal meets SDL images with 256×256 dimensions
First the pointer “ogl_texture” gets some space. glGENTEXTURES(number of IDs, array of integer pointer) generates one or more OGL integer identifiers for textures. Anyway, we just have one texture, so we just need one texture identifier, therefore we request “1” and ogl_texture should point at it. If we need to identify the texture we just need to call ogl_texture from now on.
glBINDTEXTURE(target, texture) essentially creates a texture object of type: GL_TEXTURE_1D or GL_TEXTURE_2D. Usually textures in 2d and 3d games are two-dimensional, so GL_TEXTURE_2D is a good choice. Now it is clear, ogl_texture will be a 2d texture.
Briefly, glTEXIMAGE2D(target, mipmap level, internal image format, width, height, border, pixel format, pixel type, actual pixel data) creates the actual 2d texture. The target is GL_TEXTURE_2D again since we are looking for creating a 2d texture. The mipmap level should be set to 0 because we wouldn’t want to have a mipmap effect here. A higher number corresponds to the number’s mipmap level, anyway in the example for a number different from 0 there is no image at all finally. The internal image format is RGB because the image is a RGB image, anyway there is a large list of possibilities for this parameter, you should look it up in the internet if you’re interested. The width and height of the image in pixels is received from the SDL image. The border is off (values 0 and 1 are acceptable). The pixel format is RGB, too, so again SDL_RGB is the right choice here. The pixel explains how the pixel data is stored. The pixel data from the SDL image is stored as unsigned byte (GL_UNSIGNED_BYTE). Finally the pixel data pointer of the SDL image is needed. Essentially the SDL image is now transformed to an OGL texture!
Briefly, glTEXPARAMETERi(target, texture parameter, parameter value) allocates a certain value to a specific texture parameter. The possible parameters and values are OGL specific and won’t be treated here in more detail. Anyway, again we are concerned about our 2d texture, so the target is GL_TEXTURE_2D. The parameters to be set are GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER. They are used to define how to treat textures that have to be drawn to a smaller or larger scale. The routine used for this is specified by GL_LINEAR.
Since the SDL image isn’t needed anymore it can be omitted as known by SDL_FREESURFACE.
This part is completely described in Chapter 8. Nothing has changed for this part. In short, the viewport is set up so that the tetrahedron finally can be seen.
Now the REPEAT..UNTIL loop is entered which is delayed by 50 milliseconds by known SDL_DELAY. Each cycle the the scene gets rotated by 5 degrees around the y-axis by function glROTATEf. More details about this in Chapter 8.
The actual texturing of one of the four triangles of the tetrahedron is now described. Therefore 2d texturing has to be enabled by glENABLE(OGL capability). The capability we would like to enable is defined by GL_TEXTURE_2D.
Just as known from Chapter 8 the triangle mode is started by glBEGIN(geometric primitive type) with GL_TRIANGLES. Instead of a color we now define specific texture coordinates which should be allocated to specific vertices. glTEXCOORD2f(s coordinate, t coordinate) is used to define the coordinate of the texture we then allocate to a specific vertex. By the way, even though the official names of the texture coordinates are s and t, they can be considered as x and y values, which is more common for two-dimensional coordinate systems. The values for s and t are relative, so a value of 1 (= 100%) means the full width or height, independent of the actual width or height (32 x 32, 64 x 64, 128 x 256, …), a value of 2 (= 200%) then corresponds to two times the texture’s width or height. The coordinate (s, t) = (2, 2) is allocated to the vertex with the vertex coordinates (x, y, z) = (thh, 0.0, 0.0). Texture coordinate (0, 0) is allocated to vertex (thh, hh, 0.0). Texture coordinate (0, 2) is allocated to vertex (thh, hh, 0.5). Often this texturing process is compared to papering a wall, and indeed there are similarities. The vertex coordinates are exactly the same as for the first triangle in Chapter 8.
Finally the geometry definition and the texturing mode is finished by glEND and glDISABLE(OGL capability).
The remaining three areas of the triangle are kept as in Chapter 8. Finally the display buffer if swapped after each cycle and the REPEAT..UNTIL loop stopped if a key is pressed in the console.
Last but not least everything has to be free’s and closed as known. Anyway, the texture has to free’d by glDELETETEXTURES(number of textures, texture pointer). Then the pointer can be disposed as known and SDL can be quit.
Again, if you want to learn OpenGL and its capabilities to a more advaced extend you need to read more professional tutorials related to pure OpenGL programming. As a starting point I’d like to mention NeHe Productions’ OpenGL tutorials again, because they are professional and provide example code for JEDI-SDL for several lessons. 🙂
This file contains the source code: chap8a.pas (right click and “save as”)
This file is the executable: chap8a.exe (right click and “save as”)
The final result should look and behave like this: A tetrahedron consisting of three different coloured areas (cyan, magenta and white) and one textured area is spinning slowly around itself. When pressing a key in the console the show quits.