MINI P Suraj
MINI P Suraj
MINI P Suraj
(Mini Project)
Title :
Implementation of openGL functions in mini project.
Aim :
Design and implement game / animation clip / Graphics Editor using open source
CO Mapped : CO 4, Co 5
Pre-requisite :
1. Basic programming skills of C++ and OpenGL
Theory:
OpenGL Basics:
platform (platform independent) API for rendering 2D and 3D Vector Graphics (use of
rendering software package, available across all platforms. It can be used in a range of
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
Associated Libraries:
The earliest version is released with a companion library called
OpenGL utility library. But 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
Implementation:
Mesa 3D is an open source implementation of OpenGL. It can do pure software
rendering and it may also use hardware acceleration on BSD, Linux, and other platforms
(e.g., glColor, glVertex, glTranslate, glRotate). The Core OpenGL models an object via a set of
(such as qradric surfaces). GLU functions start with a prefix "glu" (e.g., gluLookAt,
gluPerspective)3.
OpenGL Utilities Toolkit (GLUT):
provides support to interact with the Operating System
(such as creating a window, handling key and mouse inputs); and more building models
(such as sphere and torus). GLUT functions start with a prefix of
"glut"
gcc filename.c -lGL -lGLU -lglut where filename.c is the name of the file
OpenGL Overview of an
OpenGL program
• Main
• Open window and configure frame buffer (using GLUT for example)
• Loop
• Check for events if window event (resize, unhide, maximize etc.) modify the viewport and
Redraw else if input event (keyboard and mouse etc.) handle the event (such as move the
Redraw
• Render
• Use OpenGL to
OpenGL Syntax
• All functions have the form: gl*
• glVertex3f() – 3 means that this function take three arguments, and f means that the type
• glVertex2i() – 2 means that this function take two arguments, and i means that the type of
OpenGL states
▪ On/off (e.g., depth buffer test)
▪ glEnable( GLenum ) ▪
glDisable( GLenum )
Examples:
▪ glEnable(GL_DEPTH_TEST);
▪ glDisable(GL_LIGHTING);
• Mode States
Examples: glShadeModel(GL_FLAT) or
Drawing in 3D
➢ Depth buffer (or z-buffer) allows scene to remove hidden surfaces. Use
➢ GL_POINT, GL_FILL
➢ glCullFace( Mode )
➢ glFrontFace( Vertex_Ordering )
Viewing transformation
• glMatrixMode ( Mode )
• glLoadIdentity()
• glTranslate3f(x,y,z)
• glRotate3f(angle,x,y,z)
• glScale3f(x,y,z)
OpenGL provides a consistent interface to the underlying graphics hardware. This
abstraction allows a single program to run a different graphics hardware easily. A program
written with
OpenGL can even be run in software (slowly) on machines with no graphics acceleration.
OpenGL function names always begin with gl, such as glClear(), and they may end with
characters that indicate the types of the parameters, for example glColor3f(GLfloat red,
GLfloat green, GLfloat blue) takes three floating-point color parameters and
floating-point values. OpenGL constants begin with GL, such as GL DEPTH. OpenGL also
uses special names for types that are passed to its functions, such as GLfloat or GLint, the
corresponding C types are compatible, that is float and int respectively. GLU is the OpenGL
utility library. It contains useful functions at a higher level than those provided by OpenGL,
for example, to draw complex shapes or set up cameras. All GLU functions are written on
top of OpenGL. Like OpenGL, GLU function names begin with glu, and constants begin with
GLU. GLUT, the OpenGL Utility Toolkit, provides a system for setting up callbacks for
interacting with the user and functions for dealing with the windowing system. This
abstraction allows a program to run on different operating systems with only a recompile.
Glut follows the convention of prepending function names with glut and constants with
Glut.
Graphics Mode:
Screen is divided into pixels. While working in C programming language,
default output mode is text mode. To draw graphics objects on screen display
mode must be changed from text mode to graphics mode. To change from text
program
initgraph() function is used to change from text mode to graphics mode. The
graphics, driver and graphics mode are the parameters to this function,
detectgraph() fiction is used to find out the graphics driver and graphics
mode.
4. line (int x1.int y1int x2,int y2) ; line function is used to draw a line from
Circle function is used to draw a circle with canter (x, y) and radius of a circle.
Rectangle function is used to draw a rectangle. Coordinates of left top and right
7. ellipse (int x, int y, start angle, end angle, int x radius, int y radius);
Ellipse function is used to draw ellipse with center(x, y) starting angle, end
Algorithm :
1. Start
6. . Draw the circle for left wheel of car using circle function
7. Draw the circle for right wheel of car using circle function
8.draw the line Line left of left wheel using line function
10 draw other parts of car and increase the x coordinates of both wheel to run the car.
11. Stop
Assignment No. 8: Car Animation Mini project
Batch: B3
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h> void
main()
{
int gd=DETECT,gm,i;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
outtextxy(175,150,"); outtextxy(175,170,"*********
330, 50 + i, 330);
// Line middle of both wheel
delay(100);
setcolour(BLACK);
+ i, 330);
getch();