Thursday, June 30, 2011

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;

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<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <windows.h>

Tuesday, June 21, 2011

Mini project Quiz in C

Welcome to the Mini Project Quiz in C! This article is about creating a simple quiz game in the C programming language. The target readers of this article are students and absolute beginner C programmers. 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 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 arrays 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 how to use one-dimensional, two-dimensional, and three-dimensional C arrays to store questions, question options, and answers. 
Part 3: Gameplay and the final score: You will learn to use a loop to display questions one by one, check the user's correct answer, and calculate the final score.

You can also watch a video about this project on YouTube.



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


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>

#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)
{
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
/*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;
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()
{
d_mainmenu();
return 0;
}

Monday, June 20, 2011

Mini project snake game in c

Mini project Snake game in C is console application created without graphic. We draw game window, and snake only using Asterix character and zero character to draw food. User can play game using up, left, right, and down arrow key. The score is calculated based on the number of foods eaten by snake. The main objective of this project is to provide knowledge and technique about creating snake game in C programming. User can use any graphics library to draw window, snake and food to make it similar to commercial games. However, the code base and algorithm of the game is same in all snake game available in market. I have separated game drawing source code and snake game paly source code so that you can use any graphics library Easily and quickly. 

In this article, I will explain the following items:
  • Flowchart of the game
  • Data Structure and Algorithm
  • Techniques to move snake direction
  • Calculating snake next coordinate
  • Collision detection
  • Techniques to display moving snake and game play
Also, Download the final version of game Download Project from Github.

I have explained the game in following two articles:




Friday, June 17, 2011

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 http://www.4shared.com/file/J-cjGaN-/bounce.html .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
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

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

// Set the clipping volume
gluPerspective(45,ratio,0.1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x, y, z,
     x + lx,y + ly,z + lz,
 0.0f,1.0f,0.0f);


}