{"id":488,"date":"2021-07-03T11:12:09","date_gmt":"2021-07-03T03:12:09","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=488"},"modified":"2025-10-09T13:55:52","modified_gmt":"2025-10-09T05:55:52","slug":"swust-computer-graphics-experiment-4-sphere-gouraud-illumination-model","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2021\/07\/03\/swust-computer-graphics-experiment-4-sphere-gouraud-illumination-model\/","title":{"rendered":"SWUST \u8ba1\u7b97\u673a\u56fe\u5f62\u5b66 \u5b9e\u9a8c\u56db \u7403\u4f53Gouraud\u5149\u7167\u6a21\u578b"},"content":{"rendered":"<pre><code class=\"language-cpp\">#include &lt;iostream&gt;\n#include &lt;GL\/glut.h&gt;\n\n\/* -- - \u5e38\u91cf-- - *\/\nconst int HEIGHT(800);\nconst int WIDTH(800);\n\nvoid Display();\nvoid Reshape(int w, int h);\nvoid init();\n\nint time(0);\n\nint main(int argc, char** argv)\n{\n    glutInit(&amp;argc, argv);\n    \/\/glut\u521d\u59cb\u5316\n\n    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);\n    \/\/\u53cc\u7f13\u5b58\u6a21\u5f0f\n\n    glutInitWindowSize(WIDTH, HEIGHT);\n    glutInitWindowPosition(50, 100);\n    \/\/\u7a97\u53e3\u521d\u59cb\u5316\n\n    glClearColor(0, 0, 0, 1);\n    \/\/\u7a97\u53e3\u989c\u8272\n\n    glutCreateWindow(&quot;Window - 3D&quot;);\n    \/\/\u7a97\u53e3\n\n    init();\n    glutDisplayFunc(Display);\n    glutReshapeFunc(Reshape);\n    glutMainLoop();\n\n    return 0;\n}\n\nvoid Display()\n{\n    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\n    glutSolidSphere(1.0, 300, 16);\/\/\u534a\u5f84\uff0c\u5357\u5317\u7ecf\u7ebf\uff0c\u7eac\u7ebf\n\n    \/\/\u53cc\u7f13\u5b58\u4f7f\u7528glutSwapBuffers\uff0c\u4f46\u7f13\u5b58glFlush\n    glutSwapBuffers();\n}\n\nvoid Reshape(int w, int h)\n{\n    glViewport(0, 0, (GLsizei)w, (GLsizei)h);\/\/\u4f7f\u50cf\u7d20\u77e9\u9635\u5360\u636e\u6574\u4e2a\u65b0\u7a97\u53e3\n    glMatrixMode(GL_PROJECTION);\/\/\u8bbe\u7f6e\u5f53\u524d\u77e9\u9635\u4e3a\u6295\u5f71\u77e9\u9635\n    glLoadIdentity();\n\n    float nowRange = 1.5;\n    GLfloat nRange = (GLfloat)nowRange;\n\n    if (w &lt;= h) \/\/\u6539\u53d8\u7a97\u53e3\u5927\u5c0f\uff0c\u56fe\u5f62\u5f62\u72b6\u4e0d\u53d8\n        glOrtho(-nRange, nRange, -nRange * h \/ w, nRange * h \/ w, -nRange, nRange);\n    else\n        glOrtho(-nRange * w \/ h, nRange * w \/ h, -nRange, nRange, -nRange, nRange);\n\n    glMatrixMode(GL_MODELVIEW);\/\/\u6a21\u578b\u77e9\u9635,\u544a\u8bc9\u6211\u4eec\u5f53\u524d\u77e9\u9635\n    glLoadIdentity();\n}\n\nvoid init()\n{\n    \/\/\u5149\u6e90light0\n    GLfloat mat_specular[] = { 1.0,1.0,1.0,1.0 };\n    GLfloat mat_shininess[] = { 128.0 };\n\n    GLfloat light_position[] = { 1.0,1.0,1.0,0.0 };\/\/1.0\u8868\u793a\u5149\u6e90\u4e3a\u70b9\u5750\u6807x,y,z\n    GLfloat white_light[] = { 1.0,1.0,1.0,1.0 };   \/\/\u5149\u6e90\u7684\u989c\u8272\n    GLfloat lmodel_ambient[] = { 0.2,0.2,0.2,1.0 };\/\/\u5fae\u5f31\u73af\u5883\u5149\uff0c\u4f7f\u7269\u4f53\u53ef\u89c1\n    glClearColor(0.0, 0.0, 0.0, 1.0);\n    glShadeModel(GL_SMOOTH);\/\/GL_SMOOTH\n\n    \/\/glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);\n    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);\/\/\u6307\u5b9a\u5f53\u524d\u6750\u8d28\u5c5e\u6027 \u955c\u9762\u53cd\u5c04\u989c\u8272\n    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); \/\/\u955c\u9762\u53cd\u5c04\u6307\u6570\n\n    glLightfv(GL_LIGHT0, GL_POSITION, light_position);\/\/\u5149\u6e90\u7f16\u53f7-7\uff0c\u5149\u6e90\u7279\u6027\uff0c\u53c2\u6570\u6570\u636e\n    glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);\n    glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);\n    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); \/\/\u6307\u5b9a\u5168\u5c40\u7684\u73af\u5883\u5149\uff0c\u7269\u4f53\u624d\u80fd\u53ef\u89c1\/\/*\/\n\n    glEnable(GL_LIGHTING);\n    glEnable(GL_LIGHT0);\n    glEnable(GL_DEPTH_TEST);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;iostream&gt; #include &lt;GL\/glut.h&gt; \/* &#8212; &#8211; \u5e38\u91cf&#8","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[238,237],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/488"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=488"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/488\/revisions"}],"predecessor-version":[{"id":489,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/488\/revisions\/489"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}