![]() |
#2
sophialiu2011-05-12 12:03
|

#include <GL/glut.h>
#include <GL/glu.h>
float aVertex[4][3]={{-0.5,0,0},{-0.3,0.8,0},{0.3,0.8,0},{0.5,0,0}};
float bVertex[4][3]={{-0.5,0,0},{-0.66,-0.6,0},{0.66,-0.8,0},{0.5,0,0}};
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(0.4,0.5,0.7,1);
glBegin(GL_POINTS);
glVertex3fv(aVertex[0]);
glVertex3fv(aVertex[1]);
glVertex3fv(aVertex[2]);
glVertex3fv(aVertex[3]);
glEnd();
glColor3f(0.7,0.2,0.2);
glMap1f(GL_MAP1_VERTEX_3,0,1,3,4,&aVertex[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glBegin(GL_LINE_STRIP);
const int NUM=30;
for(int i=0;i<=NUM;++i)
{
glEvalCoord1f(1.0f*i/NUM);
}
glEnd();
glDisable(GL_MAP1_VERTEX_3);
glMap1f(GL_MAP1_VERTEX_3,0,1,3,4,&bVertex[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glBegin(GL_LINE_STRIP);
for(int i=0;i<=NUM;++i)
{
glEvalCoord1f(1.0f*i/NUM);
}
glEnd();
glDisable(GL_MAP1_VERTEX_3);
glutSwapBuffers();
}
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(120,1,0.1,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
}
void init()
{
glClearColor(0,0,0,0);
glShadeModel(GL_SMOOTH);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
#include <GL/glu.h>
float aVertex[4][3]={{-0.5,0,0},{-0.3,0.8,0},{0.3,0.8,0},{0.5,0,0}};
float bVertex[4][3]={{-0.5,0,0},{-0.66,-0.6,0},{0.66,-0.8,0},{0.5,0,0}};
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(0.4,0.5,0.7,1);
glBegin(GL_POINTS);
glVertex3fv(aVertex[0]);
glVertex3fv(aVertex[1]);
glVertex3fv(aVertex[2]);
glVertex3fv(aVertex[3]);
glEnd();
glColor3f(0.7,0.2,0.2);
glMap1f(GL_MAP1_VERTEX_3,0,1,3,4,&aVertex[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glBegin(GL_LINE_STRIP);
const int NUM=30;
for(int i=0;i<=NUM;++i)
{
glEvalCoord1f(1.0f*i/NUM);
}
glEnd();
glDisable(GL_MAP1_VERTEX_3);
glMap1f(GL_MAP1_VERTEX_3,0,1,3,4,&bVertex[0][0]);
glEnable(GL_MAP1_VERTEX_3);
glBegin(GL_LINE_STRIP);
for(int i=0;i<=NUM;++i)
{
glEvalCoord1f(1.0f*i/NUM);
}
glEnd();
glDisable(GL_MAP1_VERTEX_3);
glutSwapBuffers();
}
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(120,1,0.1,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
}
void init()
{
glClearColor(0,0,0,0);
glShadeModel(GL_SMOOTH);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}