Ooogles is a ultra-thin object oriented Delphi wrapper around OpenGL-ES 2.0 with near-zero impact on performance. It can also be used to create OpenGL applications for desktop platforms using the OpenGL-ES subset of OpenGL.
This wrapper is still pretty low-level. It is not a "rendering engine" or high-level framework, so you still need OpenGL knowledge.
The main goals of Ooogles are to make it easier and less error-prone to use OpenGL-ES, offering error reporting in DEBUG
builds and a better Code Insight experience in the Delphi IDE.
Ooogles has the following features:
TGLTexture
and TGLShader
, preventing these types of errors.GL_INVALID_ENUM
errors. This wrapper uses true Delphi enums instead, preventing most of these errors.DEBUG
mode, it will expose those errors through exceptions, and it will also log any warnings to the debug console.gl
class (which acts more like a namespace). For example, the OpenGL API glClear
is wrapped in the method gl.Clear
.DEBUG
conditional define, and assertions enabled (the default configuration for Debug builds), every OpenGL call is checked for errors, and an exception is raised when an error occurs, indicating the type of error and in which method it occurred. When DEBUG
is not defined, or assertions are disabled, all error checking code is removed from the build so it has zero impact on performance.DEBUG
mode with assertions enabled, warnings will be logged to the debug console if you forget to bind an object before you use it (or when a different object than the one you are using is currently bound).ExamplesCommon
directory.The wrapper does not provide higher-level features such as automatic OpenGL resource managment. You need to release OpenGL resources yourself when you no longer need them. Resources are usually created using a method called New
and released using a methods called Delete
. For example:
var
Texture: TGLTexture;
begin
Texture.New;
// Do something with texture
Texture.Delete;
end;
I may add automatic resource management in the future if and when Delphi gets support for record finalizers.
Also, the wrapper only supports OpenGL-ES version 2.0. It does not support the "old" version 1 fixed-function rendering pipeline. I may add support for version 3.0 and up once it is offered by Delphi becomes more mainstream.
This wrapper has no dependencies other than requiring the FastMath library. This library offers (among other things) very fast vector and matrix math calculations, which makes it ideal for use in high performance (OpenGL) applications.
To get started:
FM_COLUMN_MAJOR
conditional define to your project (for All configurations - All platforms). This enables column-major storage of matrices, which makes more sense for OpenGL applications.InitOoogles
. This is needed to emulate OpenGL-ES on OpenGL platforms. If your application uses multiple contexts, you must call InitOoogles once for each context (after making it current). Take a look at the Sample.Platform.*
units for examples of when to call this.Winapi.OpenGL
, iOSapi.OpenGLES
etc). To make it easier to use the correct OpenGL units, it is easiest if you include the 'OpenGL.inc' file in your uses clauses instead, as in:uses
{$INCLUDE 'OpenGL.inc'}
Neslib.Ooogles;
Just make sure you "use" at least one other unit after the include file.
The following is a list of the main classes (actually records) used in Ooogles, along with links to their documentation:
attribute
in a vertex shader.uniform
in a vertex or fragment shader.If you are fluent in OpenGL, the you may find the following table helpful to translate from a OpenGL API to an Ooogles method. It should all be pretty straightforward.
OpenGL | Ooogles |
---|---|
glActiveTexture | TGLTexture.BindToTextureUnit |
glAttachShader | TGLProgram.AttachShader |
glBindAttribLocation | TGLVertexAttrib.Bind |
glBindBuffer | TGLBuffer.Bind |
glBindFramebuffer | TGLFramebuffer.Bind |
glBindTexture | TGLTexture.Bind |
glBlendColor | gl.BlendColor |
glBlendEquation | gl.BlendEquation |
glBlendEquationSeparate | gl.BlendEquationSeparate |
glBlendFunc | gl.BlendFunc |
glBlendFuncSeparate | gl.BlendFuncSeparate |
glBufferData | TGLBuffer.Data |
glBufferSubData | TGLBuffer.SubData |
glCheckFramebufferStatus | TGLFramebuffer.Status |
glClear | gl.Clear |
glClearColor | gl.ClearColor |
glClearDepthf | gl.ClearDepth |
glClearStencil | gl.ClearStencil |
glColorMask | gl.ColorMask |
glCompileShader | TGLShader.Compile |
glCompressedTexImage2D | TGLTexture.UploadCompressed |
glCompressedTexSubImage2D | TGLTexture.SubUploadCompressed |
glCopyTexImage2D | TGLTexture.Copy |
glCopyTexSubImage2D | TGLTexture.SubCopy |
glCreateProgram | TGLProgram.New |
glCreateShader | TGLShader.New |
glCullFace | gl.CullFace |
glDeleteBuffers | TGLBuffer.Delete |
glDeleteFramebuffers | TGLFramebuffer.Delete |
glDeleteProgram | TGLProgram.Delete |
glDeleteRenderbuffers | TGLRenderbuffer.Delete |
glDeleteShader | TGLShader.Delete |
glDeleteTextures | TGLTexture.Delete |
glDepthFunc | gl.DepthFunc |
glDepthMask | gl.DepthMask |
glDepthRangef | gl.DepthRange |
glDetachShader | TGLProgram.DetachShader |
glDisable | gl.Disable |
glDisableVertexAttribArray | TGLVertexAttrib.Disable |
glDrawArrays | gl.DrawArrays |
glDrawElements | gl.DrawElements |
glEnable | gl.Enable |
glEnableVertexAttribArray | TGLVertexAttrib.Enable |
glFinish | gl.Finish |
glFlush | gl.Flush |
glFramebufferRenderbuffer | TGLFramebuffer.AttachRenderbuffer |
glFramebufferTexture2D | TGLFramebuffer.AttachTexture |
glFrontFace | gl.FrontFace |
glGenBuffers | TGLBuffer.New |
glGenFramebuffers | TGLFramebuffer.New |
glGenRenderbuffers | TGLRenderbuffer.New |
glGenTextures | TGLTexture.New |
glGenerateMipmap | TGLTexture.GenerateMipmap |
glGetBooleanv | various Get* methods |
glGetFloatv | various Get* methods |
glGetIntegerv | various Get* methods |
glGetActiveAttrib | TGLProgram.GetAttributeInfo |
glGetActiveUniform | TGLProgram.GetUniformInfo |
glGetAttachedShaders | TGLProgram.GetAttachedShaders |
glGetAttribLocation | TGLVertexAttrib.Init |
glGetBufferParameteriv | TGLBuffer.Get* |
glGetError | gl.GetError |
glGetFramebufferAttachmentParameteriv | TGLFramebuffer.Get* |
glGetProgramInfoLog | TGLProgram (in DEBUG mode) |
glGetProgramiv | TGLProgram.Get* |
glGetRenderbufferParameteriv | TGLRenderbuffer.Get* |
glGetShaderInfoLog | TGLShader (in DEBUG mode) |
glGetShaderSource | TGLShader.GetSource |
glGetShaderiv | TGLShader.Get* |
glGetString | gl.Get* |
glGetTexParameter* | TGLTexture.Get* |
glGetUniform | TGLUniform.GetValue |
glGetUniformLocation | TGLUniform.Init |
glGetVertexAttrib* | TGLVertexAttrib.Get* |
glGetVertexAttribPointerv | TGLVertexAttrib.GetOffset/GetData |
glHint | TGLTexture.MipmapHint |
glIsBuffer | not needed |
glIsEnabled | gl.IsEnabled |
glIsFramebuffer | not needed |
glIsProgram | not needed |
glIsRenderbuffer | not needed |
glIsShader | not needed |
glIsTexture | not needed |
glLineWidth | gl.LineWidth |
glLinkProgram | TGLProgram.Link |
glPixelStorei | gl.PixelStore |
glPolygonOffset | gl.PolygonOffset |
glReadPixels | TGLFramebuffer.ReadPixels |
glReleaseShaderCompiler | TGLShader.ReleaseCompiler |
glRenderbufferStorage | TGLRenderbuffer.Storage |
glSampleCoverage | gl.SampleCoverage |
glScissor | gl.Scissor |
glShaderSource | TGLShader.SetSource |
glStencilFunc | gl.StencilFunc |
glStencilFuncSeparate | gl.StencilFuncSeparate |
glStencilMask | gl.StencilMask |
glStencilMaskSeparate | gl.StencilMaskSeparate |
glStencilOp | gl.StencilOp |
glStencilOpSeparate | gl.StencilOpSeparate |
glTexImage2D | TGLTexture.Upload |
glTexParameter | TGLTexture.MinFilter/MagFilter/WrapS/WrapT |
glTexSubImage2D | TGLTexture.SubUpload |
glUniform* | TGLUniform.SetValue/SetValues |
glUseProgram | TGLProgram.Use |
glValidateProgram | TGLProgram.Validate |
glVertexAttrib* | TGLVertexAttrib.SetValue |
glVertexAttribPointer | TGLVertexAttrib.SetConfig/SetData |
glViewport | gl.Viewport |