Project 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

#include<stdlib.

h>

#include<string.h>

#include<stdio.h>

#include<GL/glut.h>

///////////////////////////////declarations/////////////////////

int readv,cancelhl=0,okhl=0;

static char info[100]="Welcome";

int winwd=1000,winht=700,mainw,subw,saveid;

int current=0;

int curobject;

int objectcount=0;//to store count of objects

float col[27][3];//to store color values

int m=0,mode=2;// to store mode values-selection mode and render mode

int chlx=-10,chly=-10,chlhl=0;// to store color highilightable box

int curcol=2;//to store current color

int hlicon=0;//highlight icon

int fileid,viewid,editid,rightid,styleid,drawid;//to store menu ids

GLint active;// to store active objects

GLUquadricObj
*point=gluNewQuadric(),*line=gluNewQuadric(),*wire=gluNewQuadric(),*fill=gluNewQuadric();

int cut=0,copied=0,px=0,py=0;

int saved=0;

int first=1;
char filename[20],fname[20],wfname[30];

void menubackg(float x,float y,float z,float width,float height);

void activeobjects(int);

void processhits(int hits, GLuint * ptr);

void drawcube(int);

void mynew();

GLfloat vertices[]={-1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1,-1,-1,1,1,-1,1,1,1,1,-1,1,1};//to store attributes for cube

GLubyte cubeIndices[]={0,3,2,1,2,3,7,6,1,2,6,5,6,7,4,5,5,4,0,1,0,4,7,3};//to store the orientation of


vertices

#define CUBE 1

#define SPHERE 2

#define CYLINDER 3

#define CONE 4

#define LINE 5

#define RECT 6

//structures

typedef struct button

{ float x,y,z;//bottom left coordinates


int w,h;//size of button

int type;

int state;

int col;//color

char * label;//name of button

int hl;//highlighted

}BUT;

typedef struct obj

float orgx,orgy,orgz;

float size;

//float radius;

int color;

float tx,ty,tz;//translation factors

float sx,sy,sz;//scaling factors

int type;

int style;//style of object

int used;//status

}OBJ;

OBJ obar[1000];

OBJ temp;

#define BUFSIZE 512

#define MAX_OBJECTS 1000


////////////////////////////////////initialization////////////////////

int OBJECT=1;

BUT file_menu ={0,winht-20,0,70,50,0,0,0," FILE",0};

BUT edit_menu ={100,winht-20,0,70,50,0,0,0," EDIT",0};

BUT view_menu={200,winht-20,0,70,50,0,0,0," VIEW",0};

BUT col_menu={winwd-75,winht-165,0,70,50,0,0,0,"COLORS",0};

BUT ok_b={80,10,0,40,20,0,0,0,"",0};

BUT cancel_b={130,10,0,40,20,0,0,0,"",0};

BUT draw_menu ={300,winht-20,0,70,50,0,0,0," DRAW",0};

int drawing=1;//to select the drawing mode or picking mode

int transformation=0;//to select the transformation i.e. rotation,scaling or moving

///initialising the object

void objinit(OBJ * ob)

ob->orgx=0;

ob->orgy=0;

ob->orgz=-2;

ob->size=0;
ob->color=2;

ob->tx=0;

ob->ty=0;

ob->tz=0;

ob->sx=10;

ob->sy=10;

ob->sz=10;

ob->type=0;

ob->style=0;

ob->used=0;

////////////functions///////////////

int save()

{int i;

FILE * fp;

glutSetWindow(mainw);

glutHideWindow();

if(!saved)
{

//clrscr();

printf("\t\t\tSAVE\n");

printf("\tFile Name:");

scanf("%s",fname);

fp=fopen(fname,"w");

if(fp==NULL)

printf("INVALID FILE NAME/FILE EXISTS\n");

return -1;

glutShowWindow();

fprintf(fp,"%d",objectcount);

for(i=0;i<objectcount;i++)

if(obar[i].used==1)

fprintf(fp,"%f",obar[i].orgx);

fprintf(fp,"%f",obar[i].orgy);

fprintf(fp,"%f",obar[i].orgz);

fprintf(fp,"%f",obar[i].size);

fprintf(fp,"%d",obar[i].color);

fprintf(fp,"%f",obar[i].tx);
fprintf(fp,"%f",obar[i].ty);

fprintf(fp,"%f",obar[i].tz);

fprintf(fp,"%f",obar[i].sx);

fprintf(fp,"%f",obar[i].sy);

fprintf(fp,"%f",obar[i].sz);

fprintf(fp,"%d",obar[i].type);

fprintf(fp,"%d",obar[i].style);

fprintf(fp,"%d",obar[i].used);

/*if(obar[i].used==1)

fprintf(fp,"%f%f%f%f%d%f%f%f%f%f%f%d%d
%d",obar[i].orgx,obar[i].orgy,obar[i].orgz,obar[i].size,obar[i].color,obar[i].tx,obar[i].ty,obar[i].tz,obar[i].s
x,obar[i].sy,obar[i].sz,obar[i].type,obar[i].style,obar[i].used);*/

saved=1;

fclose(fp);

strcpy(info,"saved");

return 1;

int open()

{int i;

FILE * fp;

glutHideWindow();

printf("\t\t\tOPEN\n");
printf("\tFile Name:");

gets(fname);

fp=fopen(fname,"r");

if(fp==NULL)

printf("INVALID FILE NAME/FILE EXISTS\n");

return -1;

glutShowWindow();

mynew();

//glutPostRedisplay();

fscanf(fp,"%d",&objectcount);

for(i=0;i<objectcount;i++)

fscanf(fp,"%f",&obar[i].orgx);

fscanf(fp,"%f",&obar[i].orgy);

fscanf(fp,"%f",&obar[i].orgz);

fscanf(fp,"%f",&obar[i].size);

fscanf(fp,"%d",&obar[i].color);

fscanf(fp,"%f",&obar[i].tx);

fscanf(fp,"%f",&obar[i].ty);

fscanf(fp,"%f",&obar[i].tz);

fscanf(fp,"%f",&obar[i].sx);

fscanf(fp,"%f",&obar[i].sy);

fscanf(fp,"%f",&obar[i].sz);
fscanf(fp,"%d",&obar[i].type);

fscanf(fp,"%d",&obar[i].style);

fscanf(fp,"%d",&obar[i].used);

fclose(fp);

strcpy(info,"opened");

return 1;

glutPostRedisplay();

}
void drawText(char *message, float i, float j,float k)

glRasterPos3f(i,j,k);

/* write using bitmap and stroke chars */

while (*message)

glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *message++);

void drawinfo(char *message)

glRasterPos3f(10,10,2);

/* write using bitmap and stroke chars */glColor3f(1,0,0);

while (*message)

glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *message++);

glColor3fv(col[curcol]);

}
////////////// menu functions ///////////////

void filem(int index)

switch(index)

case 1: mynew();

break;

case 2:if(open())

strcpy(wfname,"3D-GRAPHICS-");

strcat(wfname,fname);

glutSetWindowTitle(wfname);

break;

case 3:

if(save())
{ strcpy(wfname,"3D-GRAPHICS-");

strcat(wfname,fname);

glutSetWindowTitle(wfname);

break;

case 4:exit(0);

break;

void editm(int index)

switch(index)

case 1:drawing=0;

break;

case 2:transformation=1;

break;

case 3:transformation=2;

break;

case 4:transformation=3;

break;
}

void viewm(int index)

int full_screen=0;

switch(index)

case 1:glutFullScreen();

break;

void stylem(int index)

obar[active].style=index;

obar[current].size=index;

void drawm(int index)

{ drawing=1;

switch(index)

case 1:OBJECT=11;
break;

case 2:OBJECT=12;

break;

case 3:OBJECT=13;

break;

case 4:OBJECT=14;

break;

void rightm(int index)

switch(index)

case 1:cut=1;

temp=obar[active];

break;

case 2:copied=1;

temp=obar[active];

break;

case 3:if(copied)

objectcount+=1;

int i=objectcount-1;
obar[i]=temp;

obar[i].used=1;

obar[i].color=temp.color;

obar[i].orgx=px;

obar[i].orgy=py;

obar[i].orgz=-1000;

obar[i].type=temp.type;

active=i;

else if(cut)

copied=0;

cut=0;

obar[active].orgx=px;

obar[active].orgy=py;

break;

case 4:objectcount--;

active=objectcount-1;

break;

glutPostRedisplay();

}
////////// to draw background

void menubackg(float x,float y,float z,float width,float height,int c)

{ glBegin(GL_POLYGON);

glColor3fv(col[c]);

if(c==2)

glColor3f(.9,.9,1);

glVertex3f(x,y,z);

glVertex3f(x,y+height,z);

glVertex3f(x+width,y+height,z);

glVertex3f(x+width,y,z);

glEnd();

void drawhlicon()

if(hlicon==1)

menubackg(0,winht-80,-.5,50,50,2);

else if(hlicon==2)

menubackg(50,winht-80,-.5,50,50,2);

else if(hlicon==3)

menubackg(100,winht-80,-.5,50,50,2);

else if(hlicon==4)

menubackg(150,winht-80,-.5,50,50,2);
else if(hlicon==5)

menubackg(200,winht-80,-.5,50,50,2);

else if(hlicon==6)

menubackg(250,winht-80,-.5,50,50,2);

void menubackg(float x,float y,float z,float width,float height)

{ glBegin(GL_POLYGON);

glColor3f(0.6,0.6,1);

glVertex3f(x,y,z);

glVertex3f(x,y+height,z);

glVertex3f(x+width,y+height,z);

glVertex3f(x+width,y,z);

glEnd();

glLineWidth(6.0);

glBegin(GL_LINE_LOOP);

glColor3f(.9,.9,1);

glVertex3f(x,y,z);

glVertex3f(x,y+height,z);

glVertex3f(x+width,y+height,z);

glVertex3f(x+width,y,z);

glEnd();
glLineWidth(1.0);

////// highlighting functions

void chl()

if(chlhl=1)

//chlhl=0;

glColor3f(0,0,1);

glLineWidth(3.0);

glBegin(GL_LINE_LOOP);

glVertex3f(chlx,chly,1);

glVertex3f(chlx,chly+30,1);

glVertex3f(chlx+30,chly+30,1);

glVertex3f(chlx+30,chly,1);

glEnd();

}
/////////////// menu drawing

void drawbutton(BUT * bt)

if(bt->type==0)

if(bt->hl)

glColor3f(0,0,1);

menubackg(bt->x+5,bt->y-5,-0.5,bt->w,bt->h,2);

glColor3fv(col[bt->col]);

drawText(bt->label,(bt->x)+3,(bt->y)+3,0);

if(bt->type==1)

if(bt->hl)

glColor3f(0,0,1);

menubackg(bt->x,bt->y-20,-0.5,bt->w,bt->h,2);

//draw_icon();
}

void colormenu()

{ float y=(winht-590);

for(int i=0;i<=26;i++)

glColor3fv(col[i++]);

glBegin(GL_POLYGON);

glVertex3f(winwd-80,y,-0.5);

glVertex3f(winwd-80,y+30,-0.5);

glVertex3f(winwd-50,y+30,-0.5);

glVertex3f(winwd-50,y,-0.5);

glEnd();

glColor3f(.9,.9,.9);

glBegin(GL_LINE_LOOP);

glVertex3f(winwd-80,y,0);

glVertex3f(winwd-80,y+30,0);

glVertex3f(winwd-50,y+30,0);

glVertex3f(winwd-50,y,0);

glEnd();

glColor3fv(col[i]);

glBegin(GL_POLYGON);

glVertex3f(winwd-50,y,-0.5);

glVertex3f(winwd-50,y+30,-0.5);
glVertex3f(winwd-20,y+30,-0.5);

glVertex3f(winwd-20,y,-0.5);

glEnd();

glColor3f(.9,.9,.9);

glBegin(GL_LINE_LOOP);

glVertex3f(winwd-50,y,0);

glVertex3f(winwd-50,y+30,0);

glVertex3f(winwd-20,y+30,0);

glVertex3f(winwd-20,y,0);

glEnd();

y=y+30;

void drawicons()

glColor3fv(col[0]);

glLineWidth(1.0);

//cube

glPushMatrix();

//glLoadIdentity();

glTranslatef(25,winht-55,30);

glRotatef(25,1,0,0);

glRotatef(15,0,1,0);
glScalef(6,6,6);

drawcube(3);

glPopMatrix();

glPointSize(1.0);

glLineWidth(1.0);

//sphere

glPushMatrix();

//glLoadIdentity();

glTranslatef(75,winht-55,0);

glRotatef(90,0,1,0);

gluSphere(wire,17,20,20);

glPopMatrix();

//cone

glPushMatrix();

//glLoadIdentity();

glTranslatef(125,winht-40,0);

glRotatef(90,1,0,0);

gluCylinder(wire,15,0,30,30,40);

glPopMatrix();

//cylinder

glPushMatrix();

//glLoadIdentity();

glTranslatef(175,winht-40,0);
glRotatef(90,1,0,0);

gluCylinder(wire,13,13,35,28,28);

//gluCylinder(wire,200,200,35,25,20);

//gluCylinder(wire,13,13,35,25,20);

glTranslatef(100,100,0);

//gluCylinder(wire,13,13,35,25,20);

glPopMatrix();

///////////////////// keyboard callback functions

void specialkey(int key,int x,int y)

if(drawing==0)

if(transformation==1)

if(key==GLUT_KEY_UP)

obar[active].orgy+=10;

else if(key==GLUT_KEY_RIGHT)

obar[active].orgx+=10;

else if(key==GLUT_KEY_LEFT)

obar[active].orgx-=10;
else if(key==GLUT_KEY_DOWN)

obar[active].orgy-=10;

else if(transformation==2)

if(key==GLUT_KEY_UP)

obar[active].ty+=10;

else if(key==GLUT_KEY_RIGHT)

obar[active].tx+=10;

else if(key==GLUT_KEY_LEFT)

obar[active].tx-=10;

else if(key==GLUT_KEY_DOWN)

obar[active].ty-=10;

else if(transformation==3)

if(key==GLUT_KEY_UP)

obar[active].sy+=1;

else if(key==GLUT_KEY_RIGHT)

obar[active].sx+=1;

else if(key==GLUT_KEY_LEFT)

obar[active].sx-=1;

else if(key==GLUT_KEY_DOWN)
obar[active].sy-=1;

glutPostRedisplay();

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

if(drawing==0)

if(transformation==1)

printf("Z\n");

if(key=='Z')

obar[active].orgz+=1;

else if(key=='z')

obar[active].orgz-=1;

else if(transformation==2)

if(key=='Z')
obar[active].tz+=1;

else if(key=='z')

obar[active].tz-=1;

else if(transformation==3)

if(key=='Z')

obar[active].sz+=1;

else if(key=='z')

obar[active].sz-=1;

glutPostRedisplay();

/////// mouse callback functions

void pmotion(int x,int y)

int height=glutGet(GLUT_WINDOW_HEIGHT);

int width=glutGet(GLUT_WINDOW_WIDTH);

y=(height-y)*winht/height;

x=(x)*winwd/width;
px=x;

py=y;

file_menu.hl=0;

view_menu.hl=0;

edit_menu.hl=0;

draw_menu.hl=0;

hlicon=0;

chlhl=0;

glutDetachMenu(0);

if(y>=winht-80 && y<=winht-30)

hlicon=0;

if(x>=0 && x<50)

hlicon=1;

else if(x>=50 && x<100)

hlicon=2;

else if(x>=100 && x<150)

hlicon=3;

}
else if(x>=150 && x<200)

hlicon=4;

else if(y>=winht-30)

glutAttachMenu(0);

if(x>0 && x<=99)

file_menu.hl=1;

glutSetMenu(fileid);

else if(x>=100 && x<200)

edit_menu.hl=1;

glutSetMenu(editid);

else if(x>=200 && x<300)

view_menu.hl=1;

glutSetMenu(viewid);
}

else if(x>=300 && x<400)

draw_menu.hl=1;

glutSetMenu(drawid);

else

glutDetachMenu(0);

else if(x>=winwd-80 && y>=(winht-590) && y<=(winht-200+30) && x<=winwd-20)

int z=y-(winht-590);

z=z/30;

chlhl=1;

if(x>=winwd-80 && x<winwd-50)

chlx=(float)(winwd-80);

chly=((float)z*30+(winht-590));

else

chlx=(float)(winwd-50);

chly=((float)z*30+(winht-590));

}
else if(x<(winwd-100) && x>=0 && y<(winht-80) && y>=50)

if(drawing)

glutAttachMenu(GLUT_RIGHT_BUTTON);

glutSetMenu(styleid);

else

glutAttachMenu(2);

glutSetMenu(rightid);

glutPostRedisplay();

void mouse(int btn,int state,int xx,int yy)

if(btn==0 && state==GLUT_DOWN)

int height=glutGet(GLUT_WINDOW_HEIGHT);
int width=glutGet(GLUT_WINDOW_WIDTH);

float x,y;

y=(height-yy)*winht/height;

x=(xx)*winwd/width;

if(y>=(winht-80) && y<(winht-30))

drawing=1;

//do icon selection

if(x<50 && x>=0)

OBJECT=1;

strcpy(info,"Cube selected");

else if(x>=50 && x<100)

OBJECT=2;

strcpy(info,"sphere selected");

else if(x>=100 && x<150)

OBJECT=3;

strcpy(info,"cone selected");

}
else if(x>=150 && x<200)

OBJECT=4;

strcpy(info,"cylinder selected");

else if(y>=(winht-30))

//select menu

else if(x>=(winwd-80)&& y>=(winht-590) && y<=(winht-200+30) && x<=(winwd-20))

int z=y-(winht-590);

z=z/30;

if(x>=(winwd-80) && x<(winwd-50))

curcol=2*z;

else

curcol=2*z+1;

}
if(!drawing)

obar[active].color=curcol;

else if(x>=0 && x<=(winwd-100) && y<=(winht-80))

if(drawing)

//draw object();

objectcount+=1;

int i=objectcount-1;;

obar[i].used=1;

obar[i].color=curcol;

obar[i].orgx=x;

obar[i].orgy=y;

obar[i].orgz=-1000;

obar[i].type=OBJECT;

printf("%d ",obar[i].type);

active=i;

current=i;

strcpy(info,"Object drawn");

drawing=0;

}
else

//select object();

// picks(btn,state,xx,height-yy);

strcpy(info,"In Selection mode");

void drawcube(int st)

if(st==1)

glScalef(1.5,1.5,1.5);

glDrawElements(GL_POINTS,24,GL_UNSIGNED_BYTE,cubeIndices);

else if(st==2)

glutWireCube(3);

else if(st==3)
//glDrawElements(GL_LINE_LOOP,24,GL_UNSIGNED_BYTE,cubeIndices);

glutWireCube(3);

else

glutSolidCube(3);

void activeobjects(int mode)

int m=0;

for(int i=0;i<objectcount;i++)

if(obar[m].used==1)

if(mode == GL_SELECT)

{ glLoadName((GLint)m);

printf("%d ",mode);

i++;

glColor3fv(col[obar[m].color]);

glPushMatrix();

//glLoadIdentity();

glTranslatef(obar[m].orgx,obar[m].orgy,obar[m].orgz);

glRotatef(obar[m].tx,1,0,0);
glRotatef(obar[m].ty,0,1,0);

glRotatef(obar[m].tz,0,0,1);

glScalef(obar[m].sx,obar[m].sy,obar[m].sz);

if(obar[m].type==1)

//glutSolidCube(10);

glScalef(2,2,2);

drawcube(obar[m].style);

else if(obar[m].type==2)

//drawsphere();

if(obar[m].style==1)

gluSphere(point,5,30,30);

else if(obar[m].style==2)

gluSphere(line,5,30,30);

else if(obar[m].style==3)

gluSphere(wire,5,30,30);

else

gluSphere(fill,5,30,30);

else if(obar[m].type==3)

{
glRotatef(90,1,0,0);

if(obar[m].style==1)

gluCylinder(point,5,0,10,50,50);

else if(obar[m].style==2)

gluCylinder(line,5,0,10,50,50);

else if(obar[m].style==3)

gluCylinder(wire,5,0,10,50,50);

else

gluCylinder(fill,5,0,10,50,50);

else if(obar[m].type==4)

glRotatef(90,1,0,0);

if(obar[m].style==1)

gluCylinder(point,3,3,10,50,50);

else if(obar[m].style==2)

gluCylinder(line,3,3,10,50,50);

else if(obar[m].style==3)

gluCylinder(wire,3,3,10,50,50);

else

gluCylinder(fill,3,3,10,50,50);

//else if(obar[m].type==4)
//{

//

//glPushMatrix();

////glLoadIdentity();

////glTranslatef(275,40,0);

////glRotatef(90,1,0,0);

//glScalef(0,0,50);

////gluCylinder(wire,13,13,35,25,20);

//glPopMatrix();

//

// printf("%d %d ",obar[m].type,m);

// if(obar[m].style==1)

// gluDisk(point,0,10,30,30);

// else if(obar[m].style==2)

// gluDisk(line,8,10,50,50);

// else if(obar[m].style==3)

// gluDisk(wire,0,10,50,50);

// else

// gluDisk(fill,0,10,50,50);

//}

else if(obar[m].type==5)

glPushMatrix();

glBegin(GL_LINES);
glVertex3f(0,0,0);

glVertex3f(5,5,0);

glEnd();

glPopMatrix();

else if(obar[m].type==11)

//drawsphere();

if(obar[m].style==1)

glutWireTeapot(10);

else if(obar[m].style==2)

glutWireTeapot(5);

else if(obar[m].style==3)

glutWireTeapot(10);

else

glutSolidTeapot(10);

else if(obar[m].type==12)

//drawsphere();

//glScalef(5,5,5);

if(obar[m].style==1)

glutWireTorus(1,2,30,30);

else if(obar[m].style==2)
glutWireTorus(1,2,30,30);

else if(obar[m].style==3)

glutWireTorus(1,2,30,30);

else

glutSolidTorus(1,2,30,30);

else if(obar[m].type==13)

//drawsphere();

glScalef(5,5,5);

if(obar[m].style==1)

glutWireIcosahedron();

else if(obar[m].style==2)

glutWireIcosahedron();

else if(obar[m].style==3)

glutWireIcosahedron();

else

glutSolidIcosahedron();

else if(obar[m].type==14)

{
//drawsphere();

glScalef(5,5,5);

if(obar[m].style==1)

glutWireTetrahedron();

else if(obar[m].style==2)

glutWireTetrahedron();

else if(obar[m].style==3)

glutWireTetrahedron();

else

glutSolidTetrahedron();

glPopMatrix();

m++;

i--;

curobject=m;

void display()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f( 1.0, 1.0, 0.0 );

//glutWireSphere(100.0,20,20);

menubackg(0,winht-31,-1,winwd,30-2);//menu bar

menubackg(0,winht-80-1,-1,winwd,50-2);//icon bar

menubackg(winwd-100,0,-1,100,winht-80+4);//color bar

menubackg(0,0,-1,winwd,50);//info bar

drawbutton(&file_menu);

drawbutton(&edit_menu);

drawbutton(&view_menu);

drawbutton(&col_menu);

drawbutton(&draw_menu);

drawinfo(info);

drawhlicon();

colormenu();

activeobjects(GL_RENDER);

chl();

drawicons();

glFlush();

glutSwapBuffers();

}
void OpenGLInit(void)

float i,j,k;

for(i=0;i<=1;i+=0.5)

for(j=0;j<=1;j+=0.5)

for(k=0;k<=1;k+=0.5)

col[m][0]=i;

col[m][1]=j;

col[m][2]=k;

m++;

for(int l=0;l<1000;l++)

objinit(& obar[l]);

glLineWidth(5.0);

glShadeModel( GL_FLAT );

glClearColor(1,1,15, 0.0 );

glClearDepth( 1.0 );

gluQuadricDrawStyle(fill,GLU_FILL);

gluQuadricDrawStyle(wire,GLU_SILHOUETTE);
gluQuadricDrawStyle(line,GLU_LINE);

gluQuadricDrawStyle(point,GLU_POINT);

glMatrixMode( GL_PROJECTION );

glLoadIdentity();

//gluPerspective( 60.0, 1000/1280, 5.0, 10.0 );

glOrtho(-0,winwd,-.0,winht,-10000,10000);

// Select the Modelview matrix

glMatrixMode( GL_MODELVIEW );

glEnable( GL_DEPTH_TEST );

//gluLookAt(0,0,-1000,0,0,0,0,1,0);

void mynew()

for(int l=0;l<100;l++)

objinit(& obar[l]);

objectcount=0;

active=0;

curcol=0;

drawing=1;

glutPostRedisplay();

}
void mydisp()

glClearColor(.8,.8,1,1);

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glClearColor(.8,.8,1,1);

glColor3f(1,0,0);

activeobjects(GL_RENDER);

drawText("File Name:",winwd-500,winht-500,-2);

glColor3f(1,1,1);

glBegin(GL_POLYGON);

drawinfo(info);

glVertex3f(winwd-450,winht-500,0);

glVertex3f(winwd-450+100,winht-500,0);

glVertex3f(winwd-450+100,winht-500+35,0);

glVertex3f(winwd-450,winht-500+35,0);

glEnd();

glFlush();

glutSwapBuffers();

void myinit()

{
glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(winwd-400,winht-400,winwd-200,winht-200,-1000,1000);

glMatrixMode(GL_MODELVIEW);

glEnable(GL_DEPTH_TEST);

static void resize(int w, int h)

float aspectRatio;

//h = (h == 0) ? 1 : h;

//w = (w == 0) ? 1 : w;

glViewport( 0, 0, w, h ); // View port uses whole window

aspectRatio = (float)w/(float)h;

// Set up the projection view matrix (not very well!)*/

glMatrixMode( GL_PROJECTION );

glLoadIdentity();

//gluPerspective( 60.0, aspectRatio, 1.0, 30.0 );

if(w<=h)

glOrtho(-0.1,1024,-0.1/aspectRatio,1280/aspectRatio,-10000,10000);
else

glOrtho(-0.1*aspectRatio,1024*aspectRatio,-0.10,1280,-10000,10000);

// Select the Modelview matrix

glMatrixMode( GL_MODELVIEW );

//sglViewport(0,0,winwd,winht);

glutReshapeWindow(winwd,winht);

int main()

glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH |GLUT_DOUBLE);

glutInitWindowPosition( 0, 0 );

glutInitWindowSize( winwd, winht );

mainw= glutCreateWindow( "3D-GRAPHICS EDITORv" );

OpenGLInit();

glutDisplayFunc( display );

//glutReshapeFunc(resize);

glutPassiveMotionFunc(pmotion);

glutMouseFunc(mouse);

glutKeyboardFunc(key);

glutSpecialFunc(specialkey);
fileid=glutCreateMenu(filem);

glutAddMenuEntry("NEW",1);

glutAddMenuEntry("OPEN",2);

glutAddMenuEntry("SAVE",3);

glutAddMenuEntry("EXIT",4);

editid=glutCreateMenu(editm);

glutAddMenuEntry("SELECT",1);

glutAddMenuEntry("MOVE",2);

glutAddMenuEntry("ROTATE",3);

glutAddMenuEntry("SCALE",4);

viewid=glutCreateMenu(viewm);

glutAddMenuEntry("FULLSCREEN",1);

styleid=glutCreateMenu(stylem);

glutAddMenuEntry("POINTS",1);

glutAddMenuEntry("LINES",2);

glutAddMenuEntry("WIRE",3);

glutAddMenuEntry("FILL",4);

rightid=glutCreateMenu(rightm);

glutAddMenuEntry("CUT",1);

glutAddMenuEntry("COPY",2);

glutAddMenuEntry("PASTE",3);

glutAddMenuEntry("DELETE",4);

glutAddSubMenu("STYLE",styleid);

drawid=glutCreateMenu(drawm);
glutAddMenuEntry("Teapot",1);

glutAddMenuEntry("Torus",2);

glutAddMenuEntry("IcosaHedron",3);

glutAddMenuEntry("TetraHedron",4);

glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3,GL_FLOAT,0,vertices);

glutMainLoop();

You might also like