Difference between revisions of "Getting Started"

From OpenGL Wiki
Jump to: navigation, search
m (geocities.com is dead. Getting rid of link to GLinfo2.zip)
(Tutorials and How To Guides)
 
(127 intermediate revisions by 37 users not shown)
Line 1: Line 1:
So you want to take advantage of the power of the OpenGL API? If you are visiting this page because a game or software implements the OpenGL API, you need to install the appropriate graphic driver which enables usage of the functionality provided.
+
So you want to take advantage of the power of the OpenGL API? If you are visiting this page because a game or software uses the OpenGL API, you need to install the appropriate graphic driver which enables usage of the functionality provided.
  
 
To program using the OpenGL API, you need the driver and the development package (depends on platform and programming language). More platform-specific details are described in the sections below.
 
To program using the OpenGL API, you need the driver and the development package (depends on platform and programming language). More platform-specific details are described in the sections below.
  
__TOC__
+
== FAQ ==
 +
{{main|FAQ}}
 +
 +
This Wiki maintains a FAQ page for OpenGL.
  
== FAQ ==
+
== Downloading OpenGL ==
The Wiki FAQ is under the "General OpenGL" section. Here is a direct link<br>
 
http://www.opengl.org/wiki/FAQ<br>
 
<br>
 
The other opengl.org FAQ is located here<br>
 
http://www.opengl.org/resources/faq/<br>
 
  
== Windows ==
+
In all three major desktop platforms (Linux, macOS, and Windows), OpenGL more or less comes with the system. However, you ''will'' need to ensure that you have downloaded and installed a recent driver for your graphics hardware.
  
If you are running Windows 98/Me/NT/2000/XP/2003/Vista, the OpenGL library has already been installed on your system.
+
=== Windows ===
  
Remember that GL is a system component on Windows. DO NOT modify or copy OpenGL32.dll from one OS to another.
+
Appropriate Windows driver websites:
The filename is <code>OpenGL32.dll</code> and is either in <code>WINDOWS\SYSTEM</code>, <code>WINNT\SYSTEM32</code> or <code>WINDOWS\SYSTEM32</code>. This also means that you do not have to ship a copy of the library with your application since it will already be available on the system.
 
  
The standard Windows <code>OpenGL32.dll</code> library alone will not provide you with hardware acceleration for OpenGL. In order to get hardware acceleration, you will need to install the latest drivers for your graphics card. The second reason to install new drivers is to have the latest version of GL on your system (the max version supported by your GPU):
+
* [http://support.amd.com/en-us/download AMD/ATI]
* [http://support.amd.com/us/gpudownload/Pages/index.aspx AMD/ATI]
+
* [https://downloadcenter.intel.com/ Intel]
* [http://www.intel.com/support/graphics/detect.htm Intel]
 
 
* [http://www.nvidia.com/Download/index.aspx NVidia]
 
* [http://www.nvidia.com/Download/index.aspx NVidia]
* [http://www.s3graphics.com/en/drivers/index.aspx S3 Graphics]
 
  
 
Some sites also distribute beta versions of graphics drivers, which may give you access to bug fixes or new functionality before an official driver release from the manufacturer:
 
Some sites also distribute beta versions of graphics drivers, which may give you access to bug fixes or new functionality before an official driver release from the manufacturer:
 
* [http://www.guru3d.com Guru3D]
 
* [http://www.guru3d.com Guru3D]
  
GLU is also included in the system folder as <code>glu32.dll</code>
+
Without drivers, you will default to a software version of OpenGL 1.1 (on Win98, ME, and 2000), a Direct3D wrapper that supports OpenGL 1.1 (WinXP), or a Direct3D wrapper that supports OpenGL 1.1 (Windows Vista and Windows 7). None of these options are particularly fast, so installing drivers is always a good idea.
This is also a system component. Updated DLL should be placed in your program's folder. You can get a GLU's source code from [http://www.mesa3d.org MESA3D].
 
 
 
Other libraries like GLUT, freeGLUT, QT, etc are not part of the OS. These should be downloaded from the net. [http://www.opengl.org/resources/libraries/ GLUT and OpenGL Utility Libraries]
 
 
 
Windows 98, Me, 2000 support OpenGL version 1.1 as a software rasterizer implemented in <code>OpenGL32.dll</code>. There is no support for hardware acceleration therefore installing drivers is necessary. Windows XP supports OpenGL version 1.1 as a Direct3D wrapper in <code>OpenGL32.dll</code>. Since performance will be lousy, installing drivers is a good idea. On Windows 2003, you aren't suppose to use it as a desktop machine, but it is similar to Win 2000/XP. Windows Vista supports OpenGL version 1.4 as a Direct3D wrapper. ''Always'' install drivers. Once again, by installing the latest version of the video driver, you can get hw acceleration, you avoid the Direct3D wrapper, you get the maximum version of GL supported by your GPU.
 
  
=== 64 bits Windows versions ===
+
If your system does not contain a GPU, or the GPU vendor delivers graphics drivers providing OpenGL support that's so old as to be useless to you, you might want to consider installing the Mesa3D OpenGL library on your system. See this wiki link for details:
If you are running the 64 bit version of Windows Vista or perhaps you are running Windows XP x64, you might be wondering if there is a <code>OpenGL64.dll</code> file. The answer is no, there isn't. On both of these Operating Systems, <code>Windows\System32</code> contains all the 64 bit DLLs. It contains the <code>OpenGL32.dll</code> which is actually a 64 bit dll.
 
  
For 32 bit programs, Windows detects the exe as a 32 bit program and instead of using System32 files, it uses Windows\SysWOW64 which actually contains the 32 bit DLLs. WOW means '''W'''indows '''O'''n '''W'''indows which is a backwards-compatibility layer.
+
* [[Platform specifics: Windows#Installing Mesa3D on Windows|Installing Mesa3D on Windows]]
  
To find your Windows' System32 directory, go to: Start, Run... and type in <code>%WINDIR%\System32</code>. The system will redirect you to the default System32 directory automatically; this is also true for the 32 bits versions of Windows.
+
=== Linux ===
  
== Linux ==
+
Graphics on Linux is almost exclusively implemented using the X windows system. Supporting OpenGL on Linux involves using GLX extensions to the X Server. There is a standard Application Binary Interface defined for OpenGL on Linux that gives application compatibility for OpenGL for a range of drivers. In addition the Direct Rendering Infrastructure (DRI) is a driver framework that allows drivers to be written and interoperate within a standard framework to easily support hardware acceleration, the DRI is included in of XFree86 4.0 but may need a card specific driver to be configured after installation.
 
+
These days, XFree86 has been rejected in favor of XOrg due to the change in the license of XFree86, so many developers left Xfree86 and joined the XOrg group. Popular Linux distros come with XOrg now.
Graphics on Linux is almost exclusively implemented using the X windows system. Supporting OpenGL on Linux involves using GLX extensions to the X Server. There is a standard Application Binary Interface defined for OpenGL on Linux that gives application compatability for OpenGL for a range of drivers. In addition the Direct Rendering Infrastucture (DRI) is a driver framework that allows drivers to be written and interoperate within a standard framework to easily support hardware acceleration, the DRI is included in of XFree86 4.0 but may need a card specific driver to be configured after installation.
 
These days, XFree86 has been rejected in favor of XOrg due to the change in the license of XFree86, so many developers left Xfree86 and joined the XOrg group. Popular Linux distros come with XOrg now. Developers
 
  
 
Vendors have different approaches to drivers on Linux, some support Open Source efforts using the DRI, and others support closed source frameworks but all methods support the standard ABI that will allow correctly written OpenGL applications to run on Linux.
 
Vendors have different approaches to drivers on Linux, some support Open Source efforts using the DRI, and others support closed source frameworks but all methods support the standard ABI that will allow correctly written OpenGL applications to run on Linux.
  
* [http://support.amd.com/us/gpudownload/Pages/index.aspx AMD/ATI]
+
* [http://support.amd.com/en-us/download/linux AMD/ATI]
* [http://intellinuxgraphics.org/ Intel]
+
* [https://01.org/linuxgraphics Intel]
 
* [http://www.nvidia.com/object/unix.html Nvidia]
 
* [http://www.nvidia.com/object/unix.html Nvidia]
* [http://www.s3graphics.com/en/drivers/index.aspx S3 Graphics]
 
 
* [http://www.faqs.org/docs/Linux-mini/Nvidia-OpenGL-Configuration.html Nvidia HOWTO (old)]
 
* [http://www.faqs.org/docs/Linux-mini/Nvidia-OpenGL-Configuration.html Nvidia HOWTO (old)]
  
 
For more information on developing OpenGL applications on Linux, see [[Platform specifics: Linux]]
 
For more information on developing OpenGL applications on Linux, see [[Platform specifics: Linux]]
  
Linux comes with Mesa libraries, which implements the OpenGL API as a software rasterizer. Most Linux distros don't come with hardware acceleration. Some Linux distributions may include support for hardware acceleration. Also, some GPUs have Open Source drivers developed by the community even though a close source driver may be available from the manufacturer.
+
=== macOS ===
  
== Mac OS X ==
+
Unlike other platforms, where the Operating System and OpenGL implementations are often updated separately, OpenGL updates are included as part of macOS system updates. To obtain the latest OpenGL on macOS, users should upgrade to the latest OS release, which can be found at [https://www.apple.com/macos/ Apple.com].
All versions of Mac OS X ship with OpenGL runtime libraries pre-installed. Users who want to run OpenGL applications do not need to install or configure anything.
 
  
Unlike other platforms, where the Operating System and OpenGL implementations are often updated separately, OpenGL updates are included as part of Mac OS X system updates. To obtain the latest OpenGL on Mac OS X, users should upgrade to the latest OS release, which can be found at [http://www.apple.com/macosx/ Apple.com].
+
For developers, a default installation of macOS does not include any OpenGL headers, nor does it include other necessary development tools.  These are installed by a separate developer tools package called Xcode. This installer includes the OpenGL headers, compilers (gcc), debuggers (gdb), Apple's Xcode IDE, and a number of performance tools useful for OpenGL application development.
  
For developers, a default installation of Mac OS X does not include any OpenGL headers, nor does it include other necessary development tools. These are installed by a separate developer tools package called X Code. This installer includes the OpenGL headers, compilers (gcc), debuggers (gdb), Apple's Xcode IDE, and a number of performance tools useful for OpenGL application development.
+
* [http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_intro/opengl_intro.html OpenGL Information]
 +
* [http://developer.apple.com/technology/xcode.html Download Xcode]
  
* [http://developer.apple.com/opengl OpenGL Information]
+
For more information on developing OpenGL applications on macOS, see [[Platform specifics: macOS]].
* [http://developer.apple.com/technology/xcode.html Download X Code]
 
  
For more information on developing OpenGL applications on Mac OS X, see [[Platform specifics: Mac OS X]].
+
== Writing an OpenGL Application ==
  
== OpenGL 2.0+ and extensions ==
+
The first step is to pick your language. Bindings for OpenGL exist in many languages, from C# and Java to Python and Lua. Some languages have multiple sets of OpenGL bindings, none of them being official. All of them are ultimately based on the C/C++ bindings.
If you will be programming for Windows, typically compilers comes with a standard OpenGL 1.1 <code>.h</code> and <code>.lib</code>.<br>
 
<b>Microsoft will never update gl.h and opengl32.lib</b> that comes with their compiler. It hasn't been updated since 1995. Basically, the solution is to use glext.h and wglext.h (wglext.h is for Windows only) which define all the GL 1.2, 1.3, 1.4, 1.5, 2.0, 2.1 and above tokens and functions. Keep reading.<br>
 
Also, for other compilers for Windows, the same applies : gl.h and opengl32.a is limited to GL 1.1.<br>
 
For Linux and others, you might want to borrow the same idea (getting function pointers for the GL functions)<br>
 
To access higher OpenGL functions, you would have to get the function pointers.<br>
 
For example, in C or C++, this is what you would do<br>
 
<b>PS : The info here applies also to GL 3.0</b><br>
 
  
Download <code>glext.h</code> and <code>wglext.h</code> from [http://www.opengl.org/registry/ The Extensions Registry]
+
If you are not using C/C++, you must download and install a package or library for your chosen language that includes the OpenGL bindings. Some come pre-installed, but others have separate downloads.
  
Put it in your compiler's GL folder.
+
If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you're building a 64-bit executable. The "32" part is meaningless). Visual Studio, and most Windows compilers, come with this library.
  
<pre>
+
On Linux, you need to link to libGL. This is done with a command-line parameter of "-lGL".
include <GL/gl.h>
 
include <GL/glext.h>
 
include <GL/wglext.h>
 
  
extern PFNGLACTIVETEXTUREPROC glActiveTexture;  //Put this in a .h so that you can include the header in all your other .cpp
+
=== Initialization ===
PFNGLACTIVETEXTUREPROC glActiveTexture;    //Declare your function pointer in a .cpp file
 
</pre>
 
  
Once you create a GL context, you can use wglGetProcAddress to get a pointer to the function.
+
Before you can actually use OpenGL in a program, you must first initialize it. Because OpenGL is platform-independent, there is not a standard way to initialize OpenGL; each platform handles it differently. Non-C/C++ language bindings can also handle these differently.
  
glActiveTexture = (PFNGLACTIVETEXTUREPROC) wglGetProcAddress("glActiveTexture");
+
There are two phases of OpenGL initialization. The first phase is the creation of an [[OpenGL Context]]; the second phase is to load all of the necessary functions to use OpenGL. Some non-C/C++ language bindings merge these into one.
  
This would be tedious if you had to do this for all the functions and it's is even more work if you want to detect a certain OpenGL API version, then load all the core functions. Then, detect if a certain extension is present, then load all the functions.
+
==== OpenGL Context Creation ====
  
There exists a few libraries out there that will get the function pointers for you. All you have to do is create an OpenGL rendering context and call the library's init function. The recent version of GLee doesn't require a call to its init function.
+
An OpenGL context represents all of OpenGL. Creating one is very platform-specific, as well as language-binding specific.
  
Examples are :
+
If you are using the C/C++ language binding for OpenGL, then you are strongly advised to use a [[Related_toolkits_and_APIs#Context/Window_Toolkits|window toolkit]] for managing this task. These libraries create a window, attach an OpenGL context to this window, and manage basic input for that window. Once you are comfortable with OpenGL, you can then start learning how to [[Creating an OpenGL Context|do this manually]].
*[http://glew.sourceforge.net GLEW - The GL Extension Wrangler Library]
 
*[http://elf-stone.com/glee.php GLEE - GL Easy Extension library]
 
  
GLEW is used like this :<br>
+
Most non-C/C++ language bindings will provide you with a language-specific mechanism for creating a context.
Step 1. Just before including gl.h, include glew.h<br>
 
Step 2. Just after creating your GL context and making it current, call
 
  
  GLenum err=glewInit();
+
==== Getting Functions ====
  if(err!=GLEW_OK)
 
  {
 
  //problem: glewInit failed, something is seriously wrong
 
  sprintf(ErrorMessage, "Error: %s\n", glewGetErrorString(err));
 
  return -1;
 
  }
 
  
NEW : For GL 3.0, a new header file has been released as mentioned here<br>
+
If you are using a non-C/C++ language binding, then the maintainer of that binding will already handle this as part of context creation. If you are using C/C++, read on.
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=256858#Post256858<br>
 
<br>
 
http://www.opengl.org/registry/api/gl3.h<br>
 
It includes all the new tokens and functions and the old stuff has been removed.
 
  
== OpenGL 3.0 and Above ==
+
In order to use OpenGL, you must get OpenGL API functions. For most libraries you are familiar with, you simply #include a header file, make sure a library is linked into your project or makefile, and it all works. OpenGL doesn't work that way.
OpenGL 3.0 adds many features to the core of OpenGL. It also brings with it a deprecation model that previous versions of OpenGL did not have. Before OpenGL 3.0, anything that became core had to remain in the specification permanently. The deprecation model allows OpenGL versions to announce that certain features may be removed from the core in later versions.
 
  
To support backwards compatibility, that is, to not break existing programs, a new context creation model was introduced. The old context creation model can ''only'' create OpenGL versions 2.1 or lower. Thus, the only way to use 3.0 contexts is to create them with the new API.
+
For reasons that are ultimately irrelevant to this discussion, you must manually load functions via a platform-specific API call. This boilerplate work is done with various [[OpenGL Loading Library|OpenGL loading libraries]]; these make this process smooth. You are ''strongly'' advised to use one.
  
Part of this new API is a specification of exactly what version of OpenGL you want. So if you ask for a GL 3.1 context, you are telling the system that you expect that any entrypoints version 3.1 removed from earlier versions will not be available, and that any entrypoints 3.1 added to new versions will be available. The new API can fail if the implementation simply does not implement that version of OpenGL.
+
If you want to do it manually however, there is a [[Load OpenGL Functions|guide as to how to load functions manually]]. You still should use an extension loader.
  
See also the page [[OpenGL 3.0 and beyond, creating a context]] for instructions.
+
== Using OpenGL ==
  
=== OpenGL 3.2 ===
+
OpenGL is a rendering library. What OpenGL does not do is retain information about an "object". All OpenGL sees is a ball of triangles and a bag of state with which to render them. It does not remember that you drew a line in one location and a sphere in another.
==== API & GLSL specifications ====
 
* [http://www.opengl.org/registry/doc/glspec32.core.20090803.pdf OpenGL 3.2 Core Profile Specification]
 
* [http://www.opengl.org/registry/doc/glspec32.compatibility.20090803.pdf OpenGL 3.2 Compatibility Profile Specification]
 
* [http://www.opengl.org/registry/doc/GLSLangSpec.1.50.09.pdf OpenGL Shading Language 1.50 Specification]
 
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL & GLSL Quick Reference Card]
 
* [http://www.opengl.org/sdk/ OpenGL SDK]
 
  
== How to make your first OpenGL Program ==
+
Because of that, the general way to use OpenGL is to draw everything you need to draw, then show this image with a platform-dependent buffer swapping command. If you need to update the image, you draw everything again, even if you only need to update part of the image. If you want to animate objects moving on the screen, you need a loop that constantly clears and redraws the screen.
The first thing to do is chose a programming language. It could be C, C++, C++ Managed, Visual Basic, Visual Basic .NET, Pascal, Perl, Java, Ada, x86 assembly, etc.
 
  
The second thing is to chose a compiler. It could be MS Visual C++, Code::Blocks, Delphi, Masm, etc. Remember that OpenGL is an API, so as long as you have the language bindings for your compiler, you can do OpenGL programming.
+
There are techniques for only updating a portion of the screen. And you can use OpenGL with these techniques. But OpenGL itself doesn't do it internally; ''you'' must remember where you drew everything. You must figure out what needs updating and clear only that part of the screen. And so forth.
  
Typically, a compiler comes with the binding files. For example, if you have a C++ compiler, it will come with <code>gl.h</code> and <code>opengl32.lib</code>. It may even come with <code>glu.h</code> and <code>glu32.lib</code>, <code>glut.h</code> and <code>glut32.lib</code>.
+
There are many [[#Tutorials_and_How_To_Guides|tutorials and other materials]] available for learning how to use OpenGL, both on this wiki and online.
 
 
If you don't have your binding files, you will need to figure out where to download them from. Microsoft releases their Windows Platform SDK which contains these files and most likely you don't need it because your compiler came with the files.
 
 
 
You might want to use SDL, GLUT, freeGLUT, or some other wrapper that takes care of creating a GL window for you and destroying for you. It makes it easier for someone who just wants to learn the OpenGL API syntax.
 
 
 
Assuming you know how to program in your language of choice, now all you need is to learn OpenGL. There are many online tutorials. Just search for <code>opengl+tutorial</code> in your favorite search engine.
 
  
 
== OpenGL Viewers==
 
== OpenGL Viewers==
Line 157: Line 102:
  
 
* [http://www.ozone3d.net/gpu_caps_viewer/ GPU Caps Viewer (Windows XP, Vista 32)]
 
* [http://www.ozone3d.net/gpu_caps_viewer/ GPU Caps Viewer (Windows XP, Vista 32)]
* [http://www.realtech-vr.com/glview/index.html OpenGL Extension Viewer (Windows, Windows x64 and MacOS X)]
+
* [http://realtech-vr.com/admin/glview OpenGL Extension Viewer (Windows, Windows x64 and macOS)]: This one comes with a database containing information about what extensions are implemented by hardware other than your own.
* [http://www.glbenchmark.com/index.jsp OpenGL ES benchmark tool (Linux, Symbian, Windows Mobile)]
+
* [http://www.saschawillems.de/?page_id=771 OpenGL hardware capability viewer (Windows, Linux, macOS)]
* [http://www.devbump.com/story.php?title=Fur_Rendering_Benchmark_-_A_Small_and_Handy_OpenGL_Utility Fur rendering benchmark (Windows)]
+
* [http://www.ozone3d.net/benchmarks/fur/ FurMark benchmarking application (Windows)]
* [http://www.futuremark.com/download/ Futuremark's GL ES benchmark]
 
  
== External Links ==
+
== Tutorials and How To Guides ==
* '''Tutorials'''
+
User contributed tutorials and getting started guides
** [http://nehe.gamedev.net NeHe], OpenGL Tutorials
+
 
 +
* OpenGL 3.0 and above:
 +
<!-- ** [http://www.siteduzero.com/tutoriel-3-421558-developpez-vos-jeux-video-3d-avec-opengl-3-1.html Develop with OpenGL 3.1 from scratch (Français)] -->
 +
** [https://bitbucket.org/alfonse/gltut/wiki/Home Learning Modern 3D Graphics Programming Through OpenGL].
 +
** [http://ogldev.atspace.co.uk/ OpenGL Step by Step] (using C++, FreeGLUT and GLEW)
 +
** [http://openglbook.com/ OpenGLBook.com] Free online OpenGL 4.0 book (OpenGL 3.3 code provided wherever possible) using freeglut and GLEW
 +
** [http://www.spieleprogrammierung.net/ Spiele Programmierung Windows OpenGL 3 Tutorials And Articles], Beginner to Advanced in German
 +
** [http://www.swiftless.com/opengltuts/opengl4tuts.html Swiftless OpenGL 4 Tutorials]
 +
** [http://www.opengl-tutorial.org opengl-tutorial.org] OpenGL 3.3 and later Tutorials
 +
*** [http://www.opengl-tutorial.org/beginners-tutorials/ Basics]
 +
*** [http://www.opengl-tutorial.org/intermediate-tutorials/ Intermediate]
 +
** [http://tomdalling.com/blog/category/modern-opengl/ Modern OpenGL Tom Dalling]
 +
** [http://github.prideout.net/modern-opengl-prezo/ Modern OpenGL 2012 (PDF file)] by The Little Grashopper
 +
** [http://www.learnopengl.com www.learnopengl.com]: Easy-to-understand modern OpenGL tutorials aimed at beginners.
 +
** [http://opengl-trainer.com/podcast.html OpenGL Podcast (www.OpenGL2GO.net)]: A Podcast on OpenGL, OpenGL ES, WebGL and VULKAN - From beginners to advanced Users.
 +
** [https://www.youtube.com/watch?v=W3gAzLwfIP0&index=1&list=PLlrATfBNZ98foTJPJ_Ev03o2oq3-GGOS2 TheChernoProject (Youtube)]: High Quality video series for learning modern OpenGL
 +
** [https://open.gl/introduction Open.gl/introduction]: Learn OpenGL basics
 +
 
 +
* Pre-OpenGL 3.0:
 +
** [http://www.glprogramming.com/red/ The OpenGL Programming Guide, also called the Red Book] Covers OpenGL version 1.1.
 +
** [http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-1:-The-Graphics-Pipeline.html DurianSoftware.com], Intro to Modern OpenGL ([http://www.fevrierdorian.com/blog/post/2010/10/04/Une-introduction-à-l-OpenGL-Moderne-Chapitre-1%3A-Le-Pipeline-Graphique en français])
 
** [http://www.xmission.com/~nate/opengl.html GLUT], Tutorials
 
** [http://www.xmission.com/~nate/opengl.html GLUT], Tutorials
** [http://www.delphi3d.net Delphi3D.net], Delphi programming and OpenGL
 
 
** [http://www.lighthouse3d.com lighthouse3d.com], GL 2.0, GLSL, tutorials
 
** [http://www.lighthouse3d.com lighthouse3d.com], GL 2.0, GLSL, tutorials
** [http://www.marek-knows.com marek-knows.com], Game Engine development video tutorials, OpenGL, Physics, Math, C++, 3D modeling etc
+
** [http://www.MarekKnows.com MarekKnows.com], Game development video tutorials, OpenGL, shaders, physics, math, C++, 3D modeling, network, audio etc
 +
** [http://nehe.gamedev.net NeHe], OpenGL Tutorials
 +
** [http://www.levelbylevel.com/blog/opengl-c-and-glut-using-codeblocks-and-mingw-updated/ Setting up OpenGL, C++ & GLUT on Windows 7], Beginner tutorial
 +
** [http://www.songho.ca/opengl/index.html SongHo OpenGL tutorials]
 +
** Swiftless Tutorials [http://www.swiftless.com/opengltuts.html OpenGL 1 & 2],
 +
** [http://lazyfoo.net/tutorials/OpenGL/index.php Lazy Foo's OpenGL Tutorial], Covers OpenGL 2D in both OpenGL 2.1 and modern OpenGL
 +
* [[Code Resources]]: These are small snippets of code from the web that have been useful in the past. Most of them use deprecated functionality.
 +
 
 +
 
 +
By Topic
 +
* Shadow Mapping
 +
** [http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/ opengl-tutorial.org, Tutorial 16 : Shadow mapping] PCF, shadow-acne/peter-panning, stratisfied sampling. GL3.3.
 +
** [http://www.paulsprojects.net/tutorials/smt/smt.html paulsprojects.net] GL1.5.
 +
** [http://fabiensanglard.net/shadowmapping/index.php ShadowMapping with GLSL] shadow-acne, resolution, backfaces, border-issues. GL2+
 +
 
 +
== Development Tools ==
 +
* [https://renderdoc.org/ RenderDoc] - free, stand-alone graphics debugger. Supports only the OpenGL 3.2+ Core Profile. Works on both Windows and Linux.
 +
* [https://developer.nvidia.com/nvidia-nsight-visual-studio-edition Nsight Visual Studio Edition] - Nsight 3.0 support OpenGL 4.2 Debugging and Profiling, along with Shader Debugging and Pixel History
 +
* [http://deleaker.com/ Deleaker] - Deleaker for Visual Studio finds OpenGL leaks
 +
 
 +
== See Also ==
 +
 
 +
* [[OpenGL Reference]]: All of the OpenGL {{current version}} functions and what they do.
 +
* [[Related toolkits and APIs]]: For utilities that make using OpenGL easier.
 +
* [[Language bindings]]
 +
 
 +
== External Links ==
 +
 
 +
* '''Reference Documentation'''
 +
** [https://www.khronos.org/registry/OpenGL/index_gl.php The Khronos OpenGL Registry]
 
* '''Implementations'''
 
* '''Implementations'''
 
** [http://www.mesa3d.org The Mesa 3D Graphics Library], a software renderer based on the OpenGL API.
 
** [http://www.mesa3d.org The Mesa 3D Graphics Library], a software renderer based on the OpenGL API.
 
* '''Engines'''
 
* '''Engines'''
 
** [http://www.ogre3d.org Ogre 3D engine]
 
** [http://www.ogre3d.org Ogre 3D engine]
** [http://www.geocities.com/SiliconValley/Bay/6525 3DS loader, keyframes]
+
** [http://visualizationlibrary.org Visualization Library]
 
* '''Demos'''
 
* '''Demos'''
 
** [http://www.sulaco.co.za/ Delphi OpenGL Demos]
 
** [http://www.sulaco.co.za/ Delphi OpenGL Demos]
 +
** [http://www.g-truc.net G-Truc Creation]: [http://www.g-truc.net/project-0026.html OpenGL 2.1 - 4.1 Code samples]
 
** [http://www.humus.name/ Humus.name] many demos, advanced
 
** [http://www.humus.name/ Humus.name] many demos, advanced
** [http://www.flipcode.com Flipcode] many demos
 
** [http://local.wasp.uwa.edu.au/~pbourke/ Paul Bourke] many demos and explanations, advanced
 
 
* '''Theory and General Graphics Programming'''
 
* '''Theory and General Graphics Programming'''
** [http://www.magic-software.com Magic Software] algorithms, intersection test
 
 
** [http://freespace.virgin.net/hugo.elias/graphics/x_posure.htm Light Exposure Theory]
 
** [http://freespace.virgin.net/hugo.elias/graphics/x_posure.htm Light Exposure Theory]
** [http://scriptionary.com/ Scriptionary.com] Graphics Programming related both OpenGL and Direct3D
+
* '''Vendor SDKs'''
* '''Image Loader'''
+
** [http://www.opengl.org/sdk/ OpenGL SDK projects and OpenGL man pages]
** [http://openil.sourceforge.net http://openil.sourceforge.net], DevIL, formally called OpenIL, Image Library, supports many many formats
+
** [http://developer.nvidia.com nVidia's SDK, examples and many pdf]
** [http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL] SDL and GL
+
** [http://developer.amd.com/ AMD/ATI's examples and many pdf]
** [http://lonesock.net/soil.html http://lonesock.net/soil.html] SOIL, Simple OpenGL Image Library
 
** GLaux, do not use GLaux. It is 15 years old and considered deprecated
 
* '''Sound Loader'''
 
** [http://connect.creativelabs.com/openal/default.aspx http://connect.creativelabs.com/openal/default.aspx], OpenAL, Audio Library, sort of like OpenGL, but for audio
 
** [http://un4seen.com http://un4seen.com] BASS audio library
 
** [http://www.fmod.org http://www.fmod.org] FMOD audio librray
 
* '''Language Bindings'''
 
** [http://kenai.com/projects/jogl JOGL] Java
 
** [http://graphcomp.com/opengl/ POGL] Perl
 
 
* '''Other'''
 
* '''Other'''
 
** [http://www.3dcafe.com/ 3D models]
 
** [http://www.3dcafe.com/ 3D models]
 
** [http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/ http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/]
 
** [http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/ http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/]
** [http://www.opengl.org/sdk/tools/ShaderDesigner/ http://www.opengl.org/sdk/tools/ShaderDesigner/]
 
** [http://lumina.sourceforge.net/Tutorials/Armature.html http://lumina.sourceforge.net/Tutorials/Armature.html]
 
 
** [http://www.opencsg.org http://www.opencsg.org], Constructive Solid Geometry, boolean operations with geometry
 
** [http://www.opencsg.org http://www.opencsg.org], Constructive Solid Geometry, boolean operations with geometry
** [http://www.gamedev.net/community/forums/showfaq.asp?forum_id=25#q11a http://www.gamedev.net/community/forums/showfaq.asp?forum_id=25#q11a], The Gamedev FAQ
+
** [http://www.gamedev.net/forum/25-opengl/ GameDev.net], The Gamedev OpenGL Forums
** [http://gpwiki.org http://gpwiki.org] Another Wiki about Game Programming, also has GL code snippets and other APIs
+
** [http://gpwiki.org http://gpwiki.org] A Wiki about Game Programming, also has GL code snippets and other APIs
 
 
== Documentation ==
 
* [http://www.opengl.org/documentation/specs/ The GL spec page]
 
* [http://www.opengl.org/documentation/glsl/ The GLSL spec page]
 
* [http://www.opengl.org/registry/ The extension registry]
 
* [http://graphcomp.com/opengl/apis.html OpenGL Quick Reference]
 
* [[Getting started/XML Toolchain and Man Pages|XML Toolchain and Man Pages]]
 
* [[Getting started/Viewing XHTML and MathML|Viewing XHTML and MathML]]
 
  
== SDK ==
 
* [http://www.opengl.org/sdk/ OpenGL SDK projects and OpenGL man pages]
 
* [http://developer.nvidia.com nVidia's SDK, examples and many pdf]
 
* [http://ati.amd.com/developer/index.html AMD/ATI's examples and many pdf]
 
  
 
[[Category:General OpenGL]]
 
[[Category:General OpenGL]]

Latest revision as of 00:49, 4 July 2019

So you want to take advantage of the power of the OpenGL API? If you are visiting this page because a game or software uses the OpenGL API, you need to install the appropriate graphic driver which enables usage of the functionality provided.

To program using the OpenGL API, you need the driver and the development package (depends on platform and programming language). More platform-specific details are described in the sections below.

FAQ

This Wiki maintains a FAQ page for OpenGL.

Downloading OpenGL

In all three major desktop platforms (Linux, macOS, and Windows), OpenGL more or less comes with the system. However, you will need to ensure that you have downloaded and installed a recent driver for your graphics hardware.

Windows

Appropriate Windows driver websites:

Some sites also distribute beta versions of graphics drivers, which may give you access to bug fixes or new functionality before an official driver release from the manufacturer:

Without drivers, you will default to a software version of OpenGL 1.1 (on Win98, ME, and 2000), a Direct3D wrapper that supports OpenGL 1.1 (WinXP), or a Direct3D wrapper that supports OpenGL 1.1 (Windows Vista and Windows 7). None of these options are particularly fast, so installing drivers is always a good idea.

If your system does not contain a GPU, or the GPU vendor delivers graphics drivers providing OpenGL support that's so old as to be useless to you, you might want to consider installing the Mesa3D OpenGL library on your system. See this wiki link for details:

Linux

Graphics on Linux is almost exclusively implemented using the X windows system. Supporting OpenGL on Linux involves using GLX extensions to the X Server. There is a standard Application Binary Interface defined for OpenGL on Linux that gives application compatibility for OpenGL for a range of drivers. In addition the Direct Rendering Infrastructure (DRI) is a driver framework that allows drivers to be written and interoperate within a standard framework to easily support hardware acceleration, the DRI is included in of XFree86 4.0 but may need a card specific driver to be configured after installation. These days, XFree86 has been rejected in favor of XOrg due to the change in the license of XFree86, so many developers left Xfree86 and joined the XOrg group. Popular Linux distros come with XOrg now.

Vendors have different approaches to drivers on Linux, some support Open Source efforts using the DRI, and others support closed source frameworks but all methods support the standard ABI that will allow correctly written OpenGL applications to run on Linux.

For more information on developing OpenGL applications on Linux, see Platform specifics: Linux

macOS

Unlike other platforms, where the Operating System and OpenGL implementations are often updated separately, OpenGL updates are included as part of macOS system updates. To obtain the latest OpenGL on macOS, users should upgrade to the latest OS release, which can be found at Apple.com.

For developers, a default installation of macOS does not include any OpenGL headers, nor does it include other necessary development tools. These are installed by a separate developer tools package called Xcode. This installer includes the OpenGL headers, compilers (gcc), debuggers (gdb), Apple's Xcode IDE, and a number of performance tools useful for OpenGL application development.

For more information on developing OpenGL applications on macOS, see Platform specifics: macOS.

Writing an OpenGL Application

The first step is to pick your language. Bindings for OpenGL exist in many languages, from C# and Java to Python and Lua. Some languages have multiple sets of OpenGL bindings, none of them being official. All of them are ultimately based on the C/C++ bindings.

If you are not using C/C++, you must download and install a package or library for your chosen language that includes the OpenGL bindings. Some come pre-installed, but others have separate downloads.

If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you're building a 64-bit executable. The "32" part is meaningless). Visual Studio, and most Windows compilers, come with this library.

On Linux, you need to link to libGL. This is done with a command-line parameter of "-lGL".

Initialization

Before you can actually use OpenGL in a program, you must first initialize it. Because OpenGL is platform-independent, there is not a standard way to initialize OpenGL; each platform handles it differently. Non-C/C++ language bindings can also handle these differently.

There are two phases of OpenGL initialization. The first phase is the creation of an OpenGL Context; the second phase is to load all of the necessary functions to use OpenGL. Some non-C/C++ language bindings merge these into one.

OpenGL Context Creation

An OpenGL context represents all of OpenGL. Creating one is very platform-specific, as well as language-binding specific.

If you are using the C/C++ language binding for OpenGL, then you are strongly advised to use a window toolkit for managing this task. These libraries create a window, attach an OpenGL context to this window, and manage basic input for that window. Once you are comfortable with OpenGL, you can then start learning how to do this manually.

Most non-C/C++ language bindings will provide you with a language-specific mechanism for creating a context.

Getting Functions

If you are using a non-C/C++ language binding, then the maintainer of that binding will already handle this as part of context creation. If you are using C/C++, read on.

In order to use OpenGL, you must get OpenGL API functions. For most libraries you are familiar with, you simply #include a header file, make sure a library is linked into your project or makefile, and it all works. OpenGL doesn't work that way.

For reasons that are ultimately irrelevant to this discussion, you must manually load functions via a platform-specific API call. This boilerplate work is done with various OpenGL loading libraries; these make this process smooth. You are strongly advised to use one.

If you want to do it manually however, there is a guide as to how to load functions manually. You still should use an extension loader.

Using OpenGL

OpenGL is a rendering library. What OpenGL does not do is retain information about an "object". All OpenGL sees is a ball of triangles and a bag of state with which to render them. It does not remember that you drew a line in one location and a sphere in another.

Because of that, the general way to use OpenGL is to draw everything you need to draw, then show this image with a platform-dependent buffer swapping command. If you need to update the image, you draw everything again, even if you only need to update part of the image. If you want to animate objects moving on the screen, you need a loop that constantly clears and redraws the screen.

There are techniques for only updating a portion of the screen. And you can use OpenGL with these techniques. But OpenGL itself doesn't do it internally; you must remember where you drew everything. You must figure out what needs updating and clear only that part of the screen. And so forth.

There are many tutorials and other materials available for learning how to use OpenGL, both on this wiki and online.

OpenGL Viewers

These are programs that you install and run, and they give you information specific to the OpenGL API your system implements, like the version offered by your system, the vendor, the renderer, the extension list, supported viewport size, line size, point size, plus many other details. Some might include a benchmark. Some are standalone benchmarks.

Tutorials and How To Guides

User contributed tutorials and getting started guides


By Topic

Development Tools

  • RenderDoc - free, stand-alone graphics debugger. Supports only the OpenGL 3.2+ Core Profile. Works on both Windows and Linux.
  • Nsight Visual Studio Edition - Nsight 3.0 support OpenGL 4.2 Debugging and Profiling, along with Shader Debugging and Pixel History
  • Deleaker - Deleaker for Visual Studio finds OpenGL leaks

See Also

External Links