Friday, May 31, 2013

Modern OpenGL tutorial Rotation, Scalling and Translation Matrix using GML (OpenGL Mathematics)

In previous article perspective projection I have shown you how to do perspective projection. Now its time to do Scalling, Translation and Rotation which are very important task. In ancient version of OpenGL for these operation opengl provide funcition like glRotate, glScale, glTranslate but in modern opengl this function are not available so we are using GLM (OpenGL Mathematics) for doing such task. From this article I have change the source code with OOP. I have made two reusable classes Program and Shader.

Download
All the code in this series of articles is available from github: https://github.com/smokindinesh/Modern-OpenGL-Series  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.

Setup GTK project in Code::Blocks (windows 7)


Follow the following step to setup GTK project in Code::Blocks (windows 7)
step 1: Download gtk+-bundle_2.24.10-20120208_win32.zip (all-in-one bundle) from http://www.gtk.org/download/win32.php
step 2:  Extract it in c drive creating new directory or any other place. In my case C:\GTK is the directory where I extracted the zip file.
My extracted files looks like below.




Sunday, May 19, 2013

Modern OpenGL tutorial Perspective Projection using GLM (OpenGL Mathematics)

In my previous article you may notice that in vertex data  for drawing a triangle, I have fixed the co-ordinate of z-axis to 1. If you change the value of z-axis greater than 1 or less than -1 then Image will not render on the screen because we haven't define the perspective projection matrix. In this project we are using GLM ,  in previous article there is no especial use of it so I haven't talk about it before but here we use GLM function for perspective projection .GLM is header only library made by heavy use of C++ templates due to which performance can be reduce but make programming easier. GLM can be use with GLSL easily so we are using GLM.

Download
All the code in this series of articles is available from github: https://github.com/smokindinesh/Modern-OpenGL-Series  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.

Saturday, May 18, 2013

Modern OpenGL tutorial Drawing the basic shapes

This article is almost similar to my previous tutoirals series. In previous article we draw only triangle but here we are drawing other shapes.

Download
All the code in this series of articles is available from github: https://github.com/smokindinesh/Modern-OpenGL-Series  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.

Vertex data for drawing is given below:

// Put the 18 triangle verticies into the VBO
    GLfloat vertexData[] = {
        //  X     Y     Z

        //Pentagon
        0.25f, 0.25f, 1.0f,
        0.75f, 0.25f, 1.0f,
        0.25f, 0.5f, 1.0f,

        0.25f, 0.5f, 1.0f,
        0.75f, 0.25f, 1.0f,
        0.75f, 0.5f, 1.0f,

        0.25f, 0.5f, 1.0f,
        0.75f, 0.5f, 1.0f,
        0.5f, .75f, 1.0f,

        //Triangle
        -0.25f, 0.25f, 1.0f,
        -0.5f, 0.75f, 1.0f,
        -0.75f, 0.25f, 1.0f,
        //Trapezoid
        -0.2f, -0.25f, 1.0f,
        -0.35f, -0.75f, 1.0f,
        0.35f, -0.75f, 1.0f,

        0.2f, -0.25f, 1.0f,
        -0.2f, -0.25f, 1.0f,
        0.35f, -0.75f, 1.0f,
    };

Modern OpenGL tutorial: Introduction to shader GLSL (OpenGL shader language)

Shader are compulsory on Modern OpenGL and most important. Shader are a little program they run in GPU i.e for OpenGL, shader run in rendering hardware. There are many shader language available but we use GLSL (OpenGL Shader Language) which is very similar to C but not C. For beginner, shader can be new things so just think it is a little program written in different language that run in  your graphics card. Without shader nothing can be displayed on the screen. Shader takes vertex data as an input, process it and return output value to display on the screen it is vertex processing shader which is called vertex shader. In this program we also use another shader called fragment shader which is used to output the color pixel of fragment. How shader takes input and vertex are processed you will understand later.
Lets start digging the code and I will explain related theory side by side in short so that you can learn quickly and start to write you own program.You can also download the complete source code of this tutorials.
In this whole tutorials series we are using four library:

  • GLFW for creating window, 
  • GLEW to acess OpenGL API function at run time , 
  • GLM for doing some math for us like rotation, translation etc and 
  • GLSL as shader language.
Download
All the code in this series of articles is available from github: https://github.com/smokindinesh/Modern-OpenGL-Series  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.

Wednesday, May 8, 2013

Beginner learning materials for Modern OpenGL API version 3.2

Just copy the code below, compile and run it in Code::Blocks to insure that you have successfully setup Moden OpenGL following instruction given in previous chapter Setup Modern OpenGL in Codeblocks . Also make sure that your pc graphics hardware (GPU) supports OpenGL API version 4.2 or later.

Download
All the code in this series of articles is available from github: https://github.com/smokindinesh/Modern-OpenGL-Series  You can download a zip of all the files from that page, or you can clone the repository if you are familiar with git.


Setup Modern OpenGL with GLFW, GLEW and GLM in Codeblocks

Modern OpenGL 3 and above version may be difficult especially for beginner because of  new shaders and buffer object concepts. OpenGL 1.x is simple to understand and to setup the project also which you can find in my previous articles here. By setting the GLUT or just by including gl.h and glu.h we can acess the OpenGL function because all the API function are determined in compiled time but in modern OpenGL concept is different that all the API function are determined in run time not in compiled time. 
Introduction to GLFW,GLEW and GLM
Lets discusses about all this open source library why they are necessary.
GLEW (OpenGL Extension Wrangler ) will handle the run time loading of the OpenGL API. This will give access to the OpenGL 3.2 and above API functions. It is important because accessing OpenGL functions isn't as simple as #include <GL/gl.h> unless we want to use an ancient version of OpenGL. In modern OpenGL , the API functions are determined at run time,not compile time.

GLFW (OpenGL Frame Work) is used to create a window, and receive mouse and keyboard input in a cross-platform way. We can use freeglut as a alternative of GLFW . GLFW is especially design for game. OpenGL does not handle window creation or input, so this must be done with the help of GLFW or other alternatives. 
GLM(OpenGL Mathematics) is a mathematics libray that handles vectors and metrices. Older versions of OpenGL provided functions like glRotate, glTranslate and glScale which would do some of the mathematics but in modern OpenGL previously mentioned functions do not exist and we have to do by ourselves. GLM will help us to do math.