|
|
发表于 2006-11-30 14:43:00
|
显示全部楼层
Re:为什么程序运行瞬间就消失了?
#include <gl/glut.h>
#include <stdlib.h>
#define MAX_CPTS 25
GLfloat cpts[MAX_CPTS][3];
int ncpts=0;
static int width=500,height=500;
void drawCurvers()
{
int i;
for(i=0;i<ncpts-3;i+=3)
{
glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,cpts);
glMapGrid1f(30,0.0,1.0);
glEvalMesh1(GL_LINE,0,30);
}
}
static void display()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,0.0f,0.0f);
for(i=0;i<ncpts;i++)
glVertex3f(cpts[0],cpts[1],cpts[2]);
glEnd();
glFlush();
}
static void mouse(int btn,int state,int x,int y)
{
float wx,wy;
if(btn != GLUT_LEFT_BUTTON || state!= GLUT_DOWN)
return;
wx=(2.0*x)/(float)(width-1)-1.0;
wy=(2.0*(height-y))/(float)(height)-1.0;
if(ncpts == MAX_CPTS) return;
cpts[ncpts][0]=wx;
cpts[ncpts][1]=wy;
cpts[ncpts][2]=0.0;
ncpts++;
glutPostRedisplay();
// glPointSize(5.0);
// glBegin(GL_POINT);
// glVertex3f(wx,wy,0.0);
// glEnd();
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'q':
case 'Q':
//exit(1);
break;
case 'C':
case 'c':
ncpts=0;
glutPostRedisplay();
break;
case 'e':
case 'E':
glutPostRedisplay();
break;
case 'b':
case 'B':
//drawCurvers();
break;
}
}
void reshape(int w,int h)
{
width=w;
height=h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(width,height);
glutCreateWindow("Bezier Curer");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,0.0,0.0);
glPointSize(5.0);
//glEnable(GL_MAP1_VERTEX_3);
glutMainLoop();
}
|
|