# OpenGL How to make my game run on all graphics cards

## Recommended Posts

I've coded a small demo of a game I'm creating. And I gave it to some friends, so they could test it. The problem? Well, it only ran on one of them, and still, with some minor graphic glitches.

The question. What methods are there to make sure an OpenGL game runs in lots of different hardware, without having to buy all kinds of graphic cards to test.
It is very difficult to debug errors when they only happen in different hardware.

For example, I tested it in a very powerful pc, with an ATI HD 5800, and while it ran without errors, the characters won't appear, only their shadows and the terrain...

Another example, the game would crash on all Intel cards. After hours of testing, it seems that using display lists was the reason, why, I don't know, but removing the display list code, and leaving only the glBegin (stuff) glEnd commands worked.
Well, didn't work actually, but at least the game didn't crash, only showed a black screen. I use shaders for everything, but they are all very simple. I even tested with one that just output red color to gl_FragColor and still, nothing...
Still, that same pc is able to run HL2, so, why?

Some details that may help, the game is coded in Delphi, uses OpenGL, with shaders for everything (no fixed pipeline suport), and display lists for everything (terrain + characters).

Also all the GLSL shaders make heavy use of #define and #ifdef #endif, could this be a problem on some drivers?

All features can be turned off (shadows, post processing, etc), and I did turn it off on the Intels, and still, crash.
I turned the characters off, and crash. Only when I turned the terrain off too, it worked, but of course, then, there was nothing to render..

Anyone has ideas, how to find the problems?
How to debug this kind of problems in different hardware?
Any tips about Intel + GLSL/Display list problems?

[Edited by - Relfos on December 7, 2010 5:03:36 AM]

##### Share on other sites
Use only GL 1.1 features.

HL2 uses Direct3D. You can use that also instead of GL.
Intel drivers are quite bad. Even the D3D driver sucks. Intel is great for surfing the web.

##### Share on other sites
You can't make sure that it runs on all PCs, because some PCs out there (e.g. with OEM or MS drivers) don't even have OpenGL support.

That aside, you've taken a good first step: get it out to as many people as possible so that you cover a good baseline of hardware and OSs (and OS versions). The sooner you can do this, the sooner you'll start identifying any potential problems.

If your friends are willing to help out here, you can make small demo apps containing isolated portions of your main code, which can help with identifying specific areas that do or don't work.

A technique I've found very useful in the past is to code on a machine with an Intel graphics chip in. It sounds perverse and counter-intuitive, but my reasoning is that if it works on that, it will stand a better chance of working on anything else.

You could also give your friends (or ask them to download) a copy of glIntercept, then get them to send you the logs for a frame. This can help uncover a lot of other potential problems. If not, you can put a lot of glGetError calls throughout your code and write your own logs.

If any of your friends are comfortable doing this, you can also give them the source code and ask them to run it in a debugger.

Getting to know the underlying hardware better is never a bad idea. IMO one serious weakness of OpenGL is that it's a bit too high-level; it abstracts the hardware a bit too much. What this means is that it's often possible to write really badly incorrect code and still have it run, at least on your development machine. And when weird things or crashes start happening, it can be quite difficult to pin down the exact cause.

Finally take a good look through your code and check all the GL extensions you're using. Make sure that you're checking the return values for your wglGetProcAddress (or equivalent) calls, that you're also checking the extension string, and that you're not making any assumptions about extensions being available.

##### Share on other sites
We're using OpenGL api with last features like in D3D10/D3D11 - and of course they're also available just on D3D10/D3D11 gpus ... and thus we say, that our technology targets D3D10/D3D11 gpus. (E.g. we're using OpenGL 3.2/3.3/4.0)

E.g. what am I trying to say?
Decide what are your target specifications (GeForce 8 series/AMD Radeon HD 2 series ... GeForce GTX 2 series, AMD Radeon HD 5 series ... etc.) and develop for them. You can't make your game run on all GPUs unless you use very old OpenGL 1.1 specs (and you rather won't, because some current drivers might get to problems with them ... because they're built against these specs).

##### Share on other sites
Yes, I know about that, sorry that maybe I did not explain myself correctly. My target hardware is anything that supports GLSL (I think should be OpenGL 1.5, if I'm not mistaken).
But in all hardware that I tested, all meet the requirements, however, only one of them did run the game, the others just crashed or showed a black screen.
I'm probably doing something with OpengGL that is invalid but my graphic card accepts it.

Today I just found that Intel drivers crashed because of my shaders that are full of #defines and #ifdef, #undef, etc. So it was not my problem after all, but faulty drivers... I now pre-process the shader code myself, and that seems to work, however, instead of crashing, now it shows a black screen. Why I am insisting on running on this Intel? Well, the owner of it, a friend of mine, is also a coder, and uses OpenGL and shaders, and his programs work in that laptop.

mhagain did give lots of useful advice, thanks!

"Make sure that you're checking the return values for your wglGetProcAddress (or equivalent) calls, that you're also checking the extension string, and that you're not making any assumptions about extensions being available."
Yes, my code is very strict about that, if any extension required is not found, it reports it to a log file and shows an error to the user. Also I'm using a custom OpenGL dll loader that when a function is not found, it tries to find the ARB version, and if it still fails, the EXT version.

##### Share on other sites
Are you using a nvidia or ati video card for development ? Nvidia cards are known to be more slack about the gsls syntax, whereas ati requires the correct syntax. I would sugguest to buy atleast one video card from every major video chip manufacturer you want to support (atleast nvidia & ati) and avoid high-end cards when you want to support mid-range products.

Then log everything about the video card at the beginning (including all extensions). You should use some kind of debug build which checks frequently gl errors and logs them. But be careful, checking for gl errors can be a performance killer and should be used sparely in a release build (note: flush the log file after each entry, else important log entries could be gone due internal buffering when your program crashes).

##### Share on other sites
Quote:
 Original post by Ashaman73Are you using a nvidia or ati video card for development ? Nvidia cards are known to be more slack about the gsls syntax, whereas ati requires the correct syntax.

I am using an ATI card, I bought it specially because of I known that NVidia are less strict about the sintax. However it seems like buying a cheap Intel would be even better..

Quote:
 Original post by Ashaman73Then log everything about the video card at the beginning (including all extensions).

This was already done, I used it to confirm that all cards tested meet all requirements of the game.
[/quote]

Quote:
 Original post by Ashaman73 You should use some kind of debug build which checks frequently gl errors and logs them.

Ok, I am doing this now, and debug build that calls glGetError after each openGL call and halts the game whenever an error is found, dumping the callstack, line info, etc to the log. Hopefully this will help find the problems!

A GLSL problem I found is, typecasting of a mat4 to a mat3, something like:
mat4 modelMatrix;mat3 normalMatrix = mat3(modelMatrix);

Is this valid GLSL?
Because both ATI and NVidia accept it, and Intel doesn't, even though it seems something that should be allowed, it is just something basic..

##### Share on other sites
A few words of warning that might make your life easier:
- Intel is very picky about loops and arrays in GLSL. I recently had to unroll my lighting loop by hand, because it would mis-compile on Intel 4500 drivers.

- Intel drivers do not support vertex texture fetch. This sucks.

- arrays-of-structures are treated differently between Intel, Ati and Nvidia. It's nigh impossible to make them work reliably, so avoid them if at all possible! (Plain structures should be fine).

- 1-length arrays may render incorrectly on Nvidia cards. Intel cards will downgrade them to non-array datatypes, which is a nasty surprise when binding uniforms by name.

- Ati and Nvidia cards handle conditional texture sampling differently. Nvidia is stricter here: you might notice seams on texture boundaries on Nvidia unless you use textureGrad.

- Ati drivers may fail to compile some specific loop constructs. Sometimes shuffling code around will get it them to work.

- Ati drivers have historically had problems when copying/blitting depth and stencil textures. YMMV, but I haven't managed to get depth blits to work, ever.

##### Share on other sites
Quote:
 Original post by RelfosA GLSL problem I found is, typecasting of a mat4 to a mat3, something like:mat4 modelMatrix;mat3 normalMatrix = mat3(modelMatrix);Is this valid GLSL?Because both ATI and NVidia accept it, and Intel doesn't, even though it seems something that should be allowed, it is just something basic..

That's not valid with GLSL 1.10
You need GLSL 1.20

##### Share on other sites
Quote:
 Original post by V-manThat's not valid with GLSL 1.10You need GLSL 1.20

I see, that explains it, thank you!
And thanks, Fiddler, that list is very useful to know the problems with all three.
Also, after some hours of intense debugging, I managed to make my game run on all my friends pcs, it is all ok now.

##### Share on other sites
Hi, I am developing on Intel 4500 and have spent several hours today to get things work.

Why this line gives only glClearColor?[code]gl_FragColor += vec4(color, 1.0) * vec4(lighting * 0.5, 1.0);[/code]
But this line works fine?
[code]gl_FragColor += vec4(color, 1.0) * vec4(lighting, 1.0);[/code]
Idea is that 0.5 is actually some random float instead of attenuation variable.
lighting consists of diffuse and specular. If lighting consists of only diffuse OR specular then I can multiply with attenuation and it works well. I tested it moving light farther every frame.
I havent got any other videocard at the moment, to try if it shows lights or not.
Thanks.

##### Share on other sites
[quote name='Fiddler' timestamp='1291803827' post='4743519']
- Ati drivers have historically had problems when copying/blitting depth and stencil textures. YMMV, but I haven't managed to get depth blits to work, ever.
[/quote]

Make sure you are using 2D textures (and not texture rectangles!) with the type set to GL_DEPTH_COMPONENT (everything else fails), and do not use multi-sampling! You can then read/write as GL_FLOAT if needed.... (I suffered the same problems for some time until i finally figured it out)

##### Share on other sites
The very broadly-stated way to deal with supporting many cards is simply to detect the hardware capabilities of the graphics adapter at the time that the game is launched, and then gracefully disable higher-end functions that are not supported by the users GPU -- for relatively modern cards (say SM3 or higher) this usually amounts to disabling certain "bling" features (stuff that's nice to have and use, but can be done without, vendor extensions or tesselation for instance) that aren't supported across the range of cards that a certain render path supports, or which is impractical to use in all cases due to performance. Possibly you will also want to have multiple render paths -- a somewhat contrived example would be a fully-programmable path vs. a fixed function path, or possibly an OpenGL path vs. a Direct3D path; in other words, a render path is generally something where an largely different approach must be taken, rather than just turning features on or off.

All of this is difficult to do well, mind you, but its possible to support an incredibly broad range of cards in this way -- There was a mod for the Elder scrolls, for example, which supported hardware all the way down to GeForce 2 or 3 (of course, it didn't look very good, but it was playable.) Most Id games also degrade gracefully quite a ways down.

Like others have said, come up with a minimum target based on what type of hardware you expect your typical customer to have, and build primarily around that. Always detect what features a user's GPU supports -- even if you end up not being able to run on their machine, its an invaluable asset for debugging and for seeing that, perhaps, you've missed the mark on who your target customer really is.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Forum Statistics

• Total Topics
628281
• Total Posts
2981800
• ### Similar Content

• By mellinoe
Hi all,
First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
• By aejt
I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
I have these classes:
For GPU resources:
Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).
And my plan is to define everything into these XML documents to abstract away files:
Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
Factory classes for resources:
For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
Factory classes for assets:
Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).

Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
Thanks!
• By nedondev
I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
Thanks.

• So I've recently started learning some GLSL and now I'm toying with a POM shader. I'm trying to optimize it and notice that it starts having issues at high texture sizes, especially with self-shadowing.
Now I know POM is expensive either way, but would pulling the heightmap out of the normalmap alpha channel and in it's own 8bit texture make doing all those dozens of texture fetches more cheap? Or is everything in the cache aligned to 32bit anyway? I haven't implemented texture compression yet, I think that would help? But regardless, should there be a performance boost from decoupling the heightmap? I could also keep it in a lower resolution than the normalmap if that would improve performance.
Any help is much appreciated, please keep in mind I'm somewhat of a newbie. Thanks!

• Hi,
I'm trying to learn OpenGL through a website and have proceeded until this page of it. The output is a simple triangle. The problem is the complexity.
I have read that page several times and tried to analyse the code but I haven't understood the code properly and completely yet. This is the code:

I don't know what parts are necessary for that output. And also, what the correct order of instructions for such an output or programs is, generally. That start point is too complex for a beginner of OpenGL like me and I don't know how to make the issue solved. What are your ideas please? What is the way to figure both the code and the whole program out correctly please?
I wish I'd read a reference that would teach me OpenGL through a step-by-step method.

• 10
• 11
• 17
• 14
• 9