OpenGL basics

OpenGL is a platform independent graphics API (application programming interface) that can be used to create 2D and 3D graphics. The API uses hardware acceleration, which means that calculations are made using the graphics card (GPU) in the computer rather than the main processor (CPU).

This page is a presentation of my first graphics programs that I made when I took a course in basic 3D computer graphics at the university (TNM046).

My first triangle. The color of each pixel is interpolated from the colors of the vertices.

My first triangle. The color of each pixel is interpolated from the colors of the vertices.

A cube. Again, the colors are interpolated from the vertices.

A cube. Again, the colors are interpolated from the vertices.

cube

This cube has 3 vertices at the same position but with diffrent colors in each corner. this makes it posible to make the sides diffrent colors.

This is a sphere that is drawn using a fragment based shader. The light is calculated using diffuse, specular and ambient light, at every vertex, the colors for the pixels are than interpolated from the vertices. The result is not that good.

This is a sphere that is drawn using a fragment based shader. The light is calculated using diffuse, specular and ambient light, at every vertex, the colors for the pixels are than interpolated from the vertices. The result is not that good.

Here the normals are interpolated from the vertices instead, and the light are calculated for each pixel. This requires more computer power, bot it gives a better result. This method is known as the Phong shading model.

Here the normals are interpolated from the vertices instead, and the light are calculated for each pixel. This requires more computer power, bot it gives a better result. This method is known as the Phong shading model.

All the object above are drawn using parallel projection, that means that the z coordinate is set to zero and the objects are drawn to the screen. This is an example of perspective projection. Here the z coordinate sets the scale for the x and y coordinates. this gives the appearance that objects further away from the eye is smaller.

All the object above are drawn using parallel projection, that means that the z coordinate is set to zero and the objects are drawn to the screen. This is an example of perspective projection. Here the z coordinate sets the scale for the x and y coordinates. this gives the appearance that objects further away from the eye is smaller.

This is a sphere with a texture of the earth mapped to it. The sphere is lit by (very little) ambient light and diffuse light. The position of the light source is shown with a white sphere.

This is a sphere with a texture of the earth mapped to it. The sphere is lit by (very little) ambient light and diffuse light. The position of the light source is shown with a white sphere.

Note: The following 3D objects are loaded form a obj-files that are available under the creative commons license on the internet. I take no credit for those 3D models!

On the following images, the 3D models are drawn using perspective projection and shaded with the Phong shading model (ambient, diffuse and specular light). The light source if shown with a white sphere. In the programs, the models can be rotated using the mouse, and the light source can be positioned using the arrow-keys on the keyboard.

A Maya pyramid, The object consists of 3800 vertices.

A Maya pyramid, The object consists of 3800 vertices.

A Tyrannosaurus rex. This model consists of 25000 vertices.

A Tyrannosaurus rex. This model consists of 25000 vertices.

This is a Zergling from the game "StarCraft". This model is very detailed, it consists of 250000 vertices. This 3D model was designed to be printed using a 3D printer. Therefore it has no texture image, I have used the texture from the T-Rex instead.

This is a Zergling from the game “StarCraft”. This model is very detailed, it consists of 250000 vertices. This 3D model was designed to be printed using a 3D printer. Therefore it has no texture image, I have used the texture from the T-Rex instead.

Another image of the zergling.

Another image of the zergling.

Leave a Reply

Your email address will not be published. Required fields are marked *