Вы находитесь на странице: 1из 26

Terna Engineering College

Computer Engineering Department


Program: Sem IV

Course: Computer Graphics

Faculty: sneha bendale

LAB Manual

PART A

(PART A : TO BE REFFERED BY STUDENTS)

Experiment No.11

A.1 Aim:

Study and apply basic opengl functions to draw basic primitives.Implement sierpinsky
gasket using openGL.

A.2 Prerequisite:
1. C Language.
2. Geometric Concepts.
3. Concept of 2D and 3Dbasic Transformations.
4. Projection Concepts.

A.3 Outcome:
After successful completion of this experiment students will be able to,

Apply OpengL

A.4 Theory and Procedure:


Installation and Execution Procedure for Visual Studio C++ 2010 Express

- Configuring OpenGL on Microsoft Windows and Higher


Step1:
Download and install Microsoft Visual C++ 2010 Express edition from http:
//www.microsoft.com/express/.
Step 2:
After Visual C++ has been successfully installed, do the following.
Install GLUT
1. Download and unzip the _le glut-3.7.6-bin.zip from http:
//www.xmission.com/~nate/glut.html.
OR
Download it from the link given below:
http://en.osdn.jp/projects/sfnet_colladaloader/downloads/colladaloader/colladaloader
%201.1/glut-3.7.6-bin.zip/

(a) Copy glut32.dll to C:\Windows\System32.


(b) Copy glut32.lib to C:\Program Files\Microsoft Visual Studio
10.0\VC\lib
(c) Copy glut.h to C:\Program Filesn\Microsoft Visual Stu-dio
10.0\VC\include\GL. Note that you may have to create the GL
directory.
Step 3:
Open Visual C++ 2010 from the Start Menu to bring up the welcome
screen.
Step 4:
Create a new project by going to File!New!Project.

Step 5:
Select Win32 from the Installed Templates panel and then Win32 Console
Application from the next panel. Name your project and select the folder where you
want to save it. Uncheck the box which says \Create directory for solution". Click OK to
bring up a wizard welcome window.
Step 6:
Click Application Settings for the settings dialog box.

Step 7:
Uncheck the Precompiled header box, check the Empty project box and choose
Console application. Click Finish to see a new project window.
Step 8:
Right click on Source Files and choose Add ! New Item to bring up a dialog box.
Step 9:
Select Code from the Installed Templates panel and C++ File(.cpp) from the next
panel. Name your file and click Add to see an empty code panel in the project window
titled with your chosen name. or write your own program in the code panel.
Step 10:
Save and build your project by going to Debug ! Build Solution.Then execute the
program with Debug ! Start Debugging. If the program has been built successfully, then
you should see no error in the output window.
Failure case handling method
If the build process of program is failed then do the following steps

-Select the project Properties

-Select Configuration properties

-Select Linker in panel

-Convert Enable Incremental linking to No

-Again Save and Build the project

-Execute the program for output window


PART B

(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the
concerned lab in charge faculties at the end of the practical in case the there is no
Black board access available)

Roll No. C14 Name: Pawan Bhadouria


Class : SE_Comps Batch : C1
Date of Experiment: Date of Submission:
Grade :
B.1 Document created by the student:

#include <Windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>

void display(void)
{
/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT);

/* draw Basic Primitives.point,line,triangle,polygon


*/
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POINTS);
glVertex2f (0.20, 0.20);
glVertex2f (0.80, 0.20);
glVertex2f (0.80, 0.80);
glVertex2f (0.20, 0.80);
glEnd();

glColor3f (0.0, 1.0, 1.0);


glBegin(GL_LINES);
glVertex2f (0.20, 0.20);
glVertex2f (0.20, 0.80);
glEnd();

glColor3f (0.0, 0.0, 1.0);


glBegin(GL_POLYGON);
glVertex2f (0.25, 0.25);
glVertex2f (0.75, 0.25);
glVertex2f (0.75, 0.75);
glVertex2f (0.25, 0.75);
glEnd();

glColor3f (1.0, 0.0, 1.0);


glBegin(GL_TRIANGLES);
glVertex2f (0.40, 0.40);
glVertex2f (0.60, 0.40);
glVertex2f (0.60, 0.60);
glEnd();

glFlush ();
}

void init (void)


{
/* select clearing (background) color */
glClearColor (0.0, 0.0, 0.0, 0.0);

/* initialize viewing values */


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}

OUTPUT:

#include<GL/glut.h>
int Height=650,Width=650;

struct GLintPoint
{
GLint x,y;
};
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

void myinit()
{
glClearColor(0.0,0.0,0.0,1.0);
glColor3f(1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,650.0,0.0,650.0);
}

void myKeyboard(unsigned char key, int mouseX, int mouseY)


{
switch(key)
{
case 75 : exit(0);
}
}

void myMouse(int button,int state,int x,int y)


{
static GLintPoint vertex[1];
static int pt=0;

if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)


{
if(pt==0)
{
vertex[pt].x=x;
vertex[pt].y=Height-y;
pt++;
}
else
{
glBegin(GL_LINE_STRIP);
glVertex2i(vertex[0].x,vertex[0].y);
glVertex2i(x,Height-y);
glEnd();

vertex[0].x=x;
vertex[0].y=Height-y;
}

glFlush();
}

int main(int argc,char **argv)


{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Event Driven Demo");
glutDisplayFunc(display);
glutKeyboardFunc(myKeyboard);
glutMouseFunc(myMouse);
myinit();
glutMainLoop();
return 0;
}

Output:
B.3 Observations and learning:

1. Driver development/ driver support

According to manufacturers, the driver development for professional graphics cards is


subject to special considerations in terms of quality, stability and reliability. You can also
get special performance drivers or specifically certified versions depending on the
software and hardware. Those ensure the perfect combination of hardware and
software in productive professional environments and therefore reduce outages and
waiting times.

2. Extendibility

Graphics card manufacturers have the possibility to extend the interface with further
functions. Special commands can be executed directly, instead of having to take a
detour over an emulator with this (very important in the CAD field). This influences the
functionality, velocity and stability.

3. Platform independency

OpenGL is independent of platform and programming language. Hence, it’s simple to


convert for various systems. OpenGL is, for instance, a part of MS Windows, MacOS,
Linux, Solaris, and many more.

Due to this advantage, OpenGL is mainly found in the professional field of Windows. In
opposition, the opponent dominates the computer-gaming division in which OpenGL
only plays a subordinate role. OpenGL is primarily used in various game consoles (Xbox
360, PlayStation 2/3) and in MacOS game software in the gaming field.

B.4 Conclusion:

Thus we have successfully executed basic programs in openGL.

B.5 Question of Curiosity

Q.1]Explain Different commands in OpenGL.

Ans:

GLUT, the OpenGL Utility Toolkit. As you know,OpenGL contains


rendering commands but is designed to be independent of any window system or
operating system. Consequently, it contains nocommands for opening windows or
reading events from the keyboard or mouse. OpenGL commands use the prefix gl and
initial capital letters for each word making up the command name such as glBegin().
Similarly, OpenGL defined constants begin with GL_, use all capital letters, and use
underscores to separate words such as GL_COLOR_BUFFER_BIT.
Some OpenGL command names have a number and one, two, or three letters at
the end to denote the number and type of parameters to the command. The first
character indicates the number of values of the indicated type that must be
presented to the command. The second character or character pair indicates the
specific type of the arguments: 8-bit integer, 16-bit integer, 32-bit integer, single-
precision floating-point, or double-precision floating-point. The final character, if
present, is v, indicating that the command takes a pointer to an array (a vector)
of values rather than a series of individual arguments.
For example, in the command glVertex2i(), `2' is used to indicate three arguments
and `i' is used to indicate that the arguments are integers. The letters and
numbers used in the suffixes for the ANSI C implementation are shown below.

o Number Of Arguments: 2, 3, or 4

o Data Types:
 `f' float
 `d' double float
 `s' signed short integer
 `i' signed integer
 `b' character
 `ub' unsigned character
 `us' unsigned short integer
 `ui' unsigned integer
o Formats:
 `v' indicates vector format
 absence of `v' indicates scalar format

Throughout this tutorial, OpenGL commands will be referred to by their base


names only, and an asterisk will be included to indicate that there may be a suffix
to the command name such as glColor*().
A complete set of man pages for OpenGL commands is maintained by Sun
Microsystems and can be found
at http://www.sun.com/software/graphics/OpenGL/manpages. Some of the
features described in these man pages are specific to Sun's implementation of
OpenGL.

************************

Оценить