Browse Source

Proofread README.md

master
Martok 7 years ago
parent
commit
35b02c3657
1 changed files with 36 additions and 35 deletions
  1. +36
    -35
      README.md

+ 36
- 35
README.md View File

@@ -1,5 +1,5 @@
# Overview
OpenGL is a usefull collection of classes for creating OpenGL projects in FreePascal. It wraps the most common OpenGL objects (such as RenderContext, Textures, VertexArray, FrameBuffer, ...) into simple classes. Also it comes with some data types all around graphic programming.
OpenGL is a useful collection of classes for creating OpenGL projects in Free Pascal. It wraps the most common OpenGL objects (such as RenderContext, Textures, VertexArray, FrameBuffer, ...) into simple classes. It also comes with some data types all around graphic programming.

1. dglOpenGL and dglOpenGLES
2. The render context
@@ -15,26 +15,26 @@ OpenGL is a usefull collection of classes for creating OpenGL projects in FreePa
5. Helper types

# 1. dglOpenGL and dglOpenGLES
The files dglOpenGL.pas and dglOpenGLES.pas contains all necessary constants, types and functions to make calls to the OpenGL or OpenGLES library. Also it cares about dynamically loading the needed function pointers from the library. If you want to write pure OpenGL code, this two files is all you need. The rest of this project is just to make your live easier.
The files dglOpenGL.pas and dglOpenGLES.pas contain all necessary constants, types and functions to make calls to the OpenGL or OpenGLES library. Also it takes care of dynamically loading the required function pointers from the library. If you want to write pure OpenGL code, these two files are all you need. The rest of this project is just to make your life easier.

dglOpenGL.pas and gdlOpenGLES.pas are maintained by the [Delphi OpenGL Community](http://delphigl.com).

# 2. The render context
The render context class is used to create a OpenGL render context. It is the first step you have to do before you continue writing your OpenGL App.
The render context class is used to create an OpenGL render context. It is the first step you have to do before you continue writing your OpenGL App.

First we need to know wich context class we have to create, because every operation system (e.g. Windows, Linux) and every UI service (e.g. X11, Gtk2) has it's own way to create a render context. Luckily this projects has a simple way to do this.
First we need to know wich context class we have to create, because every operating system (e.g. Windows, Linux) and every UI toolkit (e.g. pure X11, Gtk2) has its own way to create a render context. Luckily this project has a simple way to do this.
```pascal
var ContextClass: TglcContextClass;
ContextClass := TglcContext.GetPlatformClass();
```

The second think we need is a suitable pixel format descriptor that will change the pixel format of our device context to our needs. This is as simple as the last step.
The second thing we need is a suitable pixel format descriptor that will change the pixel format of our device context to our needs. This is as simple as the last step.
```pascal
var cpfs: TglcContextPixelFormatSettings;
cpfs := ContextClass.MakePF();
```

Now we can create our context object. This will not create the render context! The context objects is a simple object to manage the render context. The render context will be created later.
Now we can create our context object. This will not create the render context! The context object is a simple object to manage the render context. The render context will be created later.
```pascal
var Context: TglcContext;
Context := ContextClass.Create(aWinControl, cpfs);
@@ -42,12 +42,12 @@ Context := ContextClass.Create(aWinControl, cpfs);

Now everything is ready to use. We can create our render context.

_!Note: This step can be done in a separate thread, if yout want to do some offscreen rendering. But be carefull the render context can only be used in the thread were it was created._
_!Note: This step can be done in a separate thread, if yout want to do some offscreen rendering. But be careful: the render context can only be used in the thread were it was created._
```pascal
Context.BuildContext();
```

Congratulation, you have created a valid render context and can start normal rendering now. After you are finished you should cleanup everything. Never mind if you forget to do this, the TglcContext will care about that for you.
Congratulations, you have created a valid render context and can start normal rendering now. After you are finished you should cleanup everything. Never mind if you forget to do this, the TglcContext will care about that for you.
```pascal
Context.CloseContext();
```
@@ -59,7 +59,7 @@ FreeAndNil(Context);

# 3. OpenGL object classes
## i. TglcArrayBuffer
Array buffers, also known as vertex buffer objects, are used to store vertex data in video memory. So you can render your geometry very fast. Before you upload your data to the video memory you need to define what data you want to upload. We will define a vertex that has a three dimensional position, a two dimensional texture position and a three dimensional normal vector.
Array buffers, also known as vertex buffer objects, are used to store vertex data in video memory, so you can render your geometry very fast. Before you upload your data to the video memory you need to define what data you want to upload. We will define a vertex that has a three dimensional position, a two dimensional texture coordinate and a three dimensional normal vector.
```pascal
type
TVertex = packed record
@@ -70,12 +70,12 @@ end;
PVertex = ^TVertex;
```

Once you have defined your data, you can create a array buffer and upload your data to the video memory. In this example we use indexed vertex rendering. Each vertex is only stored once in our vertex array and then we will define an index array that describes wich vertices have to be rendered.
Once you have defined your data, you can create an array buffer and upload your data to the video memory. In this example we use indexed vertex rendering. Each vertex is only stored once in our vertex array and then we will define an index array that describes which vertices have to be rendered.
```pascal
varv
VertexBuffer: TglcArrayBuffer;
IndexBuffer: TglcArrayBuffer;
p: Pointer;
p: Pointer;

{ create our buffer objects }
VertexBuffer := TglcArrayBuffer.Create(TglcBufferTarget.btArrayBuffer);
@@ -84,7 +84,7 @@ IndexBuffer := TglcArrayBuffer.Create(TglcBufferTarget.btElementArrayBuffer);
{ write vertex data to vertex buffer }
vBuffer.Bind;

// allocate 4 * sizeof(TVertex) bytes of video memory and set it's usage to StaticDraw
// allocate 4 * sizeof(TVertex) bytes of video memory and set its usage to StaticDraw
vBuffer.BufferData(4, SizeOf(TVertex), TglcBufferUsage.buStaticDraw, nil);

// memory map video memory to our application
@@ -96,9 +96,9 @@ try
PVertex(p).tex := gluVertex2f(0.0, 0.5);
PVertex(p).nor := gluVertex3f(0.0, 1.0, 0.0);
inc(p, SizeOf(TVertex));
{ ... more vertices following }
finally
vBuffer.UnmapBuffer;
vBuffer.Unbind;
@@ -111,16 +111,16 @@ p := iBuffer.MapBuffer(TglcBufferAccess.baWriteOnly);
try
PGLuint(p) := 0;
inc(p, sizeof(GLuint));
{ ... more indices following }
finally
iBuffer.UnmapBuffer;
iBuffer.Unbind;
end;
end;
```

All data is uploaded. Know we can render our vertices using one of the glDraw methods. Before you call glDraw you must tell OpenGL where the vertex data is stored.
All data is uploaded. Now we can render our vertices using one of the glDraw methods. Before you call glDraw you must tell OpenGL where the vertex data is stored.
```pascal
// use array buffers to draw primitive
VertexBuffer.Bind;
@@ -130,30 +130,30 @@ try
// 3 float values, starting at offset 0
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, SizeOf(TVertex), Pointer(0));
// tell OpenGL where to find the texture coordinates
// 2 float values, starting at offset 12 (= 3 * sizeof(GLfloat))
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, SizeOf(TVertex), Pointer(12));
// tell OpenGL where to find the normal vector
// normal vector starting at offset 20 (= 5 * sozeof(GLfloat))
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, SizeOf(TVertex), Pointer(20));
// tell OpenGL to use our index array for indexed rendering
glEnableClientState(GL_INDEX_ARRAY);
glIndexPointer(GL_INT, 0, nil);
glDrawElements(GL_QUADS, iBuffer.DataCount, GL_UNSIGNED_INT, nil);
glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
finally
IndexBuffer.Unbind;
VertexBuffer.Unbind;
VertexBuffer.Unbind;
end;
```

@@ -163,7 +163,7 @@ FreeAndNil(VertexBuffer);
FreeAndNil(IndexBuffer);
```
## ii. TglcBitmap
TglcBitmap objects are used to manage and render textures. To simple load and render a texture you need to create two objects. TglcBitmapData to load a texture from file and convert it to the format you want to use in your texture and TglcBitmap2D to manage a OpenGL texture object, upload and download texture data and of course render your texture. Sounds simple, doesn't it?
TglcBitmap objects are used to manage and render textures. To simply load and render a texture you need to create two objects. TglcBitmapData to load a texture from file and convert it to the format you want to use in your texture and TglcBitmap2D to manage a OpenGL texture object, upload or download texture data and of course render your texture. Sounds simple, doesn't it?
```pascal
// create our texture object
var Texture: TglcBitmap2D;
@@ -219,7 +219,7 @@ finally
end;
```
## iv. TglcShader
What would an OpenGL application be without fancy shaders? TglcShader helps you to load and use shaders in your application. The simplest example of using the shader classes is to load a shader and then use it for rendering.
What would an OpenGL application be without fancy shaders? TglcShader helps you to load and use shaders in your application. The simplest example of using the shader classes is to load a shader and then use it for rendering.

Shader Code:
```glsl
@@ -243,7 +243,7 @@ void main(void)
Application Code:
```pascal
var Shader: TglcShaderProgram;
{ 'Log' is a callback to write log outputs to. So you can detect errors while compiling your shader. }
{ 'Log' is a callback to write log outputs to so you can detect errors while compiling your shader. }
Shader := TglcShaderProgram.Create(@Log);
Shader.LoadFromFile('./my-shader-file.glsl');
Shader.Compile;
@@ -252,9 +252,10 @@ Shader.Enable;
Shader.Disable;
```

As mentioned before this is a really simple example. TglcShaderProgram has some more usefull features, like settings uniform variables, binding attribute locations or completely build your shader step by step programmatically linking differend TglcShaderObjects into the TglcShaderProgram.
As mentioned before this is a really simple example. TglcShaderProgram has some more useful features, like setting uniform variables, binding attribute locations or completely build your shader step by step programmatically linking different TglcShaderObjects into the TglcShaderProgram.

## v. TglcVertexArrayObject
Vertex array objects are used to store all information about vertex buffer objects and index buffer objects. Instad of telling OpenGL all these information in every render loop, they are stored in a single objects and can be activated by simply binding the vertex array object.
Vertex array objects are used to store all information about vertex buffer objects and index buffer objects. Instad of telling OpenGL all these information in every render loop, they are stored in a single object and can be activated by simply binding the vertex array object.
```pascal
var
vbo: TglcArrayBuffer;
@@ -271,7 +272,7 @@ vao.Unbind;

# 4. Helper Classes
## i. TglcCamera
TglcCamera is a quite simple class. It wrapps the model view matrix into a usefull class and provide some methods to manipulate the model view matrix such as Tilt, Turn or Move.
TglcCamera is a quite simple class. It wraps the model view matrix into a useful class and provide some methods to manipulate the model view matrix such as Tilt, Turn or Move.
```pascal
var Camera: TglcCamera;

@@ -285,14 +286,14 @@ Camera.Activate; // activate camera
{ ... do normal rendering }
```
# ii. TglcLight and TglcMaterial
TglcLight and TglcMaterial are simple class wrappers of OpenGL light and material. Just to manage them in a object oriented way. TglcLight is specialized in 3 different classes:
* TglcLightGlobal - for global lightning
TglcLight and TglcMaterial are simple class wrappers of OpenGL light and material, just to manage them in an object oriented way. TglcLight is specialized in 3 different classes:
* TglcLightGlobal - for global lighting
* TglcLightPoint - for point lights
* TglcLightSpot - for spot lights
You can use the Bind and Unbind methods to activate and deactivate a light or material.

# 5. Helper Types
* glcTypes - Contains a list of all OpenGL enum used in this project.
* gluMatrix - Contains some usefull methods to work with matrices. gluMatrixEx is a extended version of gluMatrix using freepascal type helpers to add member methods to the matrix types.
* gluVector - Contains some usefull methods to work with vectors. gluVectorEx is a extended version of gluVector using freepascal type helpers to add member methods to the vector types.
* gluQuaternion - Contains some usefull methods to deal with quaternions.
* gluMatrix - Contains some useful methods to work with matrices. gluMatrixEx is an extended version of gluMatrix using FPC type helpers to add member methods to the matrix types.
* gluVector - Contains some useful methods to work with vectors. gluVectorEx is an extended version of gluVector using FPC type helpers to add member methods to the vector types.
* gluQuaternion - Contains some useful methods to deal with quaternions.

Loading…
Cancel
Save