OpenGL Superbible

Richard S. Wright, Benjamin Lipchak, Nicholas Haemel

Mentioned 12

The comprehensive, hands-on guide to OpenGL is now fully updated for OpenGL 2.1, and is now part of the official OpenGL series from AW.

More on

Mentioned in questions and answers.

Does anyone know a good beginners guide to using OpenGLES on the iPhone? I have found some but they all require assumed knowledge which I don't have.

In addition to "The Red Book", another useful book -with tutorials and reference- is OpenGL SuperBible.

Again not OpenGLES specific, but I believe it is useful to learn OpenGL features in general, then filter out the ones you don't need.

I currently rewrite an old Visual Basic application in java, a large part of the work involves replacing Direct3d with jogl.
Since I have no experience in dealing with Direct3d and only minimal experience using Opengl, I am stuck on finding appropriate replacements for the api calls.

Are there any good guides/tutorials or references?

Additional information:

  • Direct3D version 8

NeHe tutorials will get you up to speed quickly. If you have time and need for something more comprehensive, you should get the OpenGL SuperBible.

I've always had an interest in creating my own games, and now at university I have the opportunity to create some 2D and 3D games using Java and C++ for those who are that way inclined.

I've never really programmed a game before, let alone graphics, so I'm completely new to the area. After a quick trip to the library today I came across very little information on starting 2D game development or even graphics programming in Java or C++. I can program in Java at a reasonable level, but I have never touched C++.

  1. Can someone recommend any good books on starting Graphics Programming in Java or C++?
  2. I have no C++ experience, but I've programmed in C and Java and feel reasonably comfortable in both. Should I take the jump and dive into C++ when important marks are at stake? I hear a lot of good things about C++ as far as Games Programming goes so I'm unsure as to what is the best option for me.
  3. I'm looking to write a 2D game in my own time for a bit of fun before I start getting into the heavy work at university. Can anyone recommend some good resources for those interested in writing their own games using OpenGL and Java/C++.
  4. For those who have followed my other questions here I am terrible at Maths and hold very little knowledge of even the foundations. Is this going to be a serious problem for me? If I were to need Math knowledge what do you recommend I brush up on?

I apologise if my questions seem a bit vague, as I'm a complete newbie when it comes to a lot of these topics. Any help you could provide would be much appreciated.

EDIT: I've already checked out the question titled "game programming", but have found it to not really cater for my specific questions.

I have this book: Beginning C++ Through Game Programming. It might seem trivial at first, but it teaches you a-lot as you go through it. There is no GUI based programming in this book, just the console. Which is good to an extent if you want to see how an entire "story" of a game can come together.

You can also check out, they have a vast amount of resources and articles to get you started. Good luck. :)

Game programming, especially where graphics are concerned, involves a fair amount of math. You'll at least want to have a basic familiarity with vectors and matrices, specifically with regard to representing rotation, translation, and scaling transformations. To that end, I recommend Geometric Tools for Computer Graphics. A course in linear algebra wouldn't hurt, as well, although that's probably already in your curriculum.

As far as game programming in Java, I recommend taking a look at jMonkeyEngine, an open source game engine with all sorts of fun example code to get you started. It was originally based on the engine presented in the book 3D Game Engine Design (same author as Geometric Tools above), which is another good source of information about game programming in 3D. There's also C++ code and papers on various topics in 3D graphics at that book's official site.

Here are a few books that I used when writing OpenGL code in C++:

Fundamentals of Computer Graphics

OpenGL SuperBible

OpenGL Red Book

OpenGL Primer

You might check out the MIT OpenCourse on computer graphics too. It might help supplement your development.

Best of luck!

I am going through a similar process to you at the moment. I found the following site helpful, it has a great tutorial (space invaders in Java):

You can get the source code and mess around with it. You will probably benefit from an IDE, if you don't already have a favorite you could try Netbeans ( which is free and I think it's pretty good.

As for books this one is OK (it's java-centric):

I personally decided to use Java for games (for now) because I am very comfortable with Java and far less so with C++. But you will find that most people use C++ for commercial games. Actually I started with pygame (python games framework) which is also nice to get started, especially if you know python.

I want to learn the basic concepts like collision detection, rendering and others in a general way (keeping the library usage minimum). I believe that once my basic concepts are clear, it would help me in learning different libraries easily, like OpenGL, etc.

I know without libraries it will take long time to build things. I am doing this for learning so I don't care about productivity.

I would love if the solution is using JavaScript (HTML5 Canvas) or C/C++ (DOS mode) since I believe I will have to deal with a bit of low level stuff which would help me in learning. Other solutions are also welcome. I know Java as well.

Note: 2D games are sufficient for me.

Good question - A decent place to start is

They have some pretty fun courses, no time limit and a decent forum. I actually met some good local dev's there and since have done some stuff together.

I'd also look at getting into the yearly Global Game Jam ( It's a really great experience for novice and professional devs. You can also meet local people.

I mention "local people" cause sometimes its very difficult to do a game on your own - it really helps to have people to collaborate with. Though it brings in problems of its own (schedule conflicts, motivation, etc).

I'd take a look at the following books:






This are just a few books on the top of my head that I've enjoyed in my travels.

I'd focus on a language like python that'll get you up and running quickly. Not C++ - I think you lose a lot of productivity on the language it self, templates, smart pointers, vtables, etc. And then you have all the different version of DX, Win32 GDI etc. I think you'll be more productive in a different language. Maybe lua + python?

Also, I'd seriously look into mastering an engine. I wrote my own, and it was a great journey, but we never completed the GAME! We spent 6 months writing the engine, 2 months writing the game and got burnt out. Next time I'd use an engine for sure!

  1. Unity3D works on iphone, web, desktop.

  2. Torque is another leader, though I didn't find this one as slick as Unity.

  3. Cocos2d is a iphone specific framework, based on a python framework. Really slick.

Another option is taking an existing game that allows Mods (HL2, Quake, etc) and build some mods for it. You can probably find tons of forums and groups already doing it and perhaps contribute to an existing project or start your own.

Another really gnalry idea would to be to get the Blue Book


And don't stop till you understand and have worked through it!!! You'd be a pretty good openGL / C coder by the time you made it through that book (cover to cover). Set aside a few months...heh.

Don't forget - you can always start with paper-prototyping games, you don't have to start building computer games.

Good luck!

I am trying to rotate my object like shakes dice. please suggest simplest way to implement it in my iphone application. Any kind of sample code or documentation.

I am trying to use GLSL with openGL 2.0.

Can anyone give me a good tutorial to follow, so that I can setup GLSL properly.

Regards Zeeshan

Depending on what you are trying to achieve and what is your current knowledge, you can take different approaches.

If you are trying to learn OpenGL 2.0 while also learning GLSL, I suggest getting the Red book and the Orange book as a set, as they go hand in hand.

If you want a less comprehensive guide that will just get you started, check out the OpenGL bible.

If I misunderstood your question and you already know OpenGL, and want to study more about GLSL in particular, here's a good phong shading example that shows the basics.

Compiling a shader source is really simple,

First you need to allocate a shader slot for your source, just like you allocate a texture, using glCreateShader:

GLuint vtxShader = glCreateShader(GL_VERTEX_SHADER);
GLuint pxlShader = glCreateShader(GL_FRAGMENT_SHADER);

After that you need to load your source code somehow. Since this is really a platform dependent solution, this is up to you.

After obtaining the source, you set it using glShaderSource:

glShaderSource(vtxShader, 1, &vsSource, 0);
glShaderSource(pxlShader, 1, &psSource, 0);

Then you compile your sources with glCompileShader:


Link the shaders to each other, first allocate a program using glCreateProgram, attach the shaders into the program using glAttachShader, and link them using glLinkProgram:

GLuint shaderId = glCreateProgram();
glAttachShader(shaderId, vtxShader);
glAttachShader(shaderId, pxlShader);

Then, just like a texture, you bind it to the current rendering stage using glUseProgram:


To unbind it, use an id of 0 or another shader ID.

For cleanup:

glDetachShader(shaderId, vtxShader);
glDetachShader(shaderId, pxlShader);



And that's mostly everything to it, you can use the glUniform function family alongside with glGetUniform to set parameters as well.

I'm fixing to start on my second app which will be a game and I'm wanting to start learning OpenGL ES. I haven't been able to find many books out there that teach opengl es so I'm trying to figure out the best way to learn. I'm wanting to get to the level of almost an expert because I would like to be a full time mobile game developer one day.

I've seen Jeff LaMarches tutorials and I know about the NeHe tutorials. I'm personally thinking about buying the OpenGL blue book( link below ) and learning OpenGL first. Mainly because I've taken scientific visualization classes in college but didn't use opengl or directx and I need to learn more about the basics.

So, for those still with me what would be some advice on learning OpenGL ES?

I'm reading OpenGL Superbible 4th ed. In Chapter 2, the example code sets up the callback followed by the clear color as follows:


void RenderScene(void)

void SetupRC(void)
  glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

Is it posisble that we have a race condition here, where glClear might be executed before glClearColor?

It is not a race condition, because glutMainLoop() runs in the same thread and calling the glDisplayFunc() does not invoke any GL functions (it only saves the pointer to your callback).

From the docs:

glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered

OpenGL can only render to the GL contexts created in the same thread. Thus the calls to glClearColor() and RenderScene() will be called in the same thread. Since the call to glutMainLoop() is called later in your main(), the glClearColor() will be called strictly before glClear() in RenderScene().

I'm trying to write a simple maze game, without using any deprecated OpenGL API (i.e. no immediate mode). I'm using one Vertex Buffer Object for each tile I have in my maze, which is essentially a combination of four Vertexs:

class Vertex {
    GLfloat x, y, z; // coords
    GLfloat tx, ty;  // texture coords


and are stored in VBOs like this:

void initVBO()
    Vertex vertices[4];
    vertices[0].x = -0.5;
    vertices[0].y = -0.5;
    vertices[0].z = 0.0;
    vertices[0].tx = 0.0;
    vertices[0].ty = 1.0;
    vertices[1].x = -0.5;
    vertices[1].y = 0.5;
    vertices[1].z = 0.0;
    vertices[1].tx = 0.0;
    vertices[1].ty = 0.0;
    vertices[2].x = 0.5;
    vertices[2].y = 0.5;
    vertices[2].z = 0.0;
    vertices[2].tx = 1.0;
    vertices[2].ty = 0.0;
    vertices[3].x = 0.5;
    vertices[3].y = -0.5;
    vertices[3].z = 0.0;
    vertices[3].tx = 1.0;
    vertices[3].ty = 1.0;

    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*4, &vertices[0].x, GL_STATIC_DRAW);

    ushort indices[4];
    indices[0] = 0;
    indices[1] = 1;
    indices[2] = 2;
    indices[3] = 3;

    glGenBuffers(1, &ibo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ushort) * 4, indices, GL_STATIC_DRAW);

Now, I'm stuck on the camera movement. In a previous version of my project, I used glRotatef and glTranslatef to translate and rotate the scene and then I rendered every tile using glBegin()/glEnd() mode. But these two functions are now deprecated, and I didn't find any tutorial about creating a camera in a context using only VBOs. Which is the correct way to proceed? Should I loop between every tile modifying the position of the vertices according to the new camera position?

I will add to datenwolf's answer. I am assuming that only the shader pipeline is available to you.


In OpenGL 4.0+ Opengl does not do any rendering for you whatsoever as it moves away from the fixed function pipeline. If you are rendering your geometry without a shader right now you are using the deprecated pipeline. Getting up and running without some base framework will be difficult (not impossible, but I would recommend using a base framework). I would recommend, as a start, using GLUT (this will create a window for you and has basic callbacks for the idle function and input), GLEW (to setup the rendering context) and gLTools (matrix stack, generic shaders and shader manager for a quick setup so that you can at least start rendering).


I will be giving the important pieces here which you can then piece together. At this point I am assuming you have GLUT set up properly (search for how to set it up) and you are able to register the update loop with it and create a window (that is, the loop which calls one of your selected functions [note, this cannot be a method] every frame). Refer to the link above for help on this.

  • First, initialize glew (by calling glewInit())
  • Setup your scene. This includes using GLBatch class (from glTools) to create a set of vertices to render as triangles and initializing the GLShaderManager class (also from GLTools) and its stock shaders by calling its InitializeStockShaders() function.
  • In your idle loop, call UseStockShader() function of the shader manager to start a new batch. Call the draw() function on your vertex batch. For a complete overview of glTools, go here.
  • Don't forget to clear the window before rendering and swapping the buffers after rendering by calling glClear() and glSwapBuffers() respectively.

Note that most of the functions I gave above accept arguments. You should be able to figure those out by looking at the respective library's documentations.

MVP Matrix (EDIT: Forgot to add this section)

OpenGL renders everything that is in the -1,1 co-ordinates looking down the z-axis. It has no notion of a camera and does not care for anything that falls outside these co-ordinates. The model-view-projection matrix is what transforms your scene to fit these co-ordinates.

As a starting point, don't worry about this until you have something rendered on the screen (make sure all the co-ordinates that you give your vertex batch are less than 1). Once you do, then setup your projection matrix (default projection is orthographic) by using the GLFrustum class in glTools. You will get your projection matrix from this class which you will multiply with your model view matrix. The model-view matrix is a combination of the model's transformation matrix and your camera's transformation (remember, there is no camera, so essentially, you are moving the scene instead). Once you have multiplied all of them to make one matrix, you pass it on to the shader using the UseStockShader() function.

Use a stock shader in GLTools (e.g. GLT_SHADER_FLAT) then start creating your own.


Lastly, I would highly recommend getting this book: OpenGL SuperBible, Comprehensive Tutorial and Reference (Fifth edition - make sure it is this edition)

What OpenGL / GLUT reference is good for day to day programming as you learn?

Ideally I'm looking for something with lots of C++ sample code to help me learn as I develop OpenGL applications as well as details about the APIs similar to what MSDN provides for .net programming.

If there isn't a one stop shop, then please list the set of references I should use and what the strengths of each one is.

I learned OpenGL using the OpenGL Super Bible. It's still the best reference for it that I can find.

The Red Book is the standard book on OpenGL. Don't be discouraged by the fact that the Amazon review for the 7th Edition has only two stars; this is because people are disappointed that there isn't more on the newest OpenGL features in the book. Previous editions got more stars.

Another good book is the OpenGL SuperBible.

The NeHe Tutorials are one of the most often cited OpenGL tutorials, with sample code not only in C++ but in many other programming languages.

The PyOpenGL Documentation is identical to the OpenGL docs, but far more readable and user-friendly. Have a look.

I also second the OpenGL SuperBible.