图形学作业与答案 doc- 精品课程建设平台(6)

2019-03-22 20:21

ii = *ptr;

else if (j == 1) jj = *ptr; ptr++; }

printf (\

board[ii][jj] = (board[ii][jj] + 1) % 2; } }

#define BUFSIZE 512

void pickSquares(int button, int state, int x, int y) {

GLuint selectBuf[BUFSIZE]; GLint hits;

GLint viewport[4];

if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return;

glGetIntegerv (GL_VIEWPORT, viewport); glSelectBuffer (BUFSIZE, selectBuf); (void) glRenderMode (GL_SELECT); glInitNames(); glPushName(0);

glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity ();

gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),5.0, 5.0, viewport); gluOrtho2D (0.0, 2.0, 0.0, 2.0); drawSquares (GL_SELECT);

glMatrixMode (GL_PROJECTION); glPopMatrix (); glFlush ();

hits = glRenderMode (GL_RENDER); processHits (hits, selectBuf); glutPostRedisplay(); }

void display(void) {

glClear(GL_COLOR_BUFFER_BIT); drawSquares (GL_RENDER); glFlush(); }

void reshape(int w, int h) {

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION); glLoadIdentity();

gluOrtho2D (0.0, 2.0, 0.0, 2.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }

int main(int argc, char** argv) {

glutInit(&argc, argv);

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (200, 200); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init ();

glutMouseFunc (pickSquares); glutReshapeFunc (reshape); glutDisplayFunc(display); glutMainLoop(); return 0; }

6.10编写程序,绘制三个基本图元,并在反馈模式下输出这些图元的三维坐标反馈信息。 #include #include #include void init(void) {

glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); }

void drawGeometry (GLenum mode) {

glBegin (GL_LINE_STRIP); glNormal3f (0.0, 0.0, 1.0); glVertex3f (30.0, 30.0, 0.0); glVertex3f (50.0, 60.0, 0.0); glVertex3f (70.0, 40.0, 0.0); glEnd ();

if (mode == GL_FEEDBACK) glPassThrough (1.0); glBegin (GL_POINTS);

glVertex3f (-100.0, -100.0, -100.0); /* will be clipped */ glEnd ();

if (mode == GL_FEEDBACK) glPassThrough (2.0);

glBegin (GL_POINTS);

glNormal3f (0.0, 0.0, 1.0); glVertex3f (50.0, 50.0, 0.0); glEnd (); }

void print3DcolorVertex (GLint size, GLint *count, GLfloat *buffer) {

int i;

printf (\

for (i = 0; i < 7; i++) {

printf (\*count = *count - 1; }

printf (\}

void printBuffer(GLint size, GLfloat *buffer) {

GLint count; GLfloat token; count = size; while (count) {

token = buffer[size-count]; count--; if (token == GL_PASS_THROUGH_TOKEN) { printf (\

printf (\count--; }

else if (token == GL_POINT_TOKEN) { printf (\

print3DcolorVertex (size, &count, buffer); }

else if (token == GL_LINE_TOKEN) { printf (\

print3DcolorVertex (size, &count, buffer); print3DcolorVertex (size, &count, buffer); }

else if (token == GL_LINE_RESET_TOKEN) { printf (\

print3DcolorVertex (size, &count, buffer); print3DcolorVertex (size, &count, buffer); } } }

void display(void) {

GLfloat feedBuffer[1024]; GLint size;

glMatrixMode (GL_PROJECTION); glLoadIdentity ();

glOrtho (0.0, 100.0, 0.0, 100.0, 0.0, 1.0); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); drawGeometry (GL_RENDER);

glFeedbackBuffer (1024, GL_3D_COLOR, feedBuffer); (void) glRenderMode (GL_FEEDBACK); drawGeometry (GL_FEEDBACK);

size = glRenderMode (GL_RENDER); printBuffer (size, feedBuffer); }

int main(int argc, char** argv) {

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (100, 100); glutInitWindowPosition (100, 100); glutCreateWindow(argv[0]); init();

glutDisplayFunc(display); glutMainLoop(); return 0; }


图形学作业与答案 doc- 精品课程建设平台(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:企业管理中的“与人方便,自己方便”-201311-牛海姣

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: