Unexpected Results

From OpenGL Wiki
Jump to: navigation, search

This article explains some unexpected results and artifacts you can get when rendering stuff, and how to avoid them.

One thing that you should always do before trying anything else is to Check for OpenGL Errors.

General Causes

Undefined Behaviour

If you use OpenGL in a way that is not covered by the specification, there is no guarantee for any specific result. This can usually be avoided by checking for errors. Note that some implementations are less restrictive than the specification about what is accepted (notably NVIDIA implementations). Things might seem to work fine on some implementations, but they might not work on others.

Implementation Bugs

There might be a bug in the OpenGL implementation. This is however rare. Often people think they have discovered a bug when they in fact haven't. Make sure you follow the specification if you are going to send a bug report to the vendor.

It is (very) unlikely that two OpenGL implementations would have the same bug. If you get the same (unwanted) result on different implementations, it is probably not a bug.


Nothing is rendered at all

This means your window is filled by a single colour (often black). This can have several causes, not limited to those listed:

  • Your context isn't initialized correctly
  • You call glClear() immediately before swapping buffers
  • You don't swap buffers at all
  • Every fragment fails depth testing, perhaps since the depth buffer isn't set up correctly.
  • The objects you intend to render are not in view.

Colours appear wrong

This can be the result of passing the wrong format parameter to glTexImage*, often passing GL_RGBA instead of GL_BGRA. For more information, see Image Format and Pixel Transfer.

On Microsoft Windows, there is a setting for how many colours the monitor can display. Make sure this is set to display 32-bit colours.