Oopcgl Mini Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

OOPCGL MINI PROJECT REPORT

Introduction:
The main purpose of this mini project is to understand the how to use the graphics files and OpenGL to make
amazing animations and games.

OPENGL BASICS:
Open Graphics Library (OpenGL) is a cross-language (language independent), cross-platform (platform
independent) API for rendering 2D and 3D Vector Graphics (use of polygons to represent image). OpenGL is a
low-level, widely supported modeling and rendering software package, available across all platforms. It can be
used in a range of graphics applications, such as games, CAD design, or modeling. OpenGL API is designed
mostly in hardware.
Design: This API is defined as a set of functions which may be called by the client program. Although functions
are similar to those of C language but it is language independent.
Development: It is an evolving API and Khronos Group regularly releases its new version having some
extended feature compare to previous one. GPU vendors may also provide some additional functionality in the
form of extension.
Associated Libraries: The earliest version is released with a companion library called OpenGL utility library.
Since OpenGL is quite a complex process. So in order to make it easier other library such as OpenGL Utility
Toolkit is added which is later superseded by freeglut. Later included library were GLEE, GLEW and glbinding.

ABOUT OUR PROJECT:


Our project includes fun game about guessing which card number it is.
This game is designed such that it shuffles three cards and the player has to keep a watch oh highlighted card.
When the shuffling stops, the player is asked, ‘Which card number is it?’. So the user has to enter the card
number.
After entering the console will show whether number guessed by the user is right or wrong.
For correct answer it displays ‘Hurray’ and for wrong answer it will display ‘You are dumbo’.
And program will end.

ABOUT HEADER FILES AND OTHER FUNCTIONS USED:


1.Graphics h
The graphics.h header file provides access to a simple graphics library that makes it possible to draw lines,
rectangles, ovals, arcs, polygons, images, and strings on a graphical window.
The second step is initialize the graphics drivers on the computerusing initgraph method of graphics.

2.<conio.h>
The conio.h header file used in C programming language contains functions for console input/output.
Some of its most commonly used functions are clrscr, getch, getche,kbhit etc. They can be used to clear
screen, change color of text and background, move text, check whether a key is pressed or not and to perform
other tasks.

3.<iostream.h> is a header file of c++ program , it’s stands for input output system.
It contains declaration for the identifier cout and cin.

4. <dos.h>
The header file <dos. h> was created to facilitate calls to System API and the OS, so that programmers could
use system calls such as delay (int) or sleep (int) in their programs.
5..Stdlib.h
Standard Library
The header file stdlib. h stands for Standard Library.
It has the information of memory Dynamic Memory allocation and other Standard Functions. ... The getch()
function requires the stdlib header to be Included.

6. time.h
The time.h header file contains definitions of functions to get and manipulate date and time information.
It describes three time-related data types.

7. clock_t: clock_t represents the date as an integer which is a part of the calendar time.
time_t: time_t represents the clock time as an integer which is a part of the calendar time.
struct tm: struct tm holds the date and time
It also contains CLOCKS_PER_SEC macro which holds the number of times does the system clock ticks per
sec.

CODE:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<time.h>

void swap(char [],char []);

int card1[] = { 20,20 , 50,20 , 50,100 , 20,100 , 20,20 };


int card2[] = { 80,20 , 110,20 , 110,100 , 80,100 , 80,20 };
int card3[] = { 140,20 , 170,20 , 170,100 , 140,100 , 140,20 };

char val[3][2]={ "1" , "2", "3" };

void main()
   {
   clrscr();
   char count[2]="0";
   int swapnum=0;         //for number of times to swap the cards
   int driver,mode;

   driver=DETECT;

   initgraph(&driver , &mode , "c:\\tc\\bgi");

   setfillstyle(SOLID_FILL,YELLOW);
   fillpoly(5,card1);
   fillpoly(5,card2);
   fillpoly(5,card3);
   settextstyle(GOTHIC_FONT,HORIZ_DIR,6);
   setcolor(BLUE);
   moveto(25,25);
   outtext(val[0]);
   moveto(85,25);
   outtext(val[1]);
   moveto(145,25);
   outtext(val[2]);

   do
      {
      int num=0;
      int choice[2];
      count[0]++;

      delay(1500);

      settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
      moveto(20,150);
      outtext("No. of Times Cards have been swapped:");
      settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
      moveto(20 + swapnum*20,170);
      outtext(count);
      setfillstyle(SOLID_FILL,YELLOW);
      fillpoly(5,card1);
      fillpoly(5,card2);
      fillpoly(5,card3);

      do
     {
     randomize();
     choice[num]= (rand() + num) % 3;

     switch(choice[num])
        {
        case 0:
           setfillstyle(CLOSE_DOT_FILL,BLUE);
           fillpoly(5,card1);
           break;
        case 1:
           setfillstyle(CLOSE_DOT_FILL,BLUE);
           fillpoly(5,card2);
           break;
        case 2:
           setfillstyle(CLOSE_DOT_FILL,BLUE);
           fillpoly(5,card3);
           break;
        }
     num++;
     }while(num<2);
      swap(val[(choice[0])],val[(choice[1])]);

      }while(swapnum++ < 6);

   settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
   moveto(20,200);
   outtext("What is card number 2");
   char ans;
   ans=getch();
   if(ans==val[1][0])
      {
      moveto(20,230);
      outtext("HURRAY");
      }
   else
      {
      moveto(20,230);
      outtext("YOU DUMBO");
      }

   getch();
   closegraph();
   }

void swap(char a[], char b[])


   {
   char c;
   c=a[0];
   a[0]=b[0];
   b[0]=c;
   }
OUTPUT:

Case 1:
In case if user is able to detect the position of card after shuffling then he
will get a message as “HURRAY’
Case 2:
In case if user is not able to detect the position of card after shuffling then
he will get a message as “YOU DUMBO”

PROJECT BY:

1.Nisha Gawai
Roll number: SECO2122A059

2.Rushikesh Rathod
Roll number: SECO2122A066

3.Shrinidhi Kukde
Roll number:SECO2122A069

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy