I solved my problem about the subwindow…but a new trouble has creeped in…
i want to have an interactive application, it works simply great for the first time… but gives a problem like “debug assertion failed”.
i am using glut on vc++6.0.
as was recommended i am posting my code as well
The include files in the code pertain to processing the textual input by the user and display the corresponding shape.
Why does it take only one input???
is there any way to put it into some kind of while-loop???
HELP.
/* Main Program*/
#include<stdio.h>
#include<conio.h>
#include"INITIAL.h"
#include"Recogniz.cpp"
#include<GL/glut.h>
class Object
{
virtual void draw(float quantifier)=0;
virtual void draw(int c,float quantifier,int fill)=0;
void erase()
{
//clrscr();
}
};
class Line
{
float side;/* length ie*/
float width;
public:
Line()
{
side=iLength;
width=iThick;
}
void draw(float quantifier,int c)
{
if(quantifier>=2)
{
quantifier-=2;
if(quantifier*width > MAX*iThick)
width=MAX*iThick;
else
if(quantifier*width < MIN*iThick)
width=MIN*iThick;
else
width=quantifier*width;
glLineWidth(width);
}
else
{
if(quantifier*side > MAX*iLength)
side=MAX*iLength;
else
if(quantifier*side < MIN*iLength)
side=MIN*iLength;
else
side=quantifier*side;
}
/*Default Color*/
glColor3f(carr[c].r,carr[c].g,carr[c].b);
/* function for LINE*/
glBegin(GL_LINES);
glVertex2f(-side/2,-side/2);
glVertex2f(side/2,side/2);
glEnd();
}
};
class Circle ublic Object
{
float radius;
public:
Circle()
{
radius=iRad;
}
void draw(float quantifier)
{
if(quantifierradius > MAXiRad)
radius=MAXiRad;
else
if(quantifierradius < MINiRad)
radius=MINiRad;
else
radius=quantifier*radius;
//setcolor(color);
//circle(320,240,radius);
}
void draw(int c,float quantifier,int fill)
{
if(quantifierradius > MAXiRad)
radius=MAXiRad;
else
if(quantifierradius < MINiRad)
radius=MINiRad;
else
radius=quantifier*radius;
if(fill==0)
{
//setcolor©;
//circle(320,240,radius);
}
else
{
// setfillstyle(1,color);
// fillellipse(320,240,radius,radius);
}
}
};
class Triangle : public Object
{
float side;
int color;
public:
Triangle()
{
side=iSide;
color=1;
}
void draw(float quantifier)
{
if(quantifierside > MAXiSide)
side=MAXiSide;
else
if(quantifierside < MINiSide)
side=MINiSide;
else
side=quantifier*side;
/*Default Color*/
glColor3f(carr[1].r,carr[1].g,carr[1].b);
/* function for triangle*/
glBegin(GL_LINE_LOOP);
glVertex2f(-side,0.0);
glVertex2f(0.0,side);
glVertex2f(side,0.0);
glEnd();
}
void draw(int c,float quantifier,int fill)
{
if(quantifierside > MAXiSide)
side=MAXiSide;
else
if(quantifierside < MINiSide)
side=MINiSide;
else
side=quantifier*side;
/* fuction for setting the color*/
glColor3f(carr[c].r,carr[c].g,carr[c].b);
/* function for triangle*/
if(fill==1)
{
glBegin(GL_POLYGON);
glVertex2f(-side,0.0);
glVertex2f(0.0,side);
glVertex2f(side,0.0);
glEnd();
}
else
{
glBegin(GL_LINE_LOOP);
glVertex2f(-side,0.0);
glVertex2f(0.0,side);
glVertex2f(side,0.0);
glEnd();
}
}
};
class Rectangle : public Object
{
float length;
float breadth;
public:
Rectangle()
{
length=2*iSide;
breadth=iSide;
}
void draw(float quantifier)
{
if(quantifierlength > MAXiSide)
{
length=MAXiSide;
breadth=length/2;
}
else
if(quantifierbreadth < MINiSide/2)
{
breadth=MINiSide/2;
length=2breadth;
}
else
{
length=quantifierlength;
breadth=length/2;
}
/*Default Color*/
glColor3f(carr[1].r,carr[1].g,carr[1].b);
/* function for rectangle*/
glBegin(GL_LINE_LOOP);
glVertex2f((-length/2),0.0);
glVertex2f(length/2,0.0);
glVertex2f(length/2,breadth);
glVertex2f((-length/2),breadth);
glEnd();
}
void draw(int c,float quantifier,int fill)
{
if(quantifierlength > MAXiSide)
{
length=MAXiSide;
breadth=length/2;
}
else
if(quantifierbreadth < MINiSide/2)
{
breadth=MINiSide/2;
length=2breadth;
}
else
{
length=quantifierlength;
breadth=length/2;
}
/*function for setting the color*/
glColor3f(carr[c].r,carr[c].g,carr[c].b);
if(fill==1)
{
/* function for rectangle*/
glBegin(GL_POLYGON);
glVertex2f((-length/2),0.0);
glVertex2f(length/2,0.0);
glVertex2f(length/2,breadth);
glVertex2f((-length/2),breadth);
glEnd();
}
else
{
glBegin(GL_LINE_LOOP);
glVertex2f((-length/2),0.0);
glVertex2f(length/2,0.0);
glVertex2f(length/2,breadth);
glVertex2f((-length/2),breadth);
glEnd();
}
}
};
class Square ublic Object
{
float side;
float width;
public:
Square()
{
side=iSide;
width=iThick;
}
void draw(float quantifier)
{
if(quantifier>=2)
{
quantifier-=2;
if(quantifierwidth > MAXiThick)
width=MAXiThick;
else
if(quantifierwidth < MINiThick)
width=MINiThick;
else
width=quantifierwidth;
glLineWidth(width);
}
else
{
if(quantifierside > MAXiSide)
side=MAXiSide;
else
if(quantifierside < MINiSide)
side=MINiSide;
else
side=quantifierside;
}
/* Default Colour*/
glColor3f(carr[1].r,carr[1].g,carr[1].b);
/* function for square*/
glBegin(GL_LINE_LOOP);
glVertex2f((-side/2),0.0);
glVertex2f(side/2,0.0);
glVertex2f(side/2,side);
glVertex2f((-side/2),side);
glEnd();
}
void draw(int c,float quantifier,int fill)
{if(quantifier>=2)
{
quantifier-=2;
if(quantifierwidth > MAXiThick)
width=MAXiThick;
else
if(quantifierwidth < MINiThick)
width=MINiThick;
else
width=quantifierwidth;
glLineWidth(width);
}
else
{
if(quantifierside > MAXiSide)
side=MAXiSide;
else
if(quantifierside < MINiSide)
side=MINiSide;
else
side=quantifierside;
}
/* fuction for setting the color*/
glColor3f(carr[c].r,carr[c].g,carr[c].b);
if(fill==1)
{
/* function for square*/
glBegin(GL_POLYGON);
glVertex2f((-side/2),0.0);
glVertex2f(side/2,0.0);
glVertex2f(side/2,side);
glVertex2f((-side/2),side);
glEnd();
}
else
{
glBegin(GL_LINE_LOOP);
glVertex2f((-side/2),0.0);
glVertex2f(side/2,0.0);
glVertex2f(side/2,side);
glVertex2f((-side/2),side);
glEnd();
}
}
};
class Ellipse : public Object
{
float radius;
int color;
public:
Ellipse()
{
radius=iRad;
color=1;
}
void draw(float quantifier)
{
if(quantifierradius > MAXiRad)
radius=MAXiRad;
else
if(quantifierradius < MINiRad)
radius=MINiRad;
else
radius=quantifier*radius;
//setcolor(color);
//ellipse(320,240,0,360,radius,radius/2);
}
void draw(int c,float quantifier,int fill)
{
if(quantifierradius > MAXiRad)
radius=MAXiRad;
else
if(quantifierradius < MINiRad)
radius=MINiRad;
else
radius=quantifier*radius;
color=c;
// setfillstyle(1,color);
// fillellipse(320,240,radius,radius/2);
}
};
/* Creating Objects*/
Circle Cobj;
Triangle Tobj;
Rectangle Robj;
Square Sobj;
Ellipse Eobj;
Line Lobj;
float rx=-2.5,ry;
/* glut god!*/
void init(void)
{
glClearColor(1.0,1.0,1.0,1.0);
glShadeModel(GL_FLAT);
}
void init1(void)
{
glClearColor(0.5,0.5,0.5,1.0);
glShadeModel(GL_FLAT);
}
void resh(int w,int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,(GLdouble)w,0.0,(GLdouble)h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,w,h);
}
void disp(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glColor3f(1.0,1.0,1.0);
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(-2.5,2.5);
glVertex2f(2.5,2.5);
glVertex2f(2.5,2.25);
glVertex2f(-2.5,2.25);
glEnd();
//glRasterPos2i(rx,500);
//glFlush();
glutSwapBuffers();
}
void display(void)
{
float q;
int fill=0;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glPushMatrix();
if(!na)
{
if(s1.q2q!=0)
{
if(s1.quantifier<2)
{
if(s1.quantifier<1)
q=s1.quantifier*(1-s1.q2q);
else
q=s1.quantifier*(1+s1.q2q);
}
else
{
s1.quantifier-=2;
if(s1.quantifier<1)
q=s1.quantifier*(1-s1.q2q);
else
q=s1.quantifier*(1+s1.q2q);
q+=2;
}
}
else
q=s1.quantifier;
if(s1.verb==‘p’)
fill=1;
else fill=0;
switch(s1.shape)
{
case ‘c’: if(s1.color==-1)
Cobj.draw(q);
else
Cobj.draw(s1.color,q,fill);
break;
case 't': if(s1.color==-1)
Tobj.draw(q);
else
Tobj.draw(s1.color,q,fill);
break;
case 'r': if(s1.color==-1)
Robj.draw(q);
else
Robj.draw(s1.color,q,fill);
break;
case 's': if(s1.color==-1)
Sobj.draw(q);
else
Sobj.draw(s1.color,q,fill);
break;
case 'i': if(s1.color==-1)
Eobj.draw(q);
else
Eobj.draw(s1.color,q,fill);
break;
case 'l': if(s1.color==-1)
Lobj.draw(q,1);
else
Lobj.draw(q,s1.color);
break;
/*case 'p': if(s1.color==-1)
Pobj.draw(q);
else
Pobj.draw(s1.color,q,fill);
break;
*/
}
}
glFlush();
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei) w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
void keyboard(unsigned char k,int x,int y)
{
glColor3f(0.0,0.0,0.0);
glRasterPos2f(rx,2.27);
if(int(k)!=65)
{
cout<<char(k);
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,k);
rx+=0.1;
glutSwapBuffers();
glutSwapBuffers();
}
else
recogniz();
//glutBitmapCharacter(GLUT_BITMAP_9_BY_15,‘O’);
//disp();
}
int main(int argc,char** argv)
{
int id,id1;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
id=glutCreateWindow("Shape/Colour Tutor");
init();
initColour();
glLineWidth(3);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//recogniz();
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(0,400);
//id1=glutCreateSubWindow(id,0,400,800,600);
glutCreateWindow("Type");
//glutSetWindow(id1);
init1();
glutDisplayFunc(disp);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}