/ModernGL.jl

OpenGL 3+ bindings for Julia

Primary LanguageJuliaMIT LicenseMIT

Forked from the official repo, for use in B+. Mainly done to get ARB extensions, but also to improve the internal macros and GLENUM utility.

ModernGL

OpenGL bindings for OpenGL 3.0 through 4.6. As OpenGL 3.0 has a lot of overlaps with OpenGL 2.1, OpenGL 2.1 is partly supported as well.

The philosophy is to keep this library strictly a low-level wrapper, so you won't find any error handling (besides for the function loading itself) or abstractions in this package.

Debugging

You can rebuild ModernGL to include debug error checks:

ENV["MODERNGL_DEBUGGING"] = "true"; Pkg.build("ModernGL")
# or to get back the default behaviour:
ENV["MODERNGL_DEBUGGING"] = "false"; Pkg.build("ModernGL")

OpenGL constants are wrapped as enums, which allows you to print the name of a constant like this: GLENUM(x::GLenum).name This works pretty well, but keep in mind some constants actually have the same value, and only one name will be stored for each value. This leads to counterintuitive behavior in some cases, such as GLENUM(GL_SYNC_FLUSH_COMMANDS_BIT).name == :GL_TRUE. The behavior of GLENUM is manually overridden to return specific names for important constants, like GL_TRUE for 1 and GL_FALSE for 0. You can force other names using the macro ModernGL.@custom_glenum [value] [name].

Installation notes

There are no dependencies, besides the graphic driver. If you have any problems, you should consider updating the driver first.

An OpenGL context is needed for OpenGL, which is created with GLFW.jl.

Other OpenGL abstraction packages, which make it easier to get started with OpenGL, include:

  • GLAbstraction is a library, that offers Julian wrappers around often used OpenGL functions and types.

Known problems

There might be a few problems with older platforms and video cards, since it's not heavily tested on them.

Some more details

getProcAddress can be changed like this:

using ModernGL

function ModernGL.getprocaddress(name::ASCIIString)
	# for example change it to GLUT
	glutGetProcAddress(name)
end

If the OpenGL driver doesn't support any of the functions that you call, ModernGL should detect this and throw an error. Same happens, if you call a function before initializing an OpenGL context. This behaviour is not guaranteed though, as for example linux platforms always returns valid pointers, even if the function is not implemented by the driver. It seems, that there is actually no good way of testing if a function is supported on linux.

Credit

Credits go certainly to the OpenGL.jl (rennis250 && o-jasper) package, where I have all the OpenGL definitions from. Special thanks to rennis250 for all the support! :)

Also, I have to thank for the constructive discussion on Julia-Users, where I got a good solution for the function pointer loading (final solution was from vtjnash and got replaced by aaalexandrov's solution which doubled the speed).