Difference between revisions of "Getting Started"

From OpenGL.org
Jump to: navigation, search
m (Dictionaires are not perfect.)
m (Linux: Fixed typo)
(33 intermediate revisions by 12 users not shown)
Line 5: Line 5:
 
== FAQ ==
 
== FAQ ==
 
{{main|FAQ}}
 
{{main|FAQ}}
 
+
 
This Wiki maintains a FAQ page for OpenGL. There is an [http://www.opengl.org/resources/faq/ older FAQ] available, but information in it is more likely to be out of date.
 
This Wiki maintains a FAQ page for OpenGL. There is an [http://www.opengl.org/resources/faq/ older FAQ] available, but information in it is more likely to be out of date.
  
Line 29: Line 29:
  
 
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.
 
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. Developers
+
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.
 
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.
Line 41: Line 41:
 
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.
+
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 closed source driver may be available from the manufacturer.
  
 
=== Mac OS X ===
 
=== Mac OS X ===
Line 84: Line 84:
 
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.
 
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 [[Extension Loading Library|extension loading libraries]]; these make this process smooth. You are ''strongly'' advised to use one.
+
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.
  
 
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.
 
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.
Line 103: Line 103:
 
* [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)]: This one comes with a database containing information about what extensions are implemented by hardware other than your own.
 
* [http://www.realtech-vr.com/glview/index.html OpenGL Extension Viewer (Windows, Windows x64 and MacOS X)]: This one comes with a database containing information about what extensions are implemented by hardware other than your own.
* [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)]
  
 
== Tutorials and How To Guides ==
 
== Tutorials and How To Guides ==
 
User contributed tutorials and getting started guides
 
User contributed tutorials and getting started guides
  
* [[Tutorials]]: Tutorials hosted on this wiki
 
 
* OpenGL 3.0 and above:
 
* 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)]
 
** [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)]
 
** [http://www.arcsynthesis.org/gltut Learning Modern 3D Graphics Programming Through OpenGL].
 
** [http://www.arcsynthesis.org/gltut 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://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.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.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.marekknows.com/downloads.php5?vmk=shader MarekKnows ShaderEngine]: Video tutorials for game developers.  OpenGL Shaders, Math, Physics, Game Design and more.
 
* Pre-OpenGL 3.0:
 
* Pre-OpenGL 3.0:
** [http://www.opengl.org/documentation/red_book/ The OpenGL Programming Guide, also called the Red Book.] Covers OpenGL version 1.1.
+
** [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://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
Line 122: Line 128:
 
** [http://www.leolol.com/tutorials/graphics_tutorials.html LeoLoL], OpenGL Tutorials for Java (JOGL)
 
** [http://www.leolol.com/tutorials/graphics_tutorials.html LeoLoL], OpenGL Tutorials for Java (JOGL)
 
** [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], Non-free 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://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.levelbylevel.com/blog/opengl-c-and-glut-using-codeblocks-and-mingw-updated/ Setting up OpenGL, C++ & GLUT on Windows 7], Beginner tutorial
** Swiftless Tutorials [http://www.swiftless.com/opengltuts.html OpenGL 1 & 2],  
+
** [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.
  
Deferred Shading Tutorials
 
  
* [http://www.codinglabs.net/tutorial_def_rendering_1.aspx Deferred Rendering]
+
By Topic
* [http://www.gamerendering.com/category/rendering-methods/page/2/ Deferred Lighting]
+
* Deferred Shading Tutorials
 +
** [http://www.codinglabs.net/tutorial_def_rendering_1.aspx Deferred Rendering]
 +
** [http://www.gamerendering.com/category/rendering-methods/page/2/ Deferred Lighting]
 +
* 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 ==
 
== Development Tools ==
 +
* [http://developer.amd.com/tools/heterogeneous-computing/codexl/ AMD CodeXL] - After Graphic Remedy became a subsidiary of AMD in 2011, the new line of gDEBugger was released as a Visual Studio plugin and has since been re-released as a stand-alone application for Windows and Linux. It has since reached its end-of-life and is superseded by AMD CodeXL.
 
* [http://www.gremedy.com/ gDEBugger] - OpenGL, OpenGL ES and OpenCL Debugger, Profiler and Memory Analyzer For Windows, Linux, Mac OS X and iPhone
 
* [http://www.gremedy.com/ gDEBugger] - OpenGL, OpenGL ES and OpenCL Debugger, Profiler and Memory Analyzer For Windows, Linux, Mac OS X and iPhone
 +
{{warning|AMD's version of gDEBugger will not do any OpenCL kernel debugging without AMD hardware installed!}}
 +
* [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
  
 
== See Also ==
 
== 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.
 
* [[Related toolkits and APIs]]: For utilities that make using OpenGL easier.
 
* [[Language bindings]]
 
* [[Language bindings]]
Line 143: Line 161:
  
 
* '''Reference Documentation'''
 
* '''Reference Documentation'''
** [http://www.opengl.org/documentation/specs/ The OpenGL specification page]
 
 
** [http://www.opengl.org/documentation/glsl/ The OpenGL Shading Language specification page]
 
** [http://www.opengl.org/documentation/glsl/ The OpenGL Shading Language specification page]
 
** [http://www.opengl.org/registry/ The extension registry]
 
** [http://www.opengl.org/registry/ The extension registry]
Line 154: Line 171:
 
** [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.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
 
** [http://local.wasp.uwa.edu.au/~pbourke/ Paul Bourke] many demos and explanations, advanced
 
** [http://es.g0dsoft.com/?page_id=236 OpenGL Code Samples] modern OpenGL code samples and demos
 
** [http://es.g0dsoft.com/?page_id=236 OpenGL Code Samples] modern OpenGL code samples and demos
 +
** [http://oglplus.org/html/examples.html OGLplus Examples] OpenGL 3 and higher code examples
 
* '''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]
 
* '''Vendor SDKs'''
 
* '''Vendor SDKs'''
 
** [http://www.opengl.org/sdk/ OpenGL SDK projects and OpenGL man pages]
 
** [http://www.opengl.org/sdk/ OpenGL SDK projects and OpenGL man pages]
 
** [http://developer.nvidia.com nVidia's SDK, examples and many pdf]
 
** [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]
+
** [http://developer.amd.com/ AMD/ATI's examples and many pdf]
 
* '''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.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] A 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
  
  
 
[[Category:General OpenGL]]
 
[[Category:General OpenGL]]

Revision as of 20:51, 9 January 2014

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. There is an older FAQ available, but information in it is more likely to be out of date.

Downloading OpenGL

In all three major desktop platforms (Linux, MacOS X, 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.

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

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 closed source driver may be available from the manufacturer.

Mac OS X

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 Apple.com.

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 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 Mac OS X, see Platform specifics: Mac OS X.

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

  • AMD CodeXL - After Graphic Remedy became a subsidiary of AMD in 2011, the new line of gDEBugger was released as a Visual Studio plugin and has since been re-released as a stand-alone application for Windows and Linux. It has since reached its end-of-life and is superseded by AMD CodeXL.
  • gDEBugger - OpenGL, OpenGL ES and OpenCL Debugger, Profiler and Memory Analyzer For Windows, Linux, Mac OS X and iPhone
Warning: AMD's version of gDEBugger will not do any OpenCL kernel debugging without AMD hardware installed!

See Also

External Links