?? texture.c
字號(hào):
glVertex2i(twidth, theight); glTexCoord2f(-0.5, 1.5); glVertex2i(0, theight); glEnd(); glBegin(GL_POLYGON); glTexCoord2f(-0.5, -0.5); glVertex2i(-1, -1); glTexCoord2f(1.5, -0.5); glVertex2i(1, -1); glTexCoord2f(1.5, 1.5); glVertex2i(1, 1); glTexCoord2f(-0.5, 1.5); glVertex2i(-1, 1); glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glScalef(twidth/2, theight/2, 1.0); glTranslatef(0.5, 0.5, 0.0); glTranslatef(translation[0].value, translation[1].value, translation[2].value); glRotatef(rotation[0].value, rotation[1].value, rotation[2].value, rotation[3].value); glScalef(scale[0].value, scale[1].value, scale[2].value); /* axes */ glPushMatrix(); glTranslatef(-0.001, -0.001, 0.0); glColor3ub(0, 255, 128); glBegin(GL_LINE_STRIP); glVertex2f(0.1, 0.5); glVertex2f(0.0, 0.6); glVertex2f(-0.1, 0.5); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f(0.5, 0.1); glVertex2f(0.6, 0.0); glVertex2f(0.5, -0.1); glEnd(); glBegin(GL_LINE_STRIP); glVertex2f(0.6, 0.0); glVertex2f(0.0, 0.0); glVertex2f(0.0, 0.6); glEnd(); glColor3ub(255, 255, 0); glRasterPos2f(0.6, -0.1); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 's'); glRasterPos2f(-0.1, 0.6); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 't'); glPopMatrix(); glEnable(GL_LINE_STIPPLE); glLineStipple(1, (GLushort)stipple); glColor3ub(255, 0, 0); glBegin(GL_LINE_LOOP); glVertex2f(texcoords[0].value, texcoords[1].value); glVertex2f(texcoords[2].value, texcoords[3].value); glVertex2f(texcoords[4].value, texcoords[5].value); glVertex2f(texcoords[6].value, texcoords[7].value); glEnd(); glLineStipple(1, (GLushort)(stipple^0xffff)); glColor3ub(255, 255, 255); glBegin(GL_LINE_LOOP); glVertex2f(texcoords[0].value, texcoords[1].value); glVertex2f(texcoords[2].value, texcoords[3].value); glVertex2f(texcoords[4].value, texcoords[5].value); glVertex2f(texcoords[6].value, texcoords[7].value); glEnd(); glDisable(GL_LINE_STIPPLE); glutSwapBuffers();}voidworld_menu(int value){ char* name = 0; switch (value) { case 'f': name = "data/fishermen.ppm"; break; case 'o': name = "data/opengl.ppm"; break; case 'c': name = "data/checker.ppm"; break; case 'm': name = "data/marble.ppm"; break; case 't': name = "data/train.ppm"; break; } if (name) { free(image); image = glmReadPPM(name, &iwidth, &iheight); if (!image)
image = glmReadPPM("data/fishermen.ppm", &iwidth, &iheight); } glutSetWindow(screen); texture(); glutSetWindow(world); texture(); redisplay_all();}voidscreen_reshape(int width, int height){ glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)width/height, 0.5, 8.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eye[0], eye[1], eye[2], at[0], at[1], at[2], up[0], up[1],up[2]); glClearColor(0.2, 0.2, 0.2, 1.0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(translation[0].value, translation[1].value, translation[2].value); glRotatef(rotation[0].value, rotation[1].value, rotation[2].value, rotation[3].value); glScalef(scale[0].value, scale[1].value, scale[2].value); glMatrixMode(GL_MODELVIEW);}voidscreen_display(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(spin_y, 1.0, 0.0, 0.0); glRotatef(spin_x, 0.0, 1.0, 0.0); glColor4f(pcolor[0].value, pcolor[1].value, pcolor[2].value, pcolor[3].value); glBegin(GL_POLYGON); glNormal3f(0.0, 0.0, 1.0); glTexCoord2f(texcoords[0].value, texcoords[1].value); glVertex3f(vertices[0].value, vertices[1].value, vertices[2].value); glTexCoord2f(texcoords[2].value, texcoords[3].value); glVertex3f(vertices[3].value, vertices[4].value, vertices[5].value); glTexCoord2f(texcoords[4].value, texcoords[5].value); glVertex3f(vertices[6].value, vertices[7].value, vertices[8].value); glTexCoord2f(texcoords[6].value, texcoords[7].value); glVertex3f(vertices[9].value, vertices[10].value, vertices[11].value); glEnd(); glPopMatrix(); glutSwapBuffers();}int old_x, old_y;voidscreen_mouse(int button, int state, int x, int y){ old_x = x; old_y = y; redisplay_all();}voidscreen_motion(int x, int y){ spin_x = x - old_x; spin_y = y - old_y; redisplay_all();}voidcommand_reshape(int width, int height){ glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, height, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.0, 0.0, 0.0, 0.0); glDisable(GL_DEPTH_TEST);}voidpolygon_display(void){ setfont("helvetica", 12); drawstr(10, pcolor[0].y-50, "glEnable(GL_TEXTURE_2D);"); drawstr(10, pcolor[0].y-30, "gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, " "GL_RGB, GL_UNSIGNED_BYTE, image);"); setfont("helvetica", 18); drawstr(10, pcolor[0].y, "glColor4f("); drawstr(pcolor[0].x+50, pcolor[0].y, ","); drawstr(pcolor[1].x+50, pcolor[1].y, ","); drawstr(pcolor[2].x+50, pcolor[2].y, ","); drawstr(pcolor[3].x+50, pcolor[2].y, ");"); drawstr(10, texcoords[0].y-30, "glBegin(GL_POLYGON);"); drawstr(10, texcoords[0].y, "glTexCoord2f("); drawstr(texcoords[0].x+40, texcoords[0].y, ","); drawstr(texcoords[1].x+40, texcoords[1].y, ");"); drawstr(250, vertices[0].y, "glVertex3f("); drawstr(vertices[0].x+40, vertices[0].y, ","); drawstr(vertices[1].x+40, vertices[1].y, ","); drawstr(vertices[2].x+40, vertices[1].y, ");"); drawstr(10, texcoords[2].y, "glTexCoord2f("); drawstr(texcoords[2].x+40, texcoords[2].y, ","); drawstr(texcoords[3].x+40, texcoords[3].y, ");"); drawstr(250, vertices[3].y, "glVertex3f("); drawstr(vertices[3].x+40, vertices[3].y, ","); drawstr(vertices[4].x+40, vertices[4].y, ","); drawstr(vertices[5].x+40, vertices[5].y, ");"); drawstr(10, texcoords[4].y, "glTexCoord2f("); drawstr(texcoords[4].x+40, texcoords[4].y, ","); drawstr(texcoords[5].x+40, texcoords[5].y, ");"); drawstr(250, vertices[6].y, "glVertex3f("); drawstr(vertices[6].x+40, vertices[6].y, ","); drawstr(vertices[7].x+40, vertices[7].y, ","); drawstr(vertices[8].x+40, vertices[8].y, ");"); drawstr(10, texcoords[6].y, "glTexCoord2f("); drawstr(texcoords[6].x+40, texcoords[6].y, ","); drawstr(texcoords[7].x+40, texcoords[7].y, ");"); drawstr(250, vertices[9].y, "glVertex3f("); drawstr(vertices[9].x+40, vertices[9].y, ","); drawstr(vertices[10].x+40, vertices[10].y, ","); drawstr(vertices[11].x+40, vertices[11].y, ");"); drawstr(10, vertices[11].y+30, "glEnd();"); cell_draw(&texcoords[0]); cell_draw(&texcoords[1]); cell_draw(&texcoords[2]); cell_draw(&texcoords[3]); cell_draw(&texcoords[4]); cell_draw(&texcoords[5]); cell_draw(&texcoords[6]); cell_draw(&texcoords[7]); cell_draw(&vertices[0]); cell_draw(&vertices[1]); cell_draw(&vertices[2]); cell_draw(&vertices[3]); cell_draw(&vertices[4]); cell_draw(&vertices[5]); cell_draw(&vertices[6]); cell_draw(&vertices[7]); cell_draw(&vertices[8]); cell_draw(&vertices[9]); cell_draw(&vertices[10]); cell_draw(&vertices[11]); cell_draw(&pcolor[0]); cell_draw(&pcolor[1]); cell_draw(&pcolor[2]); cell_draw(&pcolor[3]); glColor3ub(255, 255, 255);}voidmatrix_display(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3ub(255, 255, 255); polygon_display(); setfont("helvetica", 18); drawstr(10, translation[0].y-30, "glMatrixMode(GL_TEXTURE);"); drawstr(10, translation[0].y, "glTranslatef("); drawstr(170, translation[0].y, ","); drawstr(230, translation[0].y, ","); drawstr(290, translation[0].y, ");"); drawstr(30, rotation[0].y, "glRotatef("); drawstr(170, rotation[0].y, ","); drawstr(230, rotation[0].y, ","); drawstr(290, rotation[0].y, ","); drawstr(350, rotation[0].y, ");"); drawstr(38, scale[0].y, "glScalef("); drawstr(170, scale[0].y, ","); drawstr(230, scale[0].y, ","); drawstr(290, scale[0].y, ");"); drawstr(10, scale[0].y+30, "glMatrixMode(GL_MODELVIEW);"); cell_draw(&translation[0]); cell_draw(&translation[1]); cell_draw(&translation[2]); cell_draw(&rotation[0]); cell_draw(&rotation[1]); cell_draw(&rotation[2]); cell_draw(&rotation[3]); cell_draw(&scale[0]); cell_draw(&scale[1]); cell_draw(&scale[2]); if (!selection) { glColor3ub(255, 255, 0); drawstr(10, 525, "Click on the arguments and move the mouse to modify values."); } glutSwapBuffers();}voidparameters_display(void){ float pos[4]; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3ub(255, 255, 255); polygon_display(); setfont("helvetica", 18); drawstr(10, bcolor[0].y, "GLfloat border_color[ ] = { "); drawstr(bcolor[0].x+40, bcolor[0].y, ","); drawstr(bcolor[1].x+40, bcolor[0].y, ","); drawstr(bcolor[2].x+40, bcolor[0].y, ","); drawstr(bcolor[3].x+40, bcolor[0].y, "};"); drawstr(10, ecolor[0].y, "GLfloat env_color[ ] = { "); drawstr(ecolor[0].x+40, ecolor[0].y, ","); drawstr(ecolor[1].x+40, ecolor[0].y, ","); drawstr(ecolor[2].x+40, ecolor[0].y, ","); drawstr(ecolor[3].x+40, ecolor[0].y, "};"); setfont("helvetica", 12); drawstr(10, 90, "glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR," " border_color);"); drawstr(10, 110, "glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, " "env_color);"); drawstr(10, 140, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,"); drawstr(10, 160, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,"); drawstr(10, 180, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,"); drawstr(10, 200, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,"); drawstr(10, 220, "glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,"); glColor3ub(0, 255, 128); if (minfilter == GL_LINEAR_MIPMAP_LINEAR) { drawstr(380, 140, "GL_LINEAR_MIPMAP_LINEAR"); } else if (minfilter == GL_LINEAR_MIPMAP_NEAREST) { drawstr(380, 140, "GL_LINEAR_MIPMAP_NEAREST"); } else if (minfilter == GL_NEAREST_MIPMAP_LINEAR) { drawstr(380, 140, "GL_NEAREST_MIPMAP_LINEAR"); } else if (minfilter == GL_NEAREST_MIPMAP_NEAREST) { drawstr(380, 140, "GL_NEAREST_MIPMAP_NEAREST"); } else if (minfilter == GL_LINEAR) { drawstr(380, 140, "GL_LINEAR"); } else { drawstr(380, 140, "GL_NEAREST"); } glColor3ub(255, 255, 255); glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");"); glColor3ub(0, 255, 128); if (magfilter == GL_LINEAR) { drawstr(390, 160, "GL_LINEAR"); } else { drawstr(390, 160, "GL_NEAREST"); } glColor3ub(255, 255, 255); glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");"); glColor3ub(0, 255, 128); if (wraps == GL_REPEAT) { drawstr(360, 180, "GL_REPEAT"); } else { drawstr(360, 180, "GL_CLAMP"); } glColor3ub(255, 255, 255); glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");");
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -