Tuesday, July 3, 2012

A brief Overview about openGl:

                      OpenGL was developed by the open minded developers in 1982. It was initially called as iris GL. It can be used as an alternative for Microsoft's directX. Today, OpenGL is managed by the Khronos Group -- a non-profit organization with representatives from many companies that are interested in maintaining high-quality media APIs. At a lower level, it's managed by the OpenGL Architecture Review Board (ARB). OpenGL is supported on every gaming platform, including Mac, Windows, Linux, PS3 (as a GCM wrapper), Wii, iPhone, PSP, and DS. Well, every gaming platform except for the XBox.

                       Microsoft gave a powerful blow to the openGL. It wanted to have full market share in gaming world. Fortunately openGL is recovering back and the games produced by openGL are very clear and much advanced than directX. The preview has been given here. You can compare the openGL and DirectX yourself.

OpenGL

DirectX
                                                                 
Computer Graphics:

                                It started with Cathode Ray Tube and markers. And now it is one of the most extensive and ever growing branches of computer science. Now a days it has become the vital part of the computing world. We create new GUIs, new games and new interfaces everyday for the advantage of users. Most importantly it has changed the whole computing system very rapidly and is advancing a lot. The unofficial symbol of computer graphics is a tea pot!!! It was by accident. The teapot model was created in 1975 by early computer graphics researcher Martin Newell, a member of the pioneering graphics program at the University of Utah. Newell needed a moderately simple mathematical model of a familiar object for his work. His wife Sandra Newell suggested modelling their tea service since they were sitting down to tea at the time. He got some graph paper and a pencil, and sketched the entire teapot by eye. Then he went back to the lab and edited bézier control points on a Tektronix storage tube, again by hand.


As displayed at the Computer History Museum in Mountain View, California(1990-present).
The teapot shape contains a number of elements that made it ideal for the graphics experiments of the time: it is round, contains saddle points, has a genus greater than zero because of the hole in the handle, can project a shadow on itself, and looks reasonable when displayed without a complex surface texture.

Newell made the mathematical data that described the teapot's geometry (a set of three-dimensional coordinates) publicly available, and soon other researchers began to use the same data for their computer graphics experiments. These researchers needed something with roughly the same characteristics that Newell had, and using the teapot data meant they did not have to laboriously enter geometric data for some other object. Although technical progress has meant that the act of rendering the teapot is no longer the challenge it was in 1975, the teapot continued to be used as a reference object for increasingly advanced graphics techniques.

An openGL program to illustrate the movement of teapot:

#include <cstdlib>
#include <iostream> // C++ I/O
#include <cstdio> // C I/O (for sprintf)
#include <cmath> // standard definitions
#include <GL/glut.h> // GLUT
#include <GL/glu.h> // GLU
#include <GL/gl.h> // OpenGL
using namespace std; // make std accessible
double rotAngle = 10; // rotation angle (BEWARE: Global)
void init()
{
glClearColor(0.96, 0.98, 0.03, 0); // background color
glClearDepth(1.0); // background depth value
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(70, 1, 1, 1000); // setup a perspective projection
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/* gluLookAt( // set up the camera
0.0, 0.0, 10.0, // eye position
0.0, 0.0, 0.0, // lookat position
0.0, 1.0, 0.0); */ // up direction
glEnable(GL_DEPTH_TEST); // enable hidden surface removal
glEnable(GL_LIGHTING); // enable lighting
glEnable(GL_LIGHT0); // enable
float lpos[] = { 5, 5, 5, 0 };
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
//glShadeModel(GL_FLAT); // flat shading
glShadeModel(GL_SMOOTH); // smooth shading
}
//-----------------------------------------------------------------------
// display callback function
//-----------------------------------------------------------------------
void display()
{
glClear(
GL_COLOR_BUFFER_BIT | // clear the frame buffer (color)
GL_DEPTH_BUFFER_BIT); // clear the depth buffer (depths)
glPushMatrix(); // save the current camera transform
glRotated(rotAngle, 0, 1, 0); // rotate by rotAngle about y-axis
glEnable(GL_COLOR_MATERIAL); // specify object color
glColor3f(0.07, 0.37, 0.85); // redish


glutSolidTeapot(1); // draw the teapot
glPopMatrix(); // restore the modelview matrix
glFlush(); // force OpenGL to render now
glutSwapBuffers(); // make the image visible
}
//-----------------------------------------------------------------------
// keyboard callback function
//-----------------------------------------------------------------------
void keyboard(unsigned char k, int x, int y)
{
switch (k)
{
case 'a':
rotAngle += 5; // increase rotation by 5 degrees
break;
case 's':
rotAngle -= 5; // decrease rotation by 5 degrees
break;
case 'd':
glTranslatef(0.5,0.5,0);
break;
case 'f':
glTranslatef(-0.5,-0.5,0);
break;
case 'g':
glScalef(0.5,0.5,0.5);
break;
case 'h':
glScalef(2.0,2.0,2.0);
break;
case 'q':
exit(0); // exit
}
glutPostRedisplay(); // redraw the image now
}
void usage()
{
cout << "\n\
-----------------------------------------------------------------------\n\
Menu\n\
Inputs keybord:\n\
a: Rotate counterclockwise\n\
s: Rotate clockwise\n\
d: Translate with x=1 y=1 z=0\n\
f: Translate with x= -1 y= -1 z =0 \n\
g: Zoom Out\n\
h: Zoom in\n\
q: Quit\n\
You may need to place the cursor over the graphics window for\n\
keyboard input to be processed.\n\
-----------------------------------------------------------------------\n";
cout.flush();
}
void menu(int value) {
switch (value) {
case 1 : rotAngle +=10;
break;
case 2 : rotAngle -=10;
break;
case 3 : glTranslatef(0.5,0.5,0);
break;
case 4 : glTranslatef(-0.5,-0.5,0);
break;
case 5 : glScalef(0.5,0.5,0.5);
break;
case 6 : glScalef(2.0,2.0,2.0);
break;
case 7 : exit(0);
}
glutPostRedisplay();
}
int main(int argc, char **argv)
{
usage(); // explain how to use
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH |GLUT_RGB );
glutCreateWindow("GLUT Example"); // create the window
glutCreateMenu(menu);
glutAddMenuEntry("Clockwise",1);
glutAddMenuEntry("Anticlockwise",2);
glutAddMenuEntry("Translate",3);
glutAddMenuEntry("AntiTranslate",4);
glutAddMenuEntry("Zoom out",5);
glutAddMenuEntry("Zoom in",6);
glutAddMenuEntry("Quit",7);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(display); // call display() to redraw window
glutKeyboardFunc(keyboard); // call keyboard() when key is hit
init(); // our own initializations
glutMainLoop(); // let GLUT take care of everything
return 0;
}

I hope that this was enough informative :) 


1 comment: