ຍ຺ຈຣາງຄາຌ                                         ິ                            ຃ວຠພິ຤ຽຉີກຢາຟກ                             ...
I.    ພາກລະຽໜີ                 ໄ    ໄ                 ໃ   ີ                                ໃ      ຿ຎຢ຾ກຢຠຌີລໄາຄຂຌຈໄ຤ງ Open...
   ກາຌຽຣວກຉ຺຤ຽຣວກ “Stencil Off”   ກາຌຽຣວກຉ຺຤ຽຣວກ “Stencil On”
III.   Code ຋ັຄໝ຺ຈ          #include <stdio.h>          #include <stdlib.h>          #include <string.h>          #include...
glutKeyboardFunc(keyboard);    glutMainLoop();    return 0;       /* ANSI C requires main to return int. */}voiddrawWirefr...
glColor3f(1.0, 1.0, 0.0);     if (stencilOn) {       glStencilFunc(GL_ALWAYS, 0, 1);       glStencilOp(GL_INVERT, GL_INVER...
stencilOn = 0;                glutSetWindowTitle("Stencil Disabled");                glutPostRedisplay();                b...
Upcoming SlideShare
Loading in …5
×

ບົດລາຍງານ Honda gl09

186
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
186
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ບົດລາຍງານ Honda gl09

  1. 1. ຍ຺ຈຣາງຄາຌ ິ ຃ວຠພິ຤ຽຉີກຢາຟກ ໄ ຦຺຤ຂ: Motion Shape ັລວຌ຿ຈງ: ວ.຅ ຌິຢຌກຸ ຌກຸໃ ຠ: HondaGL09 ຋. ຨວຌຈໄາ ຌາກ຾ລຄ຅ັຌ ຋. ຃ູຠຠີ ພິຠຠະ຅ັກ ຌ. ວາແພ຤ວຌ ຾ກໄ຤ພິຣາ
  2. 2. I. ພາກລະຽໜີ ໄ ໄ ໃ ີ ໃ ຿ຎຢ຾ກຢຠຌີລໄາຄຂຌຈໄ຤ງ OpenGL ຽຆິຄແຈໄຠກາຌຌາເຆໄ Header File “glut.h” ຽຆິຄຽຎຌ ັ Header File ຋ີຣ຤ຠຽວ຺າຽ຃ໃ ວຄຠເຌກາຌຂຼຌ OpenGL ຽວ຺າແ຤ໄ. ພາງເຌ຿ຎຢ຾ກຢຠແຈໄຌາລະຽໜີ ໃ ກາຌລໄາຄພາຍຽ຃ໃ ວຌແ຦຤ຈໄ຤ງກາຌຽຣວກຉ຺຤ຽຣວກ ຽຆິຄຠີຈ຤ງກັຌ຋ັຄໝ຺ຈມູໃ 3 ຉ຺຤ຽຣວກຈໄ຤ງກັຌ ໃ ໄ ຃: Motion, Stencil On, Stencil Off.II. ັ ພາກຎະຉິຍຈ ກາຌຽຨັຈ຤ຼກຂວຄ຿ຎຢ຾ກຢຠ຾ຠໃ ຌຽກີຈ຅າກກາຌ຃ຣິກຂ຤າ຾ຣໄ຤ຽຣວກຉ຺຤ຽຣວກ Motion, ໃ Stencil On ຾ຣະ Stencil Off ຈັຄຨູ ຍພາຍ:  ກາຌຽຣວກຉ຺຤ຽຣວກ “Motion”
  3. 3.  ກາຌຽຣວກຉ຺຤ຽຣວກ “Stencil Off” ກາຌຽຣວກຉ຺຤ຽຣວກ “Stencil On”
  4. 4. III. Code ຋ັຄໝ຺ຈ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <GL/glut.h> static int stencilOn = 1; /* function declarations */ void drawScene(void), setMatrix(void), animation(void), resize(int w, int h), keyboard(unsigned char c, int x, int y), menu(int choice), drawWireframe(int face), drawFilled(int face); /* global variables */ float ax, ay, az; /* angles for animation */ /* coords of a cube */ static GLfloat cube[8][3] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0}; static int faceIndex[6][4] = {0, 1, 2, 3, 1, 4, 5, 2, 4, 7, 6, 5, 7, 0, 3, 6, 3, 2, 5, 6, 7, 4, 1, 0}; int main(int argc, char **argv) { glutInit(&argc, argv); glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_STENCIL | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("Stenciled hidden surface removal"); ax = 10.0; ay = -10.0; az = 0.0; glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutCreateMenu(menu); glutAddMenuEntry("Motion", 3); glutAddMenuEntry("Stencil on", 1); glutAddMenuEntry("Stencil off", 2); glutAttachMenu(GLUT_RIGHT_BUTTON);
  5. 5. glutKeyboardFunc(keyboard); glutMainLoop(); return 0; /* ANSI C requires main to return int. */}voiddrawWireframe(int face){ int i; glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex3fv((GLfloat *) cube[faceIndex[face][i]]); glEnd();}voiddrawFilled(int face){ int i; glBegin(GL_POLYGON); for (i = 0; i < 4; i++) glVertex3fv((GLfloat *) cube[faceIndex[face][i]]); glEnd();}voiddrawScene(void){ int i; glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClearColor(0.5, 0.5, 0.5, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(ax, 1.0, 0.0, 0.0); glRotatef(-ay, 0.0, 1.0, 0.0); /* all the good stuff follows */ if (stencilOn) { glEnable(GL_STENCIL_TEST); glClear(GL_STENCIL_BUFFER_BIT); glStencilMask(1); glStencilFunc(GL_ALWAYS, 0, 1); glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); } glColor3f(1.0, 1.0, 0.0); for (i = 0; i < 6; i++) { drawWireframe(i); if (stencilOn) { glStencilFunc(GL_EQUAL, 0, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } glColor3f(1.0, 0.0, 1.0); drawFilled(i);
  6. 6. glColor3f(1.0, 1.0, 0.0); if (stencilOn) { glStencilFunc(GL_ALWAYS, 0, 1); glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); } glColor3f(1.0, 1.0, 0.0); drawWireframe(i); } glPopMatrix(); if (stencilOn) glDisable(GL_STENCIL_TEST); /* end of good stuff */ glutSwapBuffers();}voidsetMatrix(void){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}int count = 0;voidanimation(void){ /* animate the cone */ ax += 5.0; ay -= 2.0; az += 5.0; if (ax >= 360) ax = 0.0; if (ay <= -360) ay = 0.0; if (az >= 360) az = 0.0; glutPostRedisplay(); count++; if (count >= 60) glutIdleFunc(NULL);}voidmenu(int choice){ switch (choice) { case 3: count = 0; glutIdleFunc(animation); break; case 2:
  7. 7. stencilOn = 0; glutSetWindowTitle("Stencil Disabled"); glutPostRedisplay(); break; case 1: stencilOn = 1; glutSetWindowTitle("Stencil Enabled"); glutPostRedisplay(); break; } } /* ARGSUSED1 */ void keyboard(unsigned char c, int x, int y) { switch (c) { case 27: exit(0); break; default: break; } } void resize(int w, int h) { glViewport(0, 0, w, h); setMatrix(); }IV. ພາກລະ຦ົຸຍ - ລະ຦ົຸຍ຿ຈງ຦ງ ໄ ໃ ໄ ໃ ຏາຌກາຌຂຼຌ຿ຎຢ຾ກຢຠແຈໄເ຦ໄຨູຽຊິຄ຃າລັຄເຌກາຌ຾ຉໄຠຨູ ຍຉໃ າຄໂ, ກາຌໝູຌຨວຍຈໄ຤ງ Rotate ຾ຣະກາຌຽ຃ໃ ວຌງໄາງ຤ັຈຊຸ ຈໄ຤ງ Translate - ໄ ຂ຃຺ຄ຃ໄາຄ ໃ ໃ ໃ ໄ ໄ ໃ ເຌກາຌຂຼຌ຿ຎຢ຾ກຢຠງັຄຠີຍາຄລໃ ຤ຌ຋ີງັຄຍ຋ັຌ຃຺ຍຊໄ຤ຌ ຽຆັຌກາຌເຆໄຽຠ຺າ ລະຌັຌ, ຅ຶຄມາກ ໄ ໄ ໃ ັ ໃ ພັຈ຋ະຌາ຿ຎຢ຾ກຢຠຌີຂຌຽພວຽຎຌ຾ຌ຤຋າຄເຌກາຌພັຈ຋ະຌາເຌຣະຈັຍ຋ີລູ ຄຂຌ. ໄ

×