Monday, August 26, 2013

Basic GLFW Tutorials with C++

GLFW (OpenGL FrameWork) is open source library to create OpenGL Window and multi-platform  too. Very easy to manage OpenGL context and event with GLFW. It is specially suitable for game development. GLFW doesn't render 3D scene for that you have to use OpenGL library function. GLFW help to create window , handle keyboard , mouse and joystick events. This tutorials is for those who are new to OpenGL and GLFW. By the end of this tutoirals series understand the basic knowledge about OpenGL and handling events with GLFW.

Tutorials 1: Setup GLFW in Code::Blocks IDE in Windows Machine

Tutorials 2:  Introduction to GLFW

Tutorials 3: Drawing Basic Shapes

Tutorials 4: Transformation: Translation, Rotation and Scalling

Tutorials 5: Texture Mapping 

Saturday, July 27, 2013

Modern OpenGL Tutorial Series

Modern OpenGL are different than ancient opengl version before 2.0. After opengl 2.0 vetex shader and fragment shader became compulsory. It is little bit difficult for beginner to start.

All chapter include basic concept of Modern OpenGL and especially focus on beginner. After going through all the chapter user can get concept of shader, drawing shapes, perspective projection, transformation, color, texture mapping and load 3D model wavefront OBJ.

Download all the code as a zip from here: https://github.com/smokindinesh/Modern-OpenGL-Series/archive/master.zip

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.

Modern OpenGL tutorial 3D model .obj loader/parser with C++ and GLM

When you need to draw a more advanced object like character, house, terrain, vehicles we can't pass the vertices by ourselves for these object so we have to use the 3D model and model are simply the meshes made of one or more number of vertices. There are many 3D modeling software one of them is blender which is open source also. Blender help to create the model and export it into different file format like .obj, 3ds, md2 etc among them I choose the .obj (wave front obj) file which is very simple. OBJ only contain vertex, normal, texture and other material information. It doesn't support animation for animation we can use  3ds, md2  3Dmodel. There are many library to load 3D model.

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.

 In this articles I will show you how to write your own .obj model parser.

Friday, June 21, 2013

Modern OpenGL tutorial Texture Mapping Example source code

Texture mapping technique haven't change in Modern OpenGL. If you are experience in ancient version of OpenGL you might have done Texture mapping which is similar to here.Only difference is adding the extra variable to the vertex shader and fragment shader. Texture memory lie in video memory similar to VBO which is uploaded to OpenGL. Two things we have to pass in vertex shader and fragment shader. One is texture co-ordinate to define how to map on vertex and another texture color data to define the color of every pixel.Many article are there in internet about texture.Some of the great article are below.

  1. Texture Maping and Bitmap  This example use the OpenGL version 1.5 where VBO and VAO are absent.
  2. Texture is not Picture Article presents whats the texture is about.
  3. Texure This is the blog form where I learn about Modern OpenGL. 
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.

Thursday, June 20, 2013

Modern OpenGL tutorial Playing with color example

At first have a look screen shot of our program what we have going to build.

You have seen a triangle having different color at each vertex. In previous tutorials series we are just drawing the white triangle without color.

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.

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.