Color Combination Computer Graphics Project Using OpenGL Report
Color Combination Computer Graphics Project Using OpenGL Report
CONTENTS
Abstract
All the permutations and combinations of colors are taken care of.
We have used input devices like mouse and key board to interact with
program
System specifications
SOFTWARE REQUIREMENTS :
HARDWARE REQUIREMENT :
GRAPHICS SYSTEM,
Pentium P4 with 256 of Ram(Min)
Introduction to openGL
As a software interface for graphics hardware, OpenGL's main purpose is to
render two- and three-dimensional objects into a frame buffer.
These objects are described as sequences of vertices or pixels.
OpenGL performs several processing steps on this data to convert it to pixels to
form the final desired image in the frame buffer.
OpenGL Fundamentals
This section explains some of the concepts inherent in OpenGL.
As shown by the first block in the diagram, rather than having all commands
proceed immediately through the pipeline, you can choose to accumulate some
of them in a display list for processing at a later time.
Implementation
This program is implemented using various openGL functions which are
shown below.
glutCreateWindow() : this opens the OPENGL window and displays the title
at top of the window
Q-> Quit
Source Code
#include <windows.h>
#include<string.h>
#include<stdarg.h>
#include<stdio.h>
#include <glut.h>
va_list args;
va_start(args, format);
va_end(args);
glPushMatrix();
glTranslatef(-2.5, y, 0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
void doInit()
glClearColor(0.5,0.5,0.5,0.0);
11 Dept. of Computer Science & Engineering.
Color Combination
glColor3f(.0,1.0,1.0);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.1f,200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glDepthFunc(GL_LEQUAL);
void torch(){
glPushMatrix();
glutSolidSphere(0.8,50,50);
glPopMatrix();
glPushMatrix();
glRotatef(90,0,1,0);
glScaled(0.5,0.5,3);
glColor3f(0,1,1);
glutSolidTorus(0.4,1.5,50,50);
glPopMatrix();
glPushMatrix();
glTranslatef(-1.5,0,0);
glRotatef(90,0,1,0);
glScaled(0.7,0.7,1.5);
glutSolidTorus(0.4,1.5,50,50);
13 Dept. of Computer Science & Engineering.
Color Combination
glPopMatrix();
void help(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScaled(0.7,0.7,0.7);
glPopMatrix();
glFlush();
glutSwapBuffers();
void draw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
glPushMatrix();
glTranslatef(0,0,-15);
glScaled(1,1,0.1);
glColor3f(0.3,0.3,0);
15 Dept. of Computer Science & Engineering.
Color Combination
glutSolidCube(9);
glPopMatrix();
glPushMatrix();
glColor3f(1,0,1);
glutSolidCone(4.5,15,40,40);
glPopMatrix();
// Color Sphere
glPushMatrix();
glTranslatef(0,0,-14);
glScaled(1,1,0.1);
glColor3f(red1,green1,blue1);
glutSolidSphere(2,30,30);
16 Dept. of Computer Science & Engineering.
Color Combination
glPopMatrix();
// red Torch
glPushMatrix();
glTranslatef(-1.5,-2,2);
glRotatef(-20,0,0,1);
glPushMatrix();
glRotatef(90,0,1,0);
glScaled(0.3,0.3,0.3);
glColor3f(1,0,0);
torch();
glPopMatrix();
glPopMatrix();
if(red1){
glPushMatrix();
glRotatef(50,1,0,1);
glRotatef(-55,0,1,1);
17 Dept. of Computer Science & Engineering.
Color Combination
glColor3f(1,0,0);
glutWireCone(1.0,3,10,10);
glPopMatrix();
// Green Torch
glPushMatrix();
glTranslatef(0,-2,2);
glRotatef(-20,0,0,1);
glPushMatrix();
glRotatef(90,0,1,0);
glScaled(0.3,0.3,0.3);
glColor3f(0,1,0);
torch();
glPopMatrix();
glPopMatrix();
if(green1){
glPushMatrix();
glTranslatef(0,-0.5,-3);
glRotatef(10,1,0,1);
glColor3f(0,1,0);
glutWireCone(1.0,7,10,10);
glPopMatrix();
// Blue Torch
glPushMatrix();
glTranslatef(1.5,-2,2);
glRotatef(-20,0,0,1);
glPushMatrix();
glRotatef(90,0,1,0);
glScaled(0.3,0.3,0.3);
glColor3f(0,0,1);
torch();
19 Dept. of Computer Science & Engineering.
Color Combination
glPopMatrix();
glPopMatrix();
if(blue1){
glPushMatrix();
glRotatef(90,1,0,1);
glColor3f(0,0,1);
glutWireCone(1.0,3,10,10);
glPopMatrix();
glFlush();
glutSwapBuffers();
void doDisplay()
{
20 Dept. of Computer Science & Engineering.
Color Combination
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
if(help1)
help();
else
draw();
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
21 Dept. of Computer Science & Engineering.
Color Combination
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={100.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloat light_position[]={2.0f,5.0f,3.0f,1.0f};*/
GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position[]={2.0f,0.0f,0.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
GLfloat light_position2[]={0.0f,0.0f,8.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position2);
GLfloat light_position3[]={6.0f,0.0f,5.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
glFlush();
glutSwapBuffers();
if(key=='q'||key=='Q')
exit(0);
if(key=='h'||key=='H')
23 Dept. of Computer Science & Engineering.
Color Combination
help1=!help1;
glutPostRedisplay();
if(key=='s' || key=='S'){
glutIdleFunc(draw);
if(key=='r'||key=='R')
red1=!red1 ;
glutPostRedisplay();
24 Dept. of Computer Science & Engineering.
Color Combination
if(key=='g'||key=='G')
green1=!green1;
glutPostRedisplay();
if(key=='b'||key=='B')
blue1=!blue1;
glutPostRedisplay();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutDisplayFunc(doDisplay);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
doInit();
glutMainLoop();
return 0;
}
26 Dept. of Computer Science & Engineering.
Color Combination
Conclusions
Finally we conclude that this program clearly illustrate the color combination
using openGL and has been completed successfully and is ready to be
demonstrated.
Bibliography
WE HAVE OBTAINED INFORMATION FROM MANY RESOURCES TO DESIGN AND
IMPLEMENT OUR PROJECT SUCCESSIVELY. WE HAVE ACQUIRED MOST OF THE
KNOWLEDGE FROM RELATED WEBSITES. THE FOLLOWING ARE SOME OF THE
RESOURCES :
TEXT BOOKS :
INTERACTIVE COMPUTER GRAPHICS A TOP-DOWN APPROACH
-By Edward Angel.
- Feiner hughes
WEB REFERENCES:
http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson3.php
http://google.com
http://opengl.org