Saturday, April 28, 2012

GLFW Tutorial 4: Texture mapping sample code in OpenGL Framework

If you are new to the GLFW(OpenGL framework) you can follow beginning tutorial here.
On Contrary with GLUT texture mapping is very easy in GLFW . We want to use pre-generated 2D images for surface textures, light maps, transparency maps etc.These images are stored with a standard image format in a file, which requires the program to decode and load the      image(s) from file(s), which can require much work from the programmer.To make programming easier for OpenGL developers, GLFW has built-in support for loading images from files.
In this tutorial I give example for surface textures only. Surface textures are important because it helps to make object realistic.
To load a texture from a file, you can use the function glfwLoadTexture2D:
int glfwLoadTexture2D( const char *name, int flags )
This function reads a 2D image from a Truevision Targa format file (.TGA) with the name given by name, and uploads it to texture memory. It is similar to the OpenGL function glTexImage2D, except that the image data is read from a file instead of from main memory, and all the pixel format and data storage flags are handled automatically. The flags argument can be used to control how the texture is loaded. If flags is GLFW_ORIGIN_UL_BIT, the origin of the texture will be the upper left corner (otherwise it is the lower left corner). If flags is GLFW_BUILD_MIPMAPS_BIT, all mipmap levels will be generated and uploaded to texture memory (otherwise only one mipmap level is loaded). If flags is GLFW_ALPHA_MAP_BIT, then any gray scale images will be loaded as alpha maps rather than luminance maps. To make combinations of the flags, or them together (e.g. like this: GLFW_ORIGIN_UL_BIT |GLFW_BUILD_MIPMAPS_BIT).
Here is the sample program to illustrate the texture mapping with complete source code written in c++ with gcc compile and code::blocks IDE. You can also download the project file.

Tuesday, April 17, 2012

GLFW(OpenGL FrameWork) tutorial 3:Transformation:Translation,Scaling and Rotation.

If you are beginner to OpenGL FrameWork (GLFW) visit my previous tutorial lesson Here so that you can understand in details.Translation ,Scaling and Rotation of object is so easy because OpenGL provide these command to us we don’t have to write our own  Transformation matrix.

Translation command:

Translation is movement along any of the three axis in a 3D scene, for example, moving something the left is a translation on the X axis if you are looking straight on.
Command:
glTranslatef( xValue, yValue, zValue );
e.g:
glTranslate(5.0, 0.0, 0.0);
This translate the scene five unit along positive x-axis. One things you must remember ,all the scene drawn below this command will be translated.
So,if you want to translate only one object then you have to restore the transformation. Restore can be done by putting drawing scene and translation command between glPushMatrix() and glPopMatrix() .

Monday, April 16, 2012

GLFW (OpenGL Framework) tutorial 2: Drawing Basic Shapes

Lets first discuss how OpenGL does. Describing co-ordinates system of OpenGL, center of co-ordinate is middle of widow, positive x-axis is pointed towards right and negative x-axis toward left ,positive y-axis is pointed towards up and negative y-axis towards bottom , positive z-axis is pointed towards outside of screen and negative z-axis towards inside the screen.
  • coord_system
OpenGL draw object similar to our eye . By default eye is in origin and we are looking toward negative z-axis.

GLFW tutorial 1:Introduction to OpenGL Framework

Welcome to codeincodeblock.blogspot.com I have created this tutorial for 3D programming in OpenGL for beginners. OpenGL has wide range of use some of them is Gamming ,simulation, virtual prototyping. This tutorial provide only basic knowledge of OpenGL in brief with full source code and complete explanation so, that you can move quickly to advanced OpenGL programming. All tutorials is written in c++ so that you must know the basic c++ to understand this tutorial.
We use OpenGL for 3d programming. You may wondering what is OpenGL. OpenGL is software interface for graphics hardware in other word we can say it is language translator so that we can use only one language for different graphics hardware. OpenGL is hardware independent. We can draw both 3D and 2D stuff. For 2D their are better libraries like SDL ,Allegro. We use OpenGL basically for 3D stuff.
I use GLFW library and code::blocks IDE. You may confused reading OpenGL and using GLFW library, what does GLFW means? The creation of a window to render stuff in is not covered in the OpenGL specification. This is handled by platform-specific APIs. GLFW is one of this  APIs. It is a crossplatform windowing and keyboard/mouse/joystick handler. Contrary to GLUT, this is more aimed for creating games. Supports Windows, Mac OS X and Unix-like systems such as Linux and FreeBSD.
You don’t have code::blocks IDE then download it form Here .There are two options of download so, choose codeblocks-10.05mingw-setup.exe file in which MinGW compiler is already install. Then you need to setup the GLFW library in code::blocks. Follow my previous article Setup GLFW Project for setup.
Now you are ready for OpenGL 3d programming..
Goto tutorial 2 Drawing Basic Shape

Friday, April 13, 2012

List of Top Ten College Mini Projects in c/c++ with full source code

If you need to make a Mini project in c/c++ language and you are confused about the project topic then don’t worry here is the list of the Top 10 Mini Projects in c/c++ you can choose any one of them. The source code of all projects is also available. All the projects are compiled in gcc compiler with code::blocks IDE so some projects may create errors in different compilers like Turbo c/c++. If you are using Turbo c then choose another compiler it is an old compiler. The best one is the gcc/g++ compiler for c and C++.
All projects are collected by my college friends and me. Some of the projects are also edited to run in gcc compiler with code::blocks IDE from other websites. For your query and suggestion send me mail at smokindinesh@gmail.com.
 Projects in C++ 
  1. Student database system
  2. Hang Man
  3. School Fee Enquiry Management System
  4. Supermarket Billing System
  5. 3D Bounce in OpenGL
  6. Bus Reservation System
  7. Puzzel Game in wxWidget
  8. Data Exchange between Notepad and Excel (Visual C++)
  9. Employee's Management System

Projects in c
  1. Quiz Game 
  2. Contacts Management   
  3. Personal Dairy Management System  
  4. Library management
  5. Snake Game
  6. Department store system
  7. Tic-tac-toe game
  8. Telecom Billing Management System
  9. Bank Management System
  10. Medical Store Management System