project report on drawing a snowman using opengl download
#1

i require a project report on snowman which uses keyboard function using opengl
Reply
#2

#include <math.h>
#include <GL/glut.h>
#include <stdio.h>
#include <string.h>
//#include <cstdlib>
//if you got error in exit() by compiler then does not incluede stdlib.h because //exit() is also defined in glut.h file.

float angle=0.0,deltaAngle = 0.0,ratio;
float x=0.0f,y=1.75f,z=5.0f;
float lx=0.0f,ly=0.0f,lz=-1.0f;
int deltaMove = 0,h,w;
int font=(int)GLUT_BITMAP_8_BY_13;
static GLint snowman_display_list;
int bitmapHeight=13;

int frame,time,timebase=0;
char s[30];

void initWindow();

void changeSize(int w1, int h1)
{

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h1 == 0)
h1 = 1;

w = w1;
h = h1;
ratio = 1.0f * w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set the viewport to be the entire window
glViewport(0, 0, w, h);

// Set the clipping volume
gluPerspective(45,ratio,0.1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);


}




void drawSnowMan() {


glColor3f(1.0f, 1.0f, 1.0f);

// Draw Body
glTranslatef(0.0f ,0.75f, 0.0f);
glutSolidSphere(0.75f,20,20);


// Draw Head
glTranslatef(0.0f, 1.0f, 0.0f);
glutSolidSphere(0.25f,20,20);

// Draw Eyes
glPushMatrix();
glColor3f(0.0f,0.0f,0.0f);
glTranslatef(0.05f, 0.10f, 0.18f);
glutSolidSphere(0.05f,10,10);
glTranslatef(-0.1f, 0.0f, 0.0f);
glutSolidSphere(0.05f,10,10);
glPopMatrix();

// Draw Nose
glColor3f(1.0f, 0.5f , 0.5f);
glRotatef(0.0f,1.0f, 0.0f, 0.0f);
glutSolidCone(0.08f,0.5f,10,2);
}



GLuint createDL() {
GLuint snowManDL;

// Create the id for the list
snowManDL = glGenLists(2);

glNewList(snowManDL+1,GL_COMPILE);
drawSnowMan();
glEndList();
// start list
glNewList(snowManDL,GL_COMPILE);

// call the function that contains the rendering commands
for(int i = -3; i < 3; i++)
for(int j=-3; j < 3; j++) {
glPushMatrix();
glTranslatef(i*10.0,0,j * 10.0);
glCallList(snowManDL+1);
glPopMatrix();
}

// endList
glEndList();

return(snowManDL);
}

void initScene() {

glEnable(GL_DEPTH_TEST);
snowman_display_list = createDL();

}

void orientMe(float ang) {


lx = sin(ang);
lz = -cos(ang);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);
}


void moveMeFlat(int i) {
x = x + i*(lx)*0.1;
z = z + i*(lz)*0.1;
glLoadIdentity();
gluLookAt(x, y, z,
x + lx,y + ly,z + lz,
0.0f,1.0f,0.0f);
}

void setOrthographicProjection() {

// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
//settings for the perspective projection
glPushMatrix();
// reset matrix
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, w, 0, h);
// invert the y axis, down is positive
glScalef(1, -1, 1);
// mover the origin from the bottom left corner
// to the upper left corner
glTranslatef(0, -h, 0);
glMatrixMode(GL_MODELVIEW);
}

void resetPerspectiveProjection() {
// set the current matrix to GL_PROJECTION
glMatrixMode(GL_PROJECTION);
// restore previous settings
glPopMatrix();
// get back to GL_MODELVIEW matrix
glMatrixMode(GL_MODELVIEW);
}

void renderBitmapString(float x, float y, void *font,char *string)
{

char *c;
// set position to start drawing fonts
glRasterPos2f(x, y);
// loop all the characters in the string
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}


void renderScene(void) {

if (deltaMove)
moveMeFlat(deltaMove);
if (deltaAngle) {
angle += deltaAngle;
orientMe(angle);
}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Draw ground

glColor3f(0.9f, 0.9f, 0.9f);
glBegin(GL_QUADS);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, -100.0f);
glEnd();

// Draw 36 Snow Men

glCallList(snowman_display_list);

frame++;
time=glutGet(GLUT_ELAPSED_TIME);
if (time - timebase > 1000) {
sprintf(s,"FPS:%4.2f",frame*1000.0/(time-timebase));
timebase = time;
frame = 0;
}

glColor3f(0.0f,1.0f,1.0f);
setOrthographicProjection();
glPushMatrix();
glLoadIdentity();
renderBitmapString(30,15,(void *)font,"GLUT Tutorial @ 3D Tech");
renderBitmapString(30,35,(void *)font,s);
renderBitmapString(30,55,(void *)font,"Esc - Quit");
glPopMatrix();
resetPerspectiveProjection();

glutSwapBuffers();
}

void processNormalKeys(unsigned char key, int x, int y) {

if (key == 27)
exit(0);
}

void pressKey(int key, int x, int y) {

switch (key) {
case GLUT_KEY_LEFT : deltaAngle = -0.01f;break;
case GLUT_KEY_RIGHT : deltaAngle = 0.01f;break;
case GLUT_KEY_UP : deltaMove = 1;break;
case GLUT_KEY_DOWN : deltaMove = -1;break;
}

}

void releaseKey(int key, int x, int y) {

switch (key) {
case GLUT_KEY_LEFT : if (deltaAngle < 0.0f)
deltaAngle = 0.0f;
break;
case GLUT_KEY_RIGHT : if (deltaAngle > 0.0f)
deltaAngle = 0.0f;
break;
case GLUT_KEY_UP : if (deltaMove > 0)
deltaMove = 0;
break;
case GLUT_KEY_DOWN : if (deltaMove < 0)
deltaMove = 0;
break;
}
}

void initWindow() {
glutIgnoreKeyRepeat(1);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutReshapeFunc(changeSize);
initScene();

}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640,360);
glutCreateWindow("codeincodeblock.blogspot.com");

// register all callbacks
initWindow();

glutMainLoop();

return(0);
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: snowman opengl program abstract, snowman opengl pdf, download report for opengl project of the olympic, a snowman just, olympics logo cd project using opengl, solar bicycle ppt and drawing free download, snowman using opengl synopsis download,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  authentication schemes for session passwords using color and images project source code 2 2,237 03-02-2018, 09:35 AM
Last Post: Nischithnash
Smile download wi vi technology seminars report pdf 2 15,839 24-01-2018, 11:27 PM
Last Post: sultan@123
  soil stabilization using plastic ppt download Anand a. M 2 1,886 20-11-2017, 08:50 PM
Last Post: perfect dreamer
  opengl synopsis for train moving 3 1,286 05-06-2017, 09:45 AM
Last Post: jaseela123d
Wink seminar report on pavement design using geotextiles 4 1,300 18-05-2017, 11:08 AM
Last Post: Umeshyuvi
  nh dubey engineering drawing book pdf download 3 2,306 04-05-2017, 01:26 PM
Last Post: Guest
  source code for task scheduling using genetic algorithm using java 2 8,529 11-04-2017, 08:31 PM
Last Post: Guest
  132 33 kv substation training report pdf file download 2 2,010 08-08-2016, 04:02 PM
Last Post: Guest
  virtualization security in cloud computing seminars report pdf download 2 1,752 16-07-2016, 12:44 PM
Last Post: jaseela123d
  download wi vi technology seminars report pdf 2 661 14-07-2016, 02:40 PM
Last Post: anasek

Forum Jump: