
| 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. |
PROGRAM chap8;
USES CRT, SDL, GL, GLU;
VAR
userkey:CHAR;
screen:pSDL_SURFACE;
h,hh,th,thh:REAL;
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;
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 );
glBEGIN(GL_TRIANGLES);
glCOLOR3f(1.0, 1.0, 0.0);
glVERTEX3f(thh, 0.0, 0.0);
glVERTEX3f(-thh, hh, 0.0);
glVERTEX3f(-thh, -hh, 0.5);
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;
SDL_QUIT;
END.
|
PROGRAM chap8; USES CRT, SDL, GL, GLU; VAR userkey:CHAR; screen:pSDL_SURFACE; h,hh,th,thh:REAL; 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; |
| Attribute | Description |
|---|---|
| SDL_GL_RED_SIZE | Size of the framebuffer red component, in bits |
| SDL_GL_GREEN_SIZE | Size of the framebuffer green component, in bits |
| SDL_GL_BLUE_SIZE | Size of the framebuffer blue component, in bits |
| SDL_GL_ALPHA_SIZE | Size of the framebuffer alpha component, in bits |
| SDL_GL_DOUBLEBUFFER | 0 or 1, enable or disable double buffering |
| SDL_GL_BUFFER_SIZE | Size of the framebuffer, in bits |
| SDL_GL_DEPTH_SIZE | Size of the depth buffer, in bits |
| SDL_GL_STENCIL_SIZE | Size of the stencil buffer, in bits |
| SDL_GL_ACCUM_RED_SIZE | Size of the accumulation buffer red component, in bits |
| SDL_GL_ACCUM_GREEN_SIZE | Size of the accumulation buffer green component, in bits |
| SDL_GL_ACCUM_BLUE_SIZE | Size of the accumulation buffer blue component, in bits |
| SDL_GL_ACCUM_ALPHA_SIZE | Size of the accumulation buffer alpha component, in bits |
| Source of table and content: JEDI-SDL documentation. |
screen:=SDL_SETVIDEOMODE(640, 480, 0, SDL_OPENGL); IF screen=NIL THEN HALT; |
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 );
glBEGIN(GL_TRIANGLES);
glCOLOR3f(1.0, 1.0, 0.0);
glVERTEX3f(thh, 0.0, 0.0);
glVERTEX3f(-thh, hh, 0.0);
glVERTEX3f(-thh, -hh, 0.5);
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;
SDL_QUIT;
END.
|

![]() |
The final result should look and behave like this: A tetrahedron consisting of four different coloured areas (yellow, cyan, magenta and white) is spinning slowly around itself. When pressing a key in the console the show quits. |