Monday, November 21, 2011

Draw a 3D Chess Board using OpenGL utility toolkits (GLUT), a graphics project with source code

This program  may help you in graphics project of your college.I simply  tries to draw the 3D Chess Board.  For this our main goal is to draw white and black rectangular box alternately along both x and y-axis.Drawing rectangular box is simple ,it is drawn by providing all side co-ordinates with the help of glVertex3f function and only top face is assign with black or white color and other face with brown color with the help of glColor3f function. I have made two function void draw_BlackArea() and void draw_whiteArea() to draw black and white square box respectively .Inside two for loop I have call these function by creating displaylist and with the help of glTranslatef(GLfloat x,GLfloat y,GLfloat z) function I draw  alternatively by translating their position.

Tuesday, November 15, 2011

Draw Reflection of Object on the floor using OpenGL Utility Toolkit (GLUT)

Drawing reflection capture the extra realism of the Object in 3D programming.For example Bouncing ball having its reflection on the floor can make the bouncing scenario more beautiful and realistic. So,OpenGL has all the features needed to render fast high-quality reflections on planar surfaces.
        Reflection technique is not so hard its pretty simple.If you want to draw reflection on floor then suppose your floor is in x-z plane and your object along positive y-axis above the plane then for reflection of object draw the copy of object along the negative y-axis vertically below the plane or floor.Your floor must look like the reflecting surface to see the object which is below the floor for this we use alpha blending which make the floor transparent by certain percent say 40% then it is specified to be 40% the color of the floor and 60% the color of the reflection or object.But only alpha blending doesn’t make the reflection real because the reflected copy of the object may leak outside or bottom of the floor so to fixed this problem we actually going to use the stencil buffer concept.With OpenGL stenciling, we can "pre-draw" the floor into the stencil buffer without updating the color or depth buffers. Then when we go to draw the reflection,  just only allow the reflection to update pixels marked as belonging to the floor's stencil value. The floor can then be any complex (but coplanar) polygon and the reflection only shows up in the floor.

Drawing a Bitmapped Character or string in OpenGL sample example

A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window. Suppose you're drawing a bitmap and that the current raster color is red. Wherever there's a 1 in the bitmap, the corresponding pixel is replaced by a red pixel and If there's a 0 in the bitmap, the contents of thepixel are unaffected. The most common use of bitmaps is for drawing characters on the screen.
            In the simple example we use two main function glBitmap and glRasterPos2i function.
The glBitmap function draws a bitmap.

Saturday, November 12, 2011

Rotate an Object in OpenGL(GLUT) sample example with source

In GLUT we rotate the object by glRotate3f(angle_rotation,GLfloat x, GLfloat y ,GLfloat z) function angle_rotation parameter is value of angle to rotate and x,y,z co-ordinate are axis of rotation.But it does not rotate object continuously for that we have to change angle of rotation by small amount of increment. We do this by using timer thread with the help of glutTimerFunc function.Here is the sample source code copy and compile it.

Friday, November 11, 2011

How to change the color of object in OpenGL(GLUT) using keyboard function

If you have problem in changing color of object in OpenGL using keyboard while running program then this article may help you.Simply we can’t change the color of object while running for this we have to create a timer thread by using
Void  glutTimerFunc(unsigned int msecs,void (*func(int value),value)  function or other techinque can also be use.

Number of milliseconds to pass before calling the callback.


The timer callback function.


Integer value to pass to the timer callback.

Saturday, November 5, 2011

TCP Client and Server sample example with source code for Beginners in C#.

Welcome to this page who want to start writing  their own program communication through socket API using C# .Net framework.
The .NET framework provides two classes specifically for TCP: TcpClient and TcpListener.These classes provide a higher level abstraction of the Socket class, but as we will see there are instances when advanced functionality is available only through direct use of the Socket class.

In this article I have shared the simple client server program before but many visitor comment me about bad indentation of code.That's why I removed previous code completely and  started to write the series of article related TCP/IP Socket in C#.
The list of chapter:
1. Basic TCP Socket program
2. Basic UDP Socket program
3. Basic .Net Socket progarm

Note: Chapters in advanced topic will be updated soon.

How to display IPAddress of hosts using c#

This sample program demonstrates the use of the Dns, IPAddress, and IPHostEntry classes. The program takes a list of names or IP addresses as command-line parameters and prints the name and an IP address of the local host, followed by the names and IP addresses of the hosts specified on the command line.
The Dns class has several methods for resolving IP addresses. The GetHostName() method takes no arguments and returns a string containing the local host name. The GetHostByName() and Resolve() methods are basically identical; they take a string argument containing the host name to be looked up and returns the IP address and host name information for the supplied input in the form of an IPHostEntry class instance. The GetHostByAddress() method takes a string argument containing the dotted-quad string representation of an IP address and also returns host information in an IPHostEntry instance.

Friday, October 14, 2011

Simple Multithreading Application sample source code in pure C

In our general program we can’t run two process at same time for e.g we can’t run two for loop at same time.For running two process at same time we need Multithreading.In C we do it by the _beginthread and
_endthread run time  library function.All the above c run time library functions are in the process.h header file.



unsigned long _beginthread(void(* func)(void*), unsigned stack_size, void *arg);


Thursday, October 13, 2011

Generate random number in C++

Random number is generated by using srand(time(NULL)) and rand() function.For time we have to include time.h and for srand() and rand function we have to include stdlib.h.Here is the simple program which generate 10 random number.
#define MAX_NUM 10
using namespace std;

Tuesday, October 11, 2011

Conversion of infix operation to postfix and simple calculator

This code is to convert infix operation to postfix operation .This is the application of stack.Example infix  8*5+(5-3+1) converted to 85*53-1++ and result is 43.This program can be use as a simple calculator where user can calculate any result only in single step.
Copy the code and compile it in codeblock.

Monday, October 10, 2011

Winsock Programming sample project cyber management system.

 Cyber Management System is a program which interconnects different computers which allows users to communicate over the computer network and provide security from unauthorized users by login system in client server.
The project is based on the client server architecture and its communication protocols. The project basically is divided into two sections:- Cyber server and Client server. Not only a single, multiple client can connect to cyber server at any time. Cyber server has the full control over Client server. Client server is password protected user has to login to access internet and other services. New user can signup for username and password. Price rate and services is fixed by cyber server. Client can request any service sending message to cyber server.

Major component

socket API

int socket( int domain , inttype , intprotoco ) ;

Scanning pdf file in hard drive or folder source code in c++

This program use the batch processing.For batch processing we use Frofiles.exe command.
FORFILES [/p Path] [/m Mask] [/s] [/c Command] [/d [+ | -] {dd/MM/yyyy | dd}]   

Parameter List:
    /P    pathname      Indicates the path to start searching.
                        The default folder is the current working directory (.).

    /M    searchmask    Searches files according to a searchmask. The default searchmask is '*' .

    /S                  Instructs forfiles to recurse into subdirectories. Like "DIR /S".

    /C    command       Indicates the command to execute for each file.
                        Command strings should be wrapped in double quotes.

                        The default command is "cmd /c echo @file".

Sunday, October 9, 2011

Playing sound source code in C++

This source code is not for playing songs or sound clips from your hard drive only to play  sound by using windows function Beep(int dwFreq [in],int dwDuration [in]) .
Parameters are
dwFreq [in] 
                    The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767                      (0x25 through 0x7FFF)
 dwDuration [in]
                       The duration of the sound, in milliseconds.
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.
This source code play the music “twinkle twinkle little star” using windows command Beep.Here is the source code copy it and compile and run in code::blocks IDE.

Monday, September 19, 2011

Analog Clock source code using c++ and winBGI graphics

This code does not run directly in code::blocks because winBGIm graphics is for turbo compiler where you can run this code directly and we don’t have to setup library but in code::block you have to setup.To setup WinBGIm graphics library you can see my previous post here .If you setup then now you are ready to compile this code.
Copy the code below and compile it in code::block.While compiling if you got error message in line 320 of graphics.h :” redefination of int right” then change int right=0 to int top = 0.Although,you got other error then leave the message.

How to setup winBGIm library in codeblock

BGI (Borland Graphics Interface) is ancient as is turbo c++ IDE but nevertheless they are still used in our schools and colleges. Plus they do not work in windows environment (support for native DOS has been completely removed in windows vista/7).If you try to compile the source code with including “graphics.h” in code::blocks IDE then is show error because “graphics.h” only run in turbo.For code::blocks you have to setup winBGIm library.
There are many alternative to winBGIm ,But BGI is good for beginners because you don’t have to worry about whole new fancy functions,classes etc.
WinBGIm is BGI graphics library ported to computer by by Michael Main at the University of Colorado.
Before i start, i must tell you that this guide is written in accordance with code::blocks IDE.

Lets get started:
  1. First download WinBGIm from
  2. Extract it.
  3. Copy graphics.h and winbgim.h files in include folder of your compiler directory
  4. Copy libbgi.a to lib folder of your compiler directory
  5. In code::blocks open Settings >> Compiler and debugger >>linker settings
  6. click Add button  in link libraries part and browse and select libbgi.a file
  7. In right part (ie. other linker options) paste commands
  8. -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  9. click Ok
Finally, you can now compile source code using “graphics.h”.You can try this by creating "anlog clock" and you can copy source code from my post  here . The WinBGIm library gives you an alternative as I hope, you found this guide helpful and incase you need my help just leave a message.

Thursday, September 15, 2011

“Contacts Manager” mini project in C with source code

Contacts Manager is a simple mini project code in C.This is similar to contact manager in Mobile phones.You can add contacts,remove contacts,edit contacts,search contacts and view all contacts.Graphics is not used just a console application suitable for learning purpose for beginner and can be used as a reference for college mini project.In this project you learning file handling ,how to write data,delete data and search data form file.I hope my post may help you and you can send email for further help.
Copy the source code below or Download from GitHub and compile it in Code::Blocks.

Create a Matching Game using visual studio

In this tutorial, you build a matching game, where the player must match pairs of hidden icons. You learn how to:
  • Hold objects using a List object.
  • Use a foreach loop in Visual C# or a For Each loop in Visual Basic.
  • Keep track of a form's state using reference variables.
  • Build an event handler that you can use with multiple objects.
  • Make a timer fire exactly once when started.
Copy this code and create project on visual studio or Download complete project from GitHub.

Tuesday, July 12, 2011

Sample Project Math Quiz Game in windows form application

Hi! friends this is another sample project in windows form application.I have created simple Math Quiz Game 
in which players must give answer within 30 seconds.This game may not be suitable to play for entertainment but this is very helpful for reading and creating project in windows form.
     In this tutorial, I build a timed math quiz game, where the player must answer four random arithmetic problems within a specified time. You learn how to:
  • Generate random numbers using the Random class.
  • Trigger events using a Timer control.
  • Control program flow using if else statements.
  • Perform basic arithmetic operations.
In game when player fill all four answer within specific time the message box display's congratulation message if not then display's sorry message.

Here is a source code written in c sharp  copy each block of code and save them in separate file and create new project on windows form application and compile it or Download complete project from GitHub.

Tuesday, July 5, 2011

Sample project Maze game in windows form application source code

Hi! friends this is another sample project in windows form application.I have created simple Maze Game by using only labels and panel.Maze is  design by dragging and dropping in visual studio 2010.I have added start sound and game end sound also.
    In this project, user has to move the mouse pointer from the start to the finish without touching any of the walls. At the end of these project you learn how to:

  • Lay out a form using a Panel container.
  • Build a maze using Label controls.
  • Write code to show a message box.
  • Set up event handlers for mouse events.
  • Play sounds in your program.
  • Organize your code using classes.
Here's how the maze will work: The mouse pointer starts at the upper-left corner of the maze. The user navigates through the maze, being careful not to touch any of the walls with the pointer. If the pointer touches one of the walls, it automatically jumps back to the start. But if the pointer reaches the Finish label at the end of the maze, a "Congratulations" message box opens, and the game ends.

Here is a source code written in c sharp copy each block of code and save them in separate file and create new project on windows form application and compile it or Download complete project from GitHub.

Image viewer in windows form application with visual studio sample project source code

Hi! friends this is another sample project in windows form application.I have created simple image viewer project by using imageBox,checkBox,openFileDialog ,colorDialog and buttons.All these items are design by dragging and droping with visual studio 2010.Here is a source code written in c sharp copy each block of code and save them in separate file and create new project windows form application and compile it.
    In this project you can add additional feature like auto resize of image,adding next button to display next image.
Download complete from GitHub.

|                                  Program.cs                                                            |
|                                                                                                               |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

Thursday, June 30, 2011

Sample Calculator with windows form application in c# sharp using visual studio source code

Hi! friends do you want to learn windows form application in visual studio then this sample calculator project may provide hits and idea about event handling in windows form application.Code is written in c#.Here is there file for this copy one by one or Download complete project from GitHub.
You can also see other sample projects here the lists of other projects.
List of windows form sample projects.

BItmap maping and texture map in OpenGL

This the sample code for texture map in teapot and bit map is used to draw chess board.Code is compiled in codeblocks you can copy and paste this code for your study or project.Please use your own image for texture map.Image must be in bmp formate.

#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
GLuint texture[2];
GLint slices=16;
GLint stacks=16;
struct Image {
    unsigned long sizeX;
    unsigned long sizeY;
    char *data;
typedef struct Image Image;

Saturday, June 25, 2011

wxWidget sample project Puzzel source code

This is interesting game developed using wxWidget graphic library and c++ programming language compiled in gcc compiler with code::blocks IDE. You can download the complete project.At first to run this project you have to setup the wxWidget graphics library in code::blocks. All the instruction for wxWidget setup is given in this article setup wxWidget .You can make this game as your college mini projects.wxWidget is very old and popular GUI graphics library and knowledge of its is very important for student. Other GUI like windows form where you can drag and drops the control directly which make designing easy but we can't understand the actual programming so by using wiWidget we can understand complete GUI design and add the method for event handling.GUI of  Code::Blocks IDE which we use is also design in wxWidget. In this program wxWidget library is used to make a game rather than for GUI.
you can  download sourcecode here all the image file required for the project is also provide.This game is built in code::blocks IDE using C++ with wxWidget library.

Thursday, June 23, 2011

Mini project tic-tac-toe game source code in C

Hi this is a tic-tac-toe game you can copy sourcecode here or Download from GitHub.
#include <windows.h>

Tuesday, June 21, 2011

Mini project Quiz in C

Welcome to Mini Project Quiz in C! This article is about creating a simple quiz game in the C programming language. Target readers of this article are students and absolute beginner C programmer. If you are an experienced C programmer then it is not for you.

You will learn to break down an application into modules (functions), switch between screens based on user input, multi-dimensional array techniques, loops and so much more.

Like in other my sample mini-projects, I have not used a file handling system to store information to make it simple and easy to understand basic techniques.
After finishing this article, you will:

  • Truly understand how to break down the application and create a flow chart.
  • Be able to convert the flow chart processes into C functions.
  • Learn techniques to switch between processes based on user input. 
  • Have mastered the usages of multi-dimensional C array and loops.

You can download the final version of the application from GitHub Download from Github.

I have divided this article into 3 parts:
Part 1: Flow Chart and Main Menu: In this lesson, you will learn to create an application flow chart and create a welcome menu screen of the game.
Part 2: Multi-dimensional C array: In this lesson, you will understand techniques to create a function and switching between multiple functions as per user choice. You will master to use one dimension, two dimensions and three-dimension C array to store questions, question options, and answer. 
Part 3: Gameplay and the final score: You will learn to use a loop to display questions one by one, check the user correct answer and calculate the final score.

mini project Department store source code

This mini project is about department store all features required for department store are added in this programe.You can copy the source code and compile it in a code block.This project is perfect for your college mini project in C. Download Project from Github


#define ANS 15
#define ACS 4
 COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y)
/*declaration of checking functions*/
void c_code(char[]);
int check(char[]);

/*structure declaration*/
typedef struct{
char name[ANS],code[ACS];
float rate;
int quantity;
rec item;

/*declaration of display functions*/
void curser(int);
void dbill();
void d_mainmenu();
void display(rec *,int,int);
void window(int,int,int,int);
void dis_con();
void d_search();
void highlight(int,int);

/*declaration of main menu functions*/
void bill() ;
void edit();
void add();
void del();
void exit();

/*declaration of display submenu functions*/
void d_code();
void d_rate();
void d_quan();
void d_all();

/*start of main*/
int main()
return 0;

Sunday, June 19, 2011

Mini project snake game in c

Mini project in C many Student do management project like library management ,Hotel management etc.But Snake Game is mini project of first semester build by my friend which is very different.It is console application without graphic library that's why it is more interesting.This game is perfect without any error and better user interface.It is complied in code::block using c language.Here goes a source code you can copy and compiled it in code::block.I hope it can help and become a reference for your project. Download Project from Github.

Friday, June 17, 2011

Video game teheran in OpenGL

Teheran is importantor 3D game.You can donwload it source code form this link  download .For teheran you have to use gray code image.All source is written in c++ using OpenGL library.

Mini project "3D Bounce " in OpenGL

This project is my second-year mini-project. I have use the GLUT(OpenGL) library in c++.3D Bounce is a game in which we have to bounce the ball to collect the floating star,after collecting all star then a door opens for the next room. Due to lack of time, I can't complete this project but all image drawing part is completed and I hope you will complete it for your collage project.You can download it source code from this link .This program is written in complete object oriented environment ,I have made different class in different file and It's code is very lengthy so  I can't give source code here.

Wednesday, June 15, 2011

Drawing a snowman using OpenGL source code

This source code is written in c using the OpenGL library. This program is just a demo to draw a different shape object and I draw a man like an object in this program. I have also added a keyboard event in this program.

#include <math.h>
#include <GL/glut.h>
#include <stdio.h>
#include <string.h>
//#include <cstdlib>
//if you got error in exit() by compiler then does not incluede stdlib.h because //exit() is also defined in glut.h file.

float angle=0.0,deltaAngle = 0.0,ratio;
float x=0.0f,y=1.75f,z=5.0f;
float lx=0.0f,ly=0.0f,lz=-1.0f;
int deltaMove = 0,h,w;
int font=(int)GLUT_BITMAP_8_BY_13;
static GLint snowman_display_list;
int bitmapHeight=13;

int frame,time,timebase=0;
char s[30];

void initWindow();

void changeSize(int w1, int h1)

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h1 == 0)
h1 = 1;

w = w1;
h = h1;
ratio = 1.0f * w / h;
// Reset the coordinate system before modifying

// Set the viewport to be the entire window
    glViewport(0, 0, w, h);

// Set the clipping volume
gluLookAt(x, y, z,
     x + lx,y + ly,z + lz,


Sunday, June 12, 2011

Mouse event handling source code in OpenGL

This source code is written in C++ with OpenGL.It is just a demo for mouse event handling you can use this code for your project. In this example void motionPassive(int x, int y) to find out the cursor position in the window. By finding the difference between the previous and initial position the direction of the camera is changed.

Texture map in solid sphere using GLUT(OpenGL)

This source code is written in C used to draw a solid sphere using OpenGL and you can map texture in it. Create a project for OpenGL and copy and paste this code and use your desire image file for texture mapping.


#include <GL/gl.h>
#include <GL/glut.h>
#include <windows.h>
#include <stdio.h>
#include <math.h>
GLuint texture;
double angle = 0;
typedef struct
    int X;
    int Y;
    int Z;
    double U;
    double V;

const double PI = 3.1415926535897;
const int space = 10;
const int VertexCount = (90 / space) * (360 / space) * 4;
GLuint LoadTextureRAW( const char * filename );

Saturday, March 19, 2011

Digital clock source code

All most all game/graphics library provides timing function but If you create a game such as puzzle games or quiz games without graphics then you have to write your own procedure. In C programming language time.h library function is available to access clock time. Here I have provided a sample digital timer application written in C using time.h library function.

#include <stdio.h>
#include <time.h>         //this is header file for time
#include <windows.h>

COORD coord = {0, 0};
void gotoxy (int x, int y)
    coord.X = x;
    coord.Y = y; // X and Y coordinates
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

void delay(unsigned int mseconds)
    clock_t goal = mseconds + clock();
    while (goal > clock());

int main()

    long i = 0;                      /* Loop counter              */
    clock_t now = 0;                 /* Holds initial clock time  */
    int interval = 1;                /* Seconds interval for o/p  */
    int elapsed = 0;
    int min=0,MIN=0,hrs=0,sec=0;
    int d=0,f=0;
    now = clock(); /* Get current clock time    */
    for(i = 0L ;  ; i++)
        elapsed = (clock()-now)/CLOCKS_PER_SEC;

            interval += 1;


    return 0;

Resize and Move Console Window in C/C++ using windows function

This is another article related to the window.h library function. Here I will take you through resizing the console window and moving it on the screen at the desire position. If you are not using any graphics library then you will not have control over the console window easily. Using window.h library function is the only option. Also, I will also like to inform you that we are using windows function so it will not work on Unix/Linux machine.
The sample problem is written in C language and compile in the GCC compiler.

#include <windows.h>
#include <stdio.h>

HWND WINAPI GetConsoleWindowNT(void)
    //declare function pointer type
    typedef HWND WINAPI(*GetConsoleWindowT)(void);
    //declare one such function pointer
    GetConsoleWindowT GetConsoleWindow;
    //get a handle on kernel32.dll
    HMODULE hk32Lib = GetModuleHandle(TEXT("KERNEL32.DLL"));
    //assign procedure address to function pointer
    GetConsoleWindow = (GetConsoleWindowT)GetProcAddress(hk32Lib,TEXT("GetConsoleWindow"));
    //check if the function pointer is valid
    //since the function is undocumented
    if(GetConsoleWindow == NULL){
        return NULL;
    //call the undocumented function
    return GetConsoleWindow();
int main()
    HWND hWnd=GetConsoleWindowNT();

Change console windows background color in code::block

In my earlier article changing text color in codeblock and background color of console, I had provided a sample source code to change text color and text background color using windows.h library function. Similarly, we can also change console windows background color using windows.h library function. Here, I have shared a sample source code to change the console windows background color. The sample program is written in C.

#include <windows.h>          //header file for windows
#include <stdio.h>

void ClearConsoleToColors(int ForgC, int BackC);
int main()
    return 0;
void ClearConsoleToColors(int ForgC, int BackC)
    WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
    //Get the handle to the current output buffer...
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    //This is used to reset the carat/cursor to the top left.
    COORD coord = {0, 0};
    //A return value... indicating how many chars were written
    //   not used but we need to capture this since it will be
    //   written anyway (passing NULL causes an access violation).
    DWORD count;

    //This is a structure containing all of the console info
    // it is used here to find the size of the console.
    //Here we will set the current color
    SetConsoleTextAttribute(hStdOut, wColor);
    if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
        //This fills the buffer with a given character (in this case 32=space).
        FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);

        FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
        //This will set our cursor position for the next print statement.
        SetConsoleCursorPosition(hStdOut, coord);
You can change console windows background color by passing integer value range 0 up-to 256 in ClearConsoleToColors(int ForgC, int BackC) function.

Text background color of console windows using C in code::block

In my earlier article changing text color in codeblocks, I had provided sample source code to change text color using windows.h library function. Similarly, we can also change text background color using windows.h library function. Here, I have shared sample source code to change text background color. The sample program is written in C.

#include <windows.h>
#include <stdio.h>
void SetColorAndBackground(int ForgC, int BackC);
int main()
    SetColorAndBackground(5,1);   //color value range 0 up-to 256
    printf("what is text background color");
    return 0;
void SetColorAndBackground(int ForgC, int BackC)
     WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
You can change text background color by passing integer value range 0 up-to 256 in SetColorAndBackground(int ForgC, int BackC) function. First parameter is for text color and second parameter is for background color.

changing text color in codeblock

Changing text color in console applications created using the GCC compiler in codeblocks is challenging until an unless you use the graphic library. Unlike turbo c/c++ GCC does not provide the function to change text color. If you want to change the text color to make console windows colorful then we can use windows.h library function. Here in this article, I will share sample code to change text color. The sample program is written in C using windows.h library function.

#include <windows.h>         //header file for windows
#include <stdio.h>           //C standard library
void SetColor(int ForgC);
int main()
    printf("test color");
    return 0;
void SetColor(int ForgC)
     WORD wColor;
                          //We will need this handle to get the current background attribute
     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

                           //We use csbi for the wAttributes word.
     if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
                     //Mask out all but the background attribute, and add in the forgournd color
          wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
          SetConsoleTextAttribute(hStdOut, wColor);
you can change your desire text color by passing integer value range 0 up-to 256 in SetColor( ) function.

Thursday, March 17, 2011

gotoxy in code::block

gotoxy(int x, int y) a function available in Turbo C/C++. It is not standard C. This function is used to move the cursor on the screen to the desire location. The top left corner of the monitor is 0,0 and the bottom right corner might be any number based on the size of the screen. But today's standard C++ compiler such as Visual Studio, GCC and clang to not provide gotoxy function. However, if you are developing console applications without a third party graphic library then gotoxy function is useful to manage text alignment on the screen.

If you need similar implementation on a windows machine with GCC compiler then here is an example source code.
#include <windows.h>    //  header file for gotoxy
#include <iostream> //header file for standard input output
COORD coord= {0,0}; // this is global variable
void gotoxy(int x,int y)

int main()
    //calling these function
    int x;
    std::cout<<"1. This is item number one.";
    std::cout<<"2. This is item number two.";
    std::cout<<"3. This is item number three.";
    std::cout<<"4. This is item number four.";
    std::cout<<"5. This is item number five.";
    return 0;
Please watch the video below for details explanation.

Sunday, March 13, 2011

Mini project "library management" in C programming

      This is my college 1st-semester mini-project “library management “ in C programming language. This is a console application without graphics and compiled in code::block with GCC compiler. I hope it will help you to develop your own project similar project related to file handling for example “Banking “,” customer records”,” student records" etc.
I have divided my project into many functions and I will describe each of them which may help you to understand better.

Sunday, February 27, 2011

Setup GLFW 3 library in code::block IDE

GLFW is a free, open-source, multi-platform library for OpenGL and OpenGL ES especially design for game development. OpenGL itself does not provide features to handle window creation and other input, so GLFW is very useful to create the necessary context, manage windows, timing, read and control user input via keyboard, mouse, joysticks and other purposes. There are many other library alternatives to GLFW such as SDL and freeglut but if you are looking best library for 3D game development then GLFW is best. GLFW community is large and very active, at the time of updating this article latest stable version of GLFW is 3.3.2 which is released on January 20, 2020. It comes with documentation, high standard tutorials and guides and lots of test programs.

Here, I will guide you through a step by step procedure to setup GLFW 3 in Codeblocks IDE on Windows 10.

Visit GLFW download page and download 32 bit/64 bit windows binary files from the Windows pre-compiled binaries section. You have to make sure that bit of your C++ compiler and downloaded GLFW library files should match. Currently, GLFW releases are tested with MinGW, MinGW-w64 and Visual C++ 2010 and above version.

Steps to setup GLFW library and create a project in Code::blocks:
  1. Extract downloaded zip file.
  2. Create a folder in any directory and give a name "GLFW" (eg. c:\GLFW).
  3. Browse extracted files in step 1. Copy "include" folder and paste it inside the directory that you have created in step 2. Copy lib folder of corresponding to your compiler for e.g if you are using minGW then copy lib-mingw folder and paste it inside the directory that you have created in step 2 and rename it to lib. Also copy glfw3.dll file from bin folder to "C:\Windows\System32" if you are using 32-bit library files or copy to "C:\Windows\System" if you are using 64-bit library files.
  4. Now, open the code::blocks and go to File -> New -> Project or click create a new project link from the start page.
  5. From the project wizard select "empty project" and click "Go" button and provide all necessary information. Also, do not forget to add main.cpp file.
  6. Go to the menu bar and select project-> Project properties. A dialogue box will appear and click "Project's build options". Another dialogue box will appear and click the "Search directories" tab. Under the "Compiler" tab add the path of GLFW include folder (e.g. c:\GLFW\include) and under "Linker" tab add the path of GLFW lib folder (e.g. c:\GLFW\lib).
  7. Now go to "Linker Setting" tab and add three linker libglfw3.a, libglfw3dll.a and libopengl32.a. Linker libglfw3.a and libglfw3dll.a are available inside GLFW lib folder and libopengl32.a is available inside minGW compiler lib folder.
Copy and paste below code in main.cpp file and compile it to verify GLFW library setup.

#define GLFW_DLL
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdexcept>

GLFWwindow* window = NULL;
GLFWmonitor* monitor = NULL;

int main(int argc, char *argv[]) {

    throw std::runtime_error("glfwInit failed");

    window = glfwCreateWindow(800, 600, "test window",NULL, NULL);
        throw std::runtime_error("glfwOpenWindow failed.");

   // GLFW settings

    // process pending events
       glClearColor(1, 0, 0, 1); // black
   // clean up and exit
    return 0;

You have to make sure to define GLFW_DLL  and include glfw3.h header always on top of your source code as shown in the above sample code otherwise the compiler will throw undefine reference error.

You can follow the video below for details:

Friday, February 25, 2011

Setup Code::blocks in Windows 10 and It's Features



  • Open Source! GPLv3, no hidden costs.
  • Cross-platform. Runs on Linux, Mac, Windows (uses wxWidgets).
  • Written in C++. No interpreted languages or proprietary libs needed.
  • Extensible through plugins


  • Multiple compiler support:
    • GCC (MingW / GNU GCC)
    • MSVC++
    • Digital Mars
    • Borland C++ 5.5
    • Open Watcom
    • ...and more
  • Very fast custom build system (no makefiles needed)
  • Support for parallel builds (utilizing your CPU's extra cores)
  • Multi-target projects
  • Workspaces to combine multiple projects
  • Inter-project dependencies inside a workspace
  • Imports MSVC projects and workspaces (NOTE: assembly code not supported yet)
  • Imports Dev-C++ projects

Tuesday, February 22, 2011

Setup wxWidget in code::block

TO create Wxwidget Project in code::block, at first you have to download the wxPack_v2.2.10.06.exe windows installer from this website windows.

Let's create Wxwidget project
step 1:
run .exe file that you have downloaded
Click next

Setup OpenGL(glut) in code::block

Download the glut library from the website for windows.

Steps to create glut project in Code::block.
Step 1: Extract the downloaded zip file.

Step 2: Browse extracted files. Copy the glut.h file and paste it into the directory "C:\ProgramFiles(x86)\CodeBlocks\MinGW\include\GL". Copy glut.lib file and paste it into the directory "C:\Program Files(x86)\CodeBlocks\MinGW\lib". Also, copy the glut.dll and paste it into
the directory "C:\Windows\System32".

Monday, February 21, 2011

Setup SDL 2 in code::block

Setup SDL 2 in Code::Blocks (modern version)

The latest stable version of SDL (Simple DirectMedia Layer) is 2.0.10 at the time of updating this article. Unlike SDL 1.2, SDL 2 utilizes GPU memory and provides features to develop high-performance games and applications. Also, it includes easy access to graphics, sound and input handling.  
Here, I will guide you through a step by step procedure to setup SDL 2 in Codeblocks IDE on Windows 10.

Visit SDL download page and download the file "SDL2-devel-2.0.10-mingw.tar.gz (Mingw32)" from the Development Libraries section for your respective machine Win32/Linux. If you are using Visual C++ compiler in Code:blocks then download another file for Visual C++. Required links are highlighted in the screenshot below:

Steps to create SDL 2 project in Code::blocks:
  1. Extract downloaded zip file.
  2. Create a folder in any directory and give a name "SDL 2" (eg. c:\SDL 2).
  3. Browse extracted files in step 1. Copy "include" and "lib" folders and paste it inside the directory that you have created in step 2. Also, copy SDL.dll file from bin folder to "C:\Windows\System32" if you are using 32-bit library files or copy to "C:\Windows\System32" if you are using 64-bit library files.
  4. Open the code::blocks and go to File -> New -> Project or click create a new project link from the start page.
  5. From the project wizard select "empty project" and click "Go" button and provide all necessary information. Also, do not forget to  add main.cpp file.
  6. Go to menu bar and select project-> Project properties. A dialogue box will appear and click "Project's build options". Another dialogue box will appear and click the "Search directories" tab. Under "Compiler" tab provide the path of SDL include folder (e.g. c:\SDL2\include) and under "Linker" tab provide the path of SDL lib folder (e.g. c:\SDL2\lib).
  7. Now go to "Linker Setting" tab and inside "Other linker options" text box add three linkers "-lmingw32", "-lSDL2main" and "-lSDL2"
  8. Copy and paste below code in main.cpp file and compile it to verify SDL setup.  

#include <SDL2\SDL.h>
#include <iostream>
//Screen dimension constants
const int SCREEN_WIDTH = 640,SCREEN_HEIGHT= 480;

int main( int argc, char* args[] ){
 SDL_Window* window = NULL;  //The window we'll be rendering to
 SDL_Surface* screenSurface = NULL;  //The surface contained by the window
 //Initialize SDL
 if( SDL_Init( SDL_INIT_VIDEO ) < 0 ){
  std::cout<<"SDL_Error: %s\n"<<SDL_GetError()<<std::endl;
  //Create window
  if( window == NULL ){
   std::cout<<"SDL_Error: %s\n"<<SDL_GetError()<<std::endl;
   screenSurface = SDL_GetWindowSurface( window ); //Get window surface
   SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0x00, 0xFF, 0xFF ) );
 //Fill the surface with color
   SDL_UpdateWindowSurface( window ); //Update the surface
   SDL_Delay( 2000 ); //Wait two seconds
 SDL_DestroyWindow( window ); //Destroy window
 SDL_Quit();  //Quit SDL subsystems
 return 0;

You can follow the video below to know the steps in detail:

Setup SDL 1.2 in Code::Blocks (old version)
Visit SDL download page and download the file "SDL-devel-1.2.15-mingw32.tar.gz (Mingw32)" from the Development Libraries section for your respective machine Win32/Linux. If you are using Visual C++ compiler in Code:blocks then download another file for Visual C++. Required links are highlighted in the screenshot below:

Steps to create SDL 1.2 project in Code::blocks:
  1. Extract downloaded zip file.
  2. Create a folder in any directory and give a name "SDL 1.2" (eg. c:\SDL 1.2).
  3. Browse extracted files in step 1. Copy "include" and "lib" folders and paste it inside the directory that you have created in step 2. Also, copy SDL.dll file from bin folder to "C:\Windows\System32" folder.
  4. Open the code::blocks and go to File -> New -> Project or click create a new project link from the start page.
  5. From the project wizard select "SDL project" and click "Go" button and provide all necessary information.

After creating a project, built and run the default program.

You can follow the video below to know the steps in detail: