Getting started with OpenGL
If you want to learn OpenGL, this is where we’re going to start. I’ll take you through getting a window on screen, drawing a few shapes, then adding lighting, textures and a camera. Once we’ve got those working, we can have a bit more fun with shadows, reflections and particles.
Start with your first OpenGL window, or have a look at the tutorials below.
- OpenGL
- OpenGL 1.x / 2.x
Fixed-function calls - Code
- C++ and GLUT
FreeGLUT and GLEW setup - Before you start
- Some basic C++
No OpenGL experience needed
Tutorials
If you’re new to OpenGL, start at the top. We’ll add a little more to our program with each tutorial.
1. OpenGL Window (Version 2.0)
If you wish to learn OpenGL, then this is the very first tutorial for you. Learn how to create a GLUT window with an OpenGL context, and how to initially setup OpenGL.
Read tutorial →2. OpenGL Window Reshaping (Version 2.0)
Re-shaping a window with an OpenGL context can cause undesired scaling if not done correctly. If you wish to learn how to fix this, then this tutorial is for you. Learn how to setup your projection ...
Read tutorial →3. OpenGL Keyboard Interaction (Version 2.0)
Keyboard interaction can be handled by the user using system API calls, but why do that when you are already using GLUT which can handle this for you? This tutorial will focus on getting and using ...
Read tutorial →4. OpenGL Primitives – Square (Version 2.0)
One of the very first things you will want to do with OpenGL is learn how to draw shapes. OpenGL provides some basic shapes, which can then used to make complex 3D objects.
Read tutorial →5. OpenGL Colour (Version 2.0)
Colour is one of the fundamental building blocks of a scene. Colours can be used to portray mood, realsim, fictions, intensity, or anything else. It's up to the artist, and in this case, you are the ...
Read tutorial →6. OpenGL Cube (Version 2.0)
From basic 2D shapes, 3D shapes are built. And whilst complex, there are some which are provided to us by GLUT, one of those being your standard cube, made up of 12 triangles and 8 vertices, ...
Read tutorial →7. OpenGL Rotation and Translation (Version 2.0)
Placing objects in a 3D scene is nice, but often enough, you want to be able to move and interact with these shapes. Here you will learn how to rotate them with a single command.
Read tutorial →8. OpenGL Buffering (Version 2.0)
While single buffering still displays our final image, it can cause artifacts. Double buffering lets us draw everything in a second buffer, and when finished, lets us transfer it to the screen for a smoother application.
Read tutorial →9. OpenGL Blending (Version 2.0)
Colours can be mixed and matched in OpenGL, just like in real life. Here you will learn how to blend shapes using OpenGL, allowing you to overlay shapes on top of each other to get the ...
Read tutorial →10. OpenGL Scaling (Version 2.0)
Drawing shapes is fine, moving them about is fine. But do you always want a shape to be the same size? Are all tree's the same height? Of course not. Here I will show you how ...
Read tutorial →11. OpenGL Lighting (Version 2.0)
Flatly colouring shapes is perfect, if we want an unrealistic look to our scene. But for realism, we really want to add some sort of lighting system. You can learn here how to use OpenGL's lighting ...
Read tutorial →12. OpenGL Materials and Lighting (Version 2.0)
Now you have your scene looking a little nicer with some lighting, but all objects are a gray colour. Here we will learn how to assign materials to shapes to change how they look under different ...
Read tutorial →13. OpenGL Lighting Types (Version 2.0)
OpenGL provides us with not one, but three different types of lights we can make, directional lights, point lights and spot lights. I will try to teach you about how each is different, and how to ...
Read tutorial →14. OpenGL Fog (Version 2.0)
Ever notice how on a clear day, your visibility seems to go on for miles, but when the weather changes, a nice misty fog may come over, and your vision can be reduced to virtually nothing? ...
Read tutorial →15. OpenGL Fog Types (Version 2.0)
Just like there are different types of lighting in OpenGL, we also have different types of fog for different effects. Learn how to use them in this tutorial.
Read tutorial →16. OpenGL Texturing (Version 2.0)
The next step in the quest for realism after lighting, comes in the form of texturing. Texturing is the art of drawing an image on top of a 3D object and is the core behind all ...
Read tutorial →17. OpenGL Texture Coordinate Generation (Version 2.0)
When assigning a texture to an object, you need to declare the texture coordinates, little values between 0 and 1 that tell us which part of the image maps to which part of the 3D model. ...
Read tutorial →18. OpenGL Popping and Pushing Matrices (Version 2.0)
When drawing objects in OpenGL, it can be annoying that you do a translation, and then before drawing the next shape, you have to do a reverse translation to fix your positions. Well OpenGL being a ...
Read tutorial →19. OpenGL Fullscreen Mode (Version 2.0)
Most games we know, run in fullscreen mode, and lucky for us, GLUT provides this ability also. So let me show you how to make use of it.
Read tutorial →20. OpenGL MipMap Generation (Version 2.0)
Mip maps are an essential texture extension, which creates scaled down versions of a texture and uses them when an object gets further away, or closer to the near plane. This scaled down version of the ...
Read tutorial →21. OpenGL Display Lists (Version 2.0)
Display lists are a cached version of a set of OpenGL calls, which can be called again and again, at quicker framerates than writing the code over and over again. There is much controversy over the ...
Read tutorial →22. OpenGL Camera (Version 2.0)
If you look at making any game where the scene is larger than can be displayed in the window at once, then you are going to need some type of camera system. This is the first ...
Read tutorial →23. OpenGL Camera Part 2 (Version 2.0)
Here I will be extending upon the previous OpenGL Camera tutorial, and adding a strafe feature (moving side to side). A game without strafing, is going to be terrible, especially when it comes to multiplayer when ...
Read tutorial →24. OpenGL Camera Part 3 (Version 2.0)
The first person camera is done, lets take a look at the third person camera, which is essential any type of Role Playing Game. The best part is, this tutorial uses most of the same code ...
Read tutorial →25. OpenGL Vertex Colouring (Version 2.0)
Along with assigning colours to objects, did you know you can also set colours to individual vertices? Well yes, yes you can.
Read tutorial →26. OpenGL Vertex Alphas (Version 2.0)
Alpha values, just like colours, can be assigned on a per-vertex basis. This allows for varying levels of transparency across objects.
Read tutorial →27. OpenGL Basic Shadows (Version 2.0)
With lighting, comes shadowing. This tutorial takes a basic stencil buffer, and uses it as a stencil to draw a basic shadow on to it.
Read tutorial →28. OpenGL Basic Reflection (Version 2.0)
Just like our shadowing tutorial, this one uses the stencil buffer, but we are going to keep our color buffer enabled to allow us to keep our colors for a basic reflection.
Read tutorial →29. OpenGL Bounding Sphere Collision (Version 2.0)
At present, none of our OpenGL shapes can interact with each other, that is because OpenGL is purely graphics, it doesn't handle physics, so using the Euclidean distance algorithm, we can implement some basic bounding sphere ...
Read tutorial →30. OpenGL Circle Drawing (Version 2.0)
Circles are one of the few shapes that are not default in OpenGL, but the good news is, they are easily created using lines. In this tutorial, I will show you how to draw a nice, ...
Read tutorial →31. OpenGL Sphere Creation (Version 2.0)
While GLUT provides a sphere for us to draw, that sphere does not contain texture coordinates. In this tutorial, I will show you how to create your own sphere, which has texture coordinates included. Now you ...
Read tutorial →32. OpenGL Particle Engine (Version 2.0)
Lets face it, particles are ALOT of fun. Whether you want to create a weather system, some awesome fire, or just throw a million objects around randomly, they are both stimulating in a game, and fun.
Read tutorial →33. OpenGL Animating Textures (Version 2.0)
Textures by themselves are perfectly fine, you don't have to do anything with them. But have you ever wanted to load a movie into a 3D scene? Maybe you want to read a movie file, and ...
Read tutorial →34. Orthogonal Projections (Version 2.0)
While OpenGL is built for 3D rendering, it does also support 2D. This is where you want orthogonal projections, which are perfect for a Heads Up Display, or a menu system.
Read tutorial →35. OpenGL Tiling Engine (Version 2.0)
If you want to create a game like Sim City, or an RPG, then you are going to need some sort of tiling engine. This breaks up the ground into a bunch of known images and ...
Read tutorial →36. OpenGL Framebuffers (Version 2.0)
If you want to use any type of off screen rendering process, then frame buffers are probably the go for you. They allow you to render an entire scene, directly to a texture.
Read tutorial →
Before you start
You’ll need some basic C++ and a compiler. The first tutorial takes you through setting up FreeGLUT and GLEW, so we can get straight into drawing.
More tutorials
Once you can draw and texture a scene, why not try building some terrain? There are also a few extra pointers in OpenGL Drivers and OpenGL Tips.




































I have some difficulty for export code into Xcode (Apple) code… Objective-c not swift
…
Great tutorials.It gave me a hope to enter into graphics field.I wish that more tutorials should be published
Keep up the good work, your 2.0 tutorials beautiful !
Thanks for this beautiful tutorial
nice tutorials thanks, to shear this tutorial. i will wait to get more tutorials…..
brilliant tutorial swiftless.
will you be doing any tutorials on memory allocation?
Great tutorial……. can you please provide any tutorial for page flipped stereo image rendering… thanks a lot 🙂
Great Tutorial…….But from tutorial no.8 when I copied the code it didn’t compile, it had lots and lots of errors
Hi Shivam,
From no.8 and onwards, those are older tutorials. I’m guessing your errors were related to library issues but copy and paste could have been formatting errors due to special characters. I’m trying to find the time to update the remainder of the tutorials.
Cheers,
Swiftless
this was such a shit life….my head were struggling for a while…its so difficult
I want to do texture mapping in Linux. I searched many sites but i didn’t get it. Will you please help me with a simple texture mapping tutorial in linux?
Thanking in advance
ThanQ for making this easy ans intrusting
Great tutorials, really easy to understand. Tysm 🙂
Thanks for posting these, its my intention to learn open gl just for kicks and these are really well structured and organised tutorials. Just what I need. If this isnt worth a book mark i dont know what is.
Awesome please make some new Physx tutorials aswell 😉
i want to rotate, translate,scale and shear all of this shape. please help me soon.
ebrahim firouzi (nilicity@gmail.com)
code is here in c++ , opengl
===================
/*
* Desaigned by Ebrahim Firouzi
* Graphic project
* professor : Dr. Yaghmayee
*82
*/
#include // also included gl.h, glu.h
void display() {
glClear(GL_COLOR_BUFFER_BIT); // Clear all screen
//part 1 of home
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 1.0f); // pink
glVertex2f(-0.3f, -0.2f); // x, y
glVertex2f(-0.1f, -0.2f);
glVertex2f(-0.1f, 0.3f);
glVertex2f(-0.3f, 0.3f);
glEnd();
//part 2 of home
glBegin(GL_TRIANGLES); // Each set of 3 vertices form a triangle
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex2f(-0.3f, 0.3f);
glVertex2f(-0.1f, 0.3f);
glVertex2f(-0.2f, 0.5f);
glEnd();
//part 3 of home
glBegin(GL_POLYGON); //draw square
glColor3f(0.0, 1.0, 1.0);
glVertex2f(0.20, 0.0);
glVertex2f(0.20, 0.40);
glVertex2f(-0.1f, 0.3f);
glVertex2f(-0.1f, -0.2f);
glEnd();
//part 4 of home
glBegin(GL_POLYGON); //draw square
glColor3f(1.0, 1.0, 0.0);
glVertex2f(0.20, 0.40);
glVertex2f(0.10, 0.55);
glVertex2f(-0.2f, 0.5f);
glVertex2f(-0.1f, 0.3f);
glEnd();
//part 5 of home
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(0.0f, 0.0f, 1.0f); // pink
glVertex2f(-0.19, -0.2f); // x, y
glVertex2f(-0.1f, -0.2f);
glVertex2f(-0.1f, 0.07);
glVertex2f(-0.19, 0.07);
glEnd();
glFlush(); // Render now
}
// GLUT runs as a Console Application
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitWindowPosition(180, 80) ; //position of output window
glutInitWindowSize(1000, 600) ; // window size
glutCreateWindow(“Ebrahim Firouzi Graphic Project”); // Create a window with the given title
glutDisplayFunc(display); // Register callback handler for window re-paint
glutMainLoop(); // Enter infinitely event-processing loop
return 0;
}
Really the brilliant tutorials. I like them so much. Thanks for publishing these tutorials.
Morning, can u help me about make a transformer in open gl Visual C++??
u can send the source code in my email : jonathan_rere_kudus@yahoo.com
hi swiftless,,your tutorial is very informative really easy to understand,,can you make a tutorial how to create simple text in opengl?i’ve search a lot but it seems i cant find any tutorial that i can understand(im a newbies in programming.)thx a lot.
Please tell me to import 3d models of auto cad and googe sketchup…..
Thanks for the great tutorials. Please do not remove your OpenGL 1.x or 2.x tutorials, because many of us Linux/Mesa3D users are still living in the dark ages when it comes to OpenGL implementation. 🙁 Cheers.
Jeremy
Cool stuff 😉
thanku swiftless..i had no idea about opengl and i learnt a lot..:-)
Excellent tutorials. Very detailed. Very understandable. However there must be a tutorial for loading 3d models of various formats (.obj for instance) from 3d modeling software (Blender for instance) into OpenGL.
add a 3D rendering code for ct images.that is 2D to 3D conversion code
THANKS A LOT. This is one of the only site with such a complete Glut/OpenGL tutorial.
Maybe a little complement on how to include these in different programming environments (Visual Studio on Windows, XCode on Mac…).
add some more..great work
Please, more tutorials! Perhaps on more advanced rendering, like deferred shading, HDR, motion blur, frustrum culling techniques, anything like that? Showing how to use GLSL for ocean simulation (waves, shore fogging, underwater stuff…)
Your tutorials are great, please make more! 🙂