Saturday, April 28, 2012

Texture mapping in SharpGL (OpenGL in C#) sample program for windows form

At first you have to setup the SharpGL in Visual Studio for that you can follow my previous articles create SharpGL project in c# .
OpenGL bind the texture form the texture memory which do not store arbitrary images but a texture has specific constraints on the images. So,OpenGL function for texture is same whatever be the library we used for e.g GLUT,SharpGL,GLFW only the difference is how we load the images on the texture memory. These images are store in different file format , which required the program to decode and load the images form file into texture memory and this is painful effort for the programmer to write there own decoding and loading code.
In GLUT  texture  mapping example is shown in this article Texture mapping in GLUT where you can see BMP image is loaded at first in the memory and that texture memory data is used by OpenGL function for texture mapping but in GLFW we don’t have to write code for loading image from file it provide the built in function for loading image from a Truevision Targa format file (.TGA) and here is the sample project Texture in GLFW.
Now in SharpGL texture is not so difficult. We can create the Bitmap object by loading BMP image file and all the information of image can be used with this Bitmap object.

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.

Saturday, April 21, 2012

Create SharpGL/OpenGL for C# Project in windows form application

SharpGL is a C# OpenGL Class library . SharpGL 2.0 is a powerful library that allows you to use OpenGL in your managed applications. Some of the top features are:
  • Full support for all OpenGL functions up to OpenGL 4.2
  • Full support for all commonly used OpenGL extensions
  • Support for WinForms applications
  • Support for WPF applications (without resorting to WinForms hosts)
  • A powerful scene graph including polygons, shaders, NURBs and more
  • Many sample applications as starting points for your own projects.
  • Visual Studio Extension with SharpGL project templates for WPF and WinForms.
Its Class libraries are
  • SharpGL - Contains the main OpenGL object - this object wraps all OpenGL functions, enumerations and extensions.
  • SharpGL.SceneGraph - Contains all wrappers for OpenGL objects and Scene Elements - Lights, Materials, Textures, NURBs, Shaders and more.
  • SharpGL.WinForms - Contains Windows Forms Controls for your applications.
  • SharpGL.WPF - Contains WPF Controls for your applications.
  • SharpGL.Serialization - Contains classes used to load geometry and data from 3D Studio Max files, Discreet obj files and trueSpace files.

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.
glTranslatef( xValue, yValue, zValue );
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 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 in project topic then don’t worry here is the list of Top 10 Mini Projects in c/c++ you can choose any one of them. 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 error in different compiler like Turbo c/c++. If you are using Turbo c then choose another compiler it is old compiler. Best one is gcc/g++ compiler for c and c++.
All projects are collected by college friends and me. Some of the project are also edited to run in gcc compiler with code::blocks IDE from other website. For your query and suggestion send me mail at
 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.Libray management
2.Snake Game
3.Quize Game
4.Department store system
5.Tic-tac-toe game
6.Personal Dairy Management System
7.Telecom Billing Management System
8.Bank Management System
9.Contacts Management
10.Medical Store Management System

Project on C# Windows Form Application
1. List of C# Windows Form Projects

visible surface detection z-buffer algorithm in computer Graphics sample source code

This article is extension of my previous articles Projecting a 3D world co-ordinates into 2D perspective where I have drawn wireframe cube in perspective view. If we want to draw a solid object then we must decide the visible surface to render. The surface/object which we render at last that will display on screen irrespective of depth and can overwrite the nearest surface/object. So, we must implement the special method to find  out the visible surface and one of them is z-buffer method.
z-buffering is the management of image depth coordinates in three-dimensional (3-D) graphics, usually done in hardware, sometimes in software. It is one solution to the visibility problem, which is the problem of deciding which elements of a rendered scene are visible, and which are hidden. The painter's algorithm is another common solution which, though less efficient, can also handle non-opaque scene elements. Z-buffering is also known as depth buffering.
When an object is rendered, the depth of a generated pixel (z coordinate) is stored in a buffer (the z-buffer or depth buffer). This buffer is usually arranged as a two-dimensional array (x-y) with one element for each screen pixel. If another object of the scene must be rendered in the same pixel, the method compares the two depths and chooses the one closer to the observer. The chosen depth is then saved to the z-buffer, replacing the old one. In the end, the z-buffer will allow the method to correctly reproduce the usual depth perception: a close object hides a farther one. This is called z-culling.