Intel sponsors gamedev.net search:
The site is presently in a read-only mode while we perform some internal maintenance. Thank you for your patience.
Control Panel Register Bookmarks Who's Online Active Topics Stats FAQ Search
GameDev.Net Discussion Forums Frequently Asked Questions (for individual forums) Back to the Forums
Current Server Time - 1:06:44 AM
FAQ - OpenGL
Body

General Guidelines for posters



This forum is for discussion of OpenGL (hence the name). If your question is to do with the OpenGL API, GLUT or SDL then ask it here. Questions about graphics programming and algorithms which are not specific to OpenGL should go in the Graphics Programming and Theory forum.

Demonstrations of your own OpenGL programming, screenshots etc are also welcome here, particularly if you have something interesting to show off which you think others can learn from.

Don't ask questions which have been covered by this document, or which could have easily been answered by a quick search of google or by checking the relevant section of the red book or blue book. In other words, feel free to ask questions, but at least demonstrate that you tried to find the answer first.

Content



OpenGL Frequently asked Questions (and answers)




Why can't my frame rate go above 60/75/85 fps?


This is probably because "wait for vsync" is enabled in your graphics card settings. This causes your graphics card to wait for a sync signal from the monitor before flipping the buffers. To find out your true maximum frame rate, turn this feature off in your graphics card settings.


Can I do 2D in OpenGL?


Yes. Using an orthogonal projection. You can use glOrtho for this. A more detailed answer to the question was posted by Dwarf with Axe here.


How can I render text with OpenGL?


The fastest method is to use bitmap fonts. Typically you would create a greyscale texture which includes all of the letters on a black background, aligned in order of their ASCII codes. You'd then load the texture into your program as a 4 channel image (with each channel a duplicate of the first). Each letter requires texture coordinates, so you'd need to store these in a structure of some sort.

You can then render a text string by binding the font texture and setting a (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blend function (see glBlendFunc). The font's colour can then be set with glColor. Individual letters are then rendered as orthogonal quads, with texture coordinates corresponding to the current character. Since all letters use the same texture, all characters can be rendered in a single glBegin/glEnd pair if necessary. (For even more efficiency, you can use vertex arrays and render the characters with a single call to glDrawElements).



How can I do collision detection with OpenGL?


You have to write your own. OpenGL is a graphics library, it doesn't do collision detection. Neither does it do audio, wash dishes, unblock drains, or remove stubborn stains from carpets. As such, questions relating to collision detection should be asked in Math and Physics.


How can I program for OpenGL beyond version 1.1 in windows?


Although the current OpenGL version is 1.5 (as of 2004/03/29) , and this has been implemented by all major hardware manufacturers, Microsoft has only released OpenGL32.dll and OpenGl32.lib files corresponding to version OpenGL 1.1. In order to use newer core functions or any OpenGL extensions, you have to link the functions you want manually.

To do this, download the latest glext.h from the OpenGL registry which includes typedefs for all registered extension functions. After including glext.h in your project, you can then declare the functions you need using the typedefs provided, and obtain a pointer to them with wglGetProcAddress. Once linked you can then use the new functions as ordinary OpenGL commands.
  • Moving Beyond OpenGL 1.1 for Windows by Dave Astle gives a more detailed explanation and implementation details.

  • There are a number of libraries for automatically loading OpenGL extensions. These are listed in the resources section.



What is Z-fighting, and how can I avoid it?


Z fighting is a graphical artifact which occurs when two more overlapping faces share similar values in the Z buffer, causing the faces to flicker randomly as the camera moves.This can happen if your application is using a 16-bit Z buffer. The solution here to this is often to request a 24-bit Z-buffer in your pixel format descriptor, and to set the screen display depth to 32-bit.

However, you can't guarantee on support for 32-bit display modes (and thus 24-bit z-buffers) on all systems.A better solution is often to position your near and far clip planes differently. Because of the non-linear function used to generate Z values, values closest to the eye have far more precision than those farther away. Simply doubling the distance of the near clip plane will give you double the precision. You can also move the far clip plane inwards, however this is less likely to have such a dramatic effect.

How can I perform per-pixel shading operations?


On older (Geforce 1 onwards) nvidia cards, you can use NVIDIA's register combiners. The register combiners can be used to do bumpmapping and a lot of other per-pixel effects. However, reg coms lack flexibility, are fiddley to set up, and only work on NVIDIA hardware. ATI also has an extension geared towards performing per-pixel operations, however it suffers from the same problem as reg coms of being specific to one group of hardware and isnt much use on modern hardware (R300 onwards).


As the newer generation of hardware has appeared these methods have been replaced by a newer shader/program system. There are a few options avaible when considering which route to take, these being Nvidia's Cg, the low level assembler-type language (ARB_fragment_program) and the OpenGL Shading Language.


The ARB fragment program interface, while it will do the job, is all but dead and there are no plans to update it as the graphics cards move forward.




Cg is Nvidia's High level shading language, which will work on both NV and ATI hardware, however it suffers from a slight problem currently in that on non-NV hardware it produces ARB fragment program code from the Cg code, as such it suffers from the lack of updates to the ARB fragment program interface. On NV hardware this isnt such a problem as NV constantly release and update their own low level shader interface which Cg can take advantage of. Cg can also be used on NV pre-ARB fragment program hardware by setting up the register combiners for you.




The final soltion is the OpenGL Shading Language which has been taken up by 3DLabs, ATI and nVidia. The GLSL is the future as far as OpenGL shaders go, the interface is forward looking and resembles C/C++ code. Some tutorials and book chapters can be found below with the spec linked above in the 'links' section.


(orignal Answer by iNsAn1tY, updated by _the_phantom_).



How can I load .obj files into OpenGL?


Ranger_One has kindly provided code to show how to load this model type. It can be found here

How can I load 3DS files into OpenGL?


Genjix has started a series of posts on how todo it, it can be found here

Where can I find some OpenGL Shading Language Tutorials?


Noisecrime has supplied a list of locations people might find some usefull OpenGL Shading Language tutorials;

LightHouse GLSL Tutorial

ShaderTech (formally cgShader.org) 3 pages of GLSL articles, forum etc.

Clockwork Tutorials

Chapter 6 of the Orange Book

Chapter 3 of the Orange Book


Does the number of state changes matter?



Yes it does, the more you have the more work the driver and graphics card is having todo, however some state changes cost less than others, as such the type of state change tends to matter more as you shouldnt be doing redundant changes anyway.

What counts as changing a state?



Anything which effects the way OpenGL is currently configured is considered a state change, this includes setting a new drawing colour, binding a texture or performing a translation. All of these operations cause something to change somewhere in the OpenGL pipeline, ofcourse some are more expensive than others.

What are the most expensive state changes?



The order from most to least expensive is basically;

  • Binding a Shader

  • Binding a Texture

  • Updating a GLSL texture sampler uniform

  • VBO data pointers

  • Everything else



State changes which are client side are the cheapest you'll get.

Shader state changes require alot of configuration to be changed inside the GPU, thus why its lot of work. If the shader only has a vertex shader then its a bit cheaper to setup but still places them near the top.

When a texture is bound the GPU has to flush alot of caches and state again from an uncached state reading texture data from video ram.

GLSL texture samplers are a new one, the reason it is expensive to change/update these is because when you do so the driver has to perform a lookup to make sure the current sampler can be bound to the requested texture unit. The good news is that GLSL Program objects track the state of these uniforms and thus you can often set and forget the uniform values.

VBO data pointers can cost you a bit as the drivers very often do setup work, however as to when you take the hit depends on the driver, NV tend todo their work when you issue a gl*Pointer() function call and I'm not sure when ATI do theirs.

Where can I find an OpenGL GUI?


Forum regular JavaCoolDude has kindly donated his own GUI framework for poeple to use, the relivent thread on it can be found here

What is the state of OpenGL on Windows Vista?



Continue OpenGL support
> Important component of the Windows platform, particularly for high-end workstation applications
In-box hardware accelerated version of OpenGL
> Uses WGF 1.0 as common graphics pipeline
> Upgraded API support compared to XP
> OpenGL 1.4
Continue to support OpenGL ICDs
> Can be shipped by OEMs
> New ICDs required for LDDM

> Old XP ICDs work with XP driver model in Longhorn
Source


Quote:
...Currently, the implication of using the IHV-supplied OpenGL driver is that the Aeroglass desktop compositor will be switched off for the OpenGL application going through an OpenGL ICD. This means that the borders of the application window will be opaque instead of (potentially) transparently composited with underlying windows...

Quote:
...Other running apps are unaffected.


- Randi Rost, 3DLabs.

The information above was provided by msn12b and Krohm respectively.

All times are ET (US)

Moderators/Admin: Edit FAQ