いろいろ楽しんで、挑戦しています。
2004/10/23 [23:41:36] (Sat)
OpenGL Programming ???P???????????B
???????????????????B
????????????????????????????????B
http://www.westernvillage.co.jp/openglprogram.htm
http://pc5.2ch.net/test/read.cgi/tech/1091724463/-100
GLUT: http://www.opengl.org/developers/documentation/glut.html
SDL: http://www.libsdl.org/
GLUI: http://www.cs.unc.edu/~rademach/glui/
wxWindows: http://www.wxwindows.org/
FLTK: http://www.fltk.org/
Qt: http://www.trolltech.com/
FOX: http://www.fox-toolkit.org/
csgl(C#): http://csgl.sourceforge.net/
GLT: http://www.nigels.com/glt/
WideStudio: http://www.widestudio.org/
Cal3D: http://cal3d.sourceforge.net/
GtkGLExt: http://gtkglext.sourceforge.net/
JOGL(Java) https://jogl.dev.java.net/
- ??{?A?I?????W?{ -
http://www.opengl.org/documentation/red_book_1.0/
http://3dshaders.com/
- ????T?C?g -
http://www.opengl.org/resources/tutorials/
http://nehe.gamedev.net/
http://www.flipcode.com/
http://www.gamedev.net/
http://esprit.campus.luth.se/~humus/
http://www.exa-corp.co.jp/solution/VISUAL/OpenGL/index.shtml
http://www.t-pot.com/
http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
http://www.gamdev.org/
OpenGL Programming ???P???????????B
???????????????????B
????????????????????????????????B
http://www.westernvillage.co.jp/openglprogram.htm
http://pc5.2ch.net/test/read.cgi/tech/1091724463/-100
GLUT: http://www.opengl.org/developers/documentation/glut.html
SDL: http://www.libsdl.org/
GLUI: http://www.cs.unc.edu/~rademach/glui/
wxWindows: http://www.wxwindows.org/
FLTK: http://www.fltk.org/
Qt: http://www.trolltech.com/
FOX: http://www.fox-toolkit.org/
csgl(C#): http://csgl.sourceforge.net/
GLT: http://www.nigels.com/glt/
WideStudio: http://www.widestudio.org/
Cal3D: http://cal3d.sourceforge.net/
GtkGLExt: http://gtkglext.sourceforge.net/
JOGL(Java) https://jogl.dev.java.net/
- ??{?A?I?????W?{ -
http://www.opengl.org/documentation/red_book_1.0/
http://3dshaders.com/
- ????T?C?g -
http://www.opengl.org/resources/tutorials/
http://nehe.gamedev.net/
http://www.flipcode.com/
http://www.gamedev.net/
http://esprit.campus.luth.se/~humus/
http://www.exa-corp.co.jp/solution/VISUAL/OpenGL/index.shtml
http://www.t-pot.com/
http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
http://www.gamdev.org/
OpenGL??W??
OpenGL??V?[????`??????A?V?[????e??_???W????{????B
????????L???????B
?i?P?j???f???r???[??W??
??_????????f?????u?t???B
????A??_???_??????_?????イ??????_??W?n?B
?i?Q?j???e??W??
?V?[????????N???b?s???O???????e???s???B
?N???b?s???O??r???[?{?????[??(??????p????B
??????e????R?c??????B
?i?R?j?r???[?|?[?g??W??
?V?[????e??_??X?N???[?????????????????????B
???e??W??
??????e(??????e?@)??s???w????B
glMatrixMode(GL_PROJECTION);
???I???????s???P??s?????[?h???B
glLoadIdentity();
?r???[?{?????[??(??????w?????B
???????????A?E?A??A?A??N???b?v??A???N???b?v????W???`
glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 7.0);
??s???e????p???????AglOrtho()??g?p???B
???f???r???[??W??
???f???r???[??s???p??????????w????B
glMatrixMode(GL_MODELVIEW);
???I???????s???P??s?????[?h???B
glLoadIdentity();
?????s??????????B
glTranslatef(0.0f, 0.0f, -5.0f);
????X?P?[???????O???????B
glScalef(2.0f, 2.0f, 2.0f);
?????]???????B
glRotatef(45, 1.0f, 0.0f, 0.0f);
?|?[?g?r???[??W??
glViewport(Left, Bottom, Width, Height);
???`????`????????A?A?X?y?N?g?????p???B
gldAspect = Width / Height;
gluPerspective(30.0f, ???p
gldAspect, ?????A?X?y?N?g?
1.0, ??N???b?v?????
100.0); ???N???b?v?????
glViewport(0, 0, Width, Height);
?????`
OpenGL???W?????????????B
GL_LIGHT0?AGL_LIGHT1?A?E?E?E?E?E?E?AGL_LIGHT7???B
?e?????A?S???^?C?v????????B
?i?P?j????ambient)?F??x??S???????????B
?i?Q?j?g???diffuse)?F??????????A?S????????B
?i?R?j????specular)?F????A????X?|?b?g??????`????????B
?i?S?j????emission)?F?????v?????????o???B
???l??z???????B
GLfloat glfLightAmbient[] = {0.1, 0.1, 0.1, 1.0};
GLfloat glfLightDiffuse[] = {0.7, 0.7, 0.7, 1.0};
GLfloat glfLightSpecular[] = {0.0, 0.0, 0.0, 1.0};
???l??z???penGL??^???B
glLightfv(GL_LIGHT0, GL_AMBIENT, glfLightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, glfLightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR,glfLightSpecular);
glLightfv??g???????
GL_AMBIENT
GL_DIFFUSE
GL_SPECULAR
GL_POSITION
GL_SPOT_DIRECTION
GL_SPOT_EXPONENT
GL_SPOT_CUTOFF
GL_CONSTANT_ATTENUATION
GL_LINEAR_ATTENUATION
GL_QUADRATIC_ATTENUATION
????A????f????L??????B
glEnable(GL_LIGHTING);
???A??????g?p????`????B
glEnable(GL_LIGHT0);
?}?e???A?????`
?V?[??????I?u?W?F?N?g?????????`???B
?i?P?j????ambient)?F?I?u?W?F?N?g?????Y??
?i?Q?j?????diffuse)?F????U???U???????A????????????B
?i?R?j????specular)?F???????????????????s????B
?i?S?j????emission)?F????X?b?|?g??????`??????B
????l??????B
?????????l??i?[???z???????BRGBA??l?B
GLfloat glfMaterialColor[] = {0.0, 0.0, 1.0, 1.0};
OpenGL??^???B
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, glfMaterialColor);
??P?p?????[?^
GL_FRONT
GL_BACK
GL_FRONT_AND_BACK
??Q?p?????[?^
GL_AMBIENT
GL_DIFFUSE
GL_SPECULAR
GL_EMISSION
GL_SHININESS
GL_AMBIENT_AND_DIFFUSE
GL_COLOR_INDEXES
????????
glMaterialfv(GL_FRONT, GL_SHININESS, 90.0f);
??R?p?????[?^??O???P?Q?W
?@????`
OpenGL??A????f????????p??????A
?I?u?W?F?N?g???_??????
?I?u?W?F?N?g????e??_????@????`???K?v?????B
OpenGL????@?????p??????_???????????????B
????@???w???????AglNormal3f()??g?p????B
??????lVertex3f()????o???A
??????_??A???@?????????????B
??j
glBegin(GL_POLYGON);
glNormal3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glEnd;
?V?F?[?f?B???O???f??
OpenGL??A?V?[????X???[?X?V?F?[?f?B???O?A?t???b?g?V?F?[?f?B???O????B
?t???b?g?V?F?[?f?B???O?F?I?u?W?F?N?g??????|???S?????
?|???S??????S??s?N?Z????P?x????
???l??h?????B
?X???[?X?V?F?[?f?B???O?F????|???S????????????????B
?t?H???V?F?[?f?B???O?A?O?[???[?V?F?[?f?B???O?????B
glShadeModel(GL_SMOOTH);
?p?????[?^
GL_FLAT
GL_SMOOTH
?f?v?X?e?X?g
??p?`??e??t?????A?e??p?`??O???W???????K?v?????B
????????A?f?v?X?e?X?g?????B
???f?v?X?e?X?g??L??????B
glEnable(GL_DEPTH_TEST);
?f?v?X?e?X?g???A????o?t?@?[??g?p????
?V?[????????_?????O?????o?t?@?[??N???A????B
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
?B???????
?B???????I??A???S???Y????A
?i?P?jZ??[?g?A???S???Y??
?i?Q?jZ?o?b?t?@?[?A???S???Y??
1280x1024x32bit = 5MBytes???o?b?t?@?[??K?v???B
?i?R?j?X?L???????C???A???S???Y??
???????B
?_?u???o?b?t?@??
?_?u???o?b?t?@?????????A
OpenGL??_?u???o?b?t?@???????????m????K?v?????B
?t?????g?^?o?b?N?o?b?t?@?[??????????????????B
???A???????A??p?v???b?g?z?[?????????????????B
????AWindows???m?F??????B
?????h??W?A???[?J????W
???I?u?W?F?N?g??W??????I?u?W?F?N?g?????????A
?????h????[?J??????????_??p????W????l?????
??P??????????B
?????h??W???_??A?R???f?J???g??W???_?????B
???[?J????W???_??A?I?u?W?F?N?g????S?????B
???n??p????A?u???b?N??????????A
?R???I?u?W?F?N?g?????????????B
????A??L???????????????B
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f);
glRotatef(m_angle2, 0.0f, 1.0f, 0.0f);
auxSolidCube(1.0f);
glTranslatef(0.0f, -1.1f, 0.0f);
auxSolidCube(0.9f);
glTranslatef(0.0f, 2.1f, 0.0f);
auxSolidCube(0.75f);
glFlush();
?`????
?o?b?t?@?????O????penGL?`???????????B
glFlush(void);
?o?b?t?@?????O????penGL?`?????????A
???????????????????????B
glFinish(void);
?s??X?^?b?N
??{????f???r???[????????A
???s????W?????s?????A
????A???s???????
?i??{????f???r???[?????????s???j
???????B
?????????????A?s??X?^?b?N???B
glPushMatrix()?AglPopMatrix()???B
[??{????f???r???[????
glPushMatrix();
[???s????W???
[?`??
glPopMatrix();
[?????f???r???[????
glNewList
glNewList(List?? GL_COMPILE) ? glEndList()
????L????penGL???
[List???????O??L??????B
????A??? glCallList(List?? ????o????B
?}?`???`?????B
glNewList(DRAWCUBE, GL_COMPILE);
[???`???`???
glEndList ();
???A??L???????o????B
for (i=-3.0;i <= 3.0; i++) {
for (j=-3.0;j <= 3.0; j++){
for (k=-3.0;k <= 3.0; k++){
glPushMatrix;
glTranslatef(i, j, k);
glCallList(DRAWCUBE);
glPopMatrix;
}
}
}
???
?????L??
glEnable(GL_BLEND);
???????
glDisable(GL_BLEND);
?????????
glBlendFunc(GLenum sfactor, GLenum dfactor);
??P?p?????[?^ sfactor?FRGBA??[?X????????????w?
GL_ZERO
GL_ONE
GL_DST_COLOR
GL_ONE_MINUS_DST_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA
GL_SRC_ALPHA_SATURATE
??Q?p?????[?^ dfactor?FRGBA?e?X?e?B?l?[?V????????????????w?
GL_ZERO
GL_ONE
GL_SRC_COLOR
GL_ONE_MINUS_SRC_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA
??jglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
?Q????p?`??????d?????????B???d???
?????[?X?A???????e?X?e?B?l?[?V?????????B
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0,1,1,1);
[?e?X?e?B?l?[?V??????p?`?`??
glColor4f(1,0,0,0.5);
[??[?X??p?`?`??
glFlush();
glDisable(GL_BLEND);
??????????A2?x???lColor4f(1,0,0,0.5)??A???t?@?l0.5??g?p?????B
??[?X??d????????e?s?N?Z????????{?A???t?@?l????????B
???A???????e?X?e?B?l?[?V??????d????????e?s?N?Z????????A
?i?P?|?{?A???t?@?l?j????????B
?????A?A???t?@?l???????s??????B
?A???t?@?l????????????B
???????
?????????I?u?W?F?N?g??`???????A
?f?v?X?e?X?g????i???[?h?I?????[?j??????K?v???????B
?????A
?i?P?j?f?v?X?e?X?g?L?
?i?Q?j?s????I?u?W?F?N?g??S??`?
?i?R?j?f?v?X?e?X?g????[?h?I?????[???
?i?S?j?????I?u?W?F?N?g??`?
?i?T?j?f?v?X?e?X?g????[?h?I?????[?^???C?g???
????`?????K?v???????B
??j
glClearColor(0.3,0.3,0.3,0.0);
glClear(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE, GL_ZERO);
GLfloat lightAmbient[] = {0.1f, 0.1f, 0.1f, 0.0f};
GLfloat lightDiffuse[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat lightSpecular[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat lightPosition[] = {2.0f, 0.5f, 3.0f, 1.0f};
GLfloat materialSpecular[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat materialSphere1[] = {1.0f, 0.0f, 0.0f, 0.0f};
GLfloat materialSphere2[] = {0.0f, 1.0f, 0.0f, 0.0f};
GLfloat materialCube[] = {1.0f, 1.0f, 0.0f, 0.0f};
materialCube[] = {1.0f, 1.0f, 0.0f, 0.5f};
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);
glMaterialf(GL_FRONT, GL_SHININESS, 50.0f);
glTranslatef(-1.5f, 0.5f, -3.0f);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialSphere1);
auxSolidSphere(1.0);
glTranslatef(2.0f, -0.8f, 3.0f);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialSphere2);
auxSolidSphere(0.75);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialCube);
glTranslatef(-1.0f, 0.0f, -1.5f);
glRotatef(40.0f, 1.0f, 0.0f, 0.0f);
glRotatef(40.0f, 0.0f, 1.0f, 0.0f);
auxSolidCube(1.0);
glFlush();
glDepthMask(GL_TRUE);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
?A???`?G???A?V???O
?X?N???[??????W???M?[????????????????B
?i?P?j?A???`?G???A?V???O??L????
glEnable(GL_LINE_SMOOTH);
????AGL_POINT_SMOOTH?AGL_POLYGON_SMOOTH???????B
?i?Q?j?????L??
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
?i?R?jOpenGL??X???[?W???O??q???g???
glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
??P?p?????[?^
( GL_FOG_HINT )
GL_LINE_SMOOTH_HINT
( GL_PERSPECTIVE_CORRECTION_HINT )
GL_POINT_SMOOTH_HINT
GL_POLYGON_SMOOTH_HINT
??Q?p?????[?^
GL_DONT_CARE:?D???????
GL_FASTTEST:??????@??g?p??
GL_NICEST:??m???@??g?p??
??j???A???`?G???A?V???O
glClearColor(0.3,0.3,0.3,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth(2.0f);
glShadeModel(GL_FLAT);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
auxWireSphere(1.0);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
?t?H?O
?i?P?j?t?H?O??L??
glEnable(GL_FOG);
?i?Q?j?t?H?O???????
glFogi(GL_FOG_MODE,GL_LINEAR);
??P?p?????[?^
GL_FOG_MODE
??Q?p?????[?^
GL_LINEAR, GL_EXP, GL_EXP2
????AGL_LINEAR?????????A
?t?H?O??J??_??I??_????????B
glFogf(GL_FOG_START, 0.0f);
glFogf(GL_FOG_END,10.0f);
???AGL_EXP, GL_EXP2?????????A
?t?H?O??Z?x??w??????B
glFogf(GL_FOG_DENSITY, 3.0f);
?i?R?j?t?H?O??F???
glFloat fogc[]={0.6f,0.6f,0.5f,1.0f};
glFogfv(GL_FOG_COLOR,fogc);
?i?S?j?t?H?O??q???g???
glHint(GL_FOG_HINT,GL_DONT_CARE);
??P?p?????[?^
GL_FOG_HINT
??Q?p?????[?^
GL_DONT_CARE:?D???????
GL_FASTTEST:??????@??g?p??
GL_NICEST:??m???@??g?p??
??_?z?????p
OpenGL Ver 1.1?????B
???w?I?v???~?e?B?u??????_?????O????????B
?i?P?j???U???z???L???????B
glEnableClientState(GL_NORMAL_ARRAY); ???@?
glEnableClientState(GL_VERTEX_ARRAY); ??_??W
????A GL_COLOR_ARRAY:RGBA?J???[
GL_INDEX_ARRAY:?J???[??W
GL_TEXTURE_COLORD_ARRAY:?e?N?X?`????W
GL_EDGE_FLAG_ARRAY:?|???S????G?b?W?t???O
?????B
????????AglDisableClientState(GL_NORMAL_ARRAY);
?i?Q?j?z??f?[?^???
????A
static GLint vert{25,25,
100,325,
175,25,
175,325};
?i?R?jOpenGL??z???w?
glVertexPointer(size,type,stride,pointer)
glVertexPointer(2,GLint,0,vert);
????A
glColorPointer()
glNormalPointer()
gltexCoordPointer()
glEdgeFlagPointer()
glInterleavedArrays(format,stride,pointer)
?????????z???w??????B
?f?[?^?z???A?e???f?[?^????????????B
?i?S?j?????_?????O
glArrayElement(i)
?L???z?????????Ai?????_????o????B
??j
glBegin(GL_TRIANGLES);
glArrayElement(1);
glArrayElement(2);
glArrayElement(3);
glEnd();
glDrawElements(mode,count,type,indices)
count???v?f??g?p???Amode??????z?B
type??Aindices??^??w?????B
indices??A?f?[?^?z??B
glDrawArrays(mode,first,count)
?L?????z???irst???irst+count-1???z??v?f??p???A
?????????B
OpenGL??V?[????`??????A?V?[????e??_???W????{????B
????????L???????B
?i?P?j???f???r???[??W??
??_????????f?????u?t???B
????A??_???_??????_?????イ??????_??W?n?B
?i?Q?j???e??W??
?V?[????????N???b?s???O???????e???s???B
?N???b?s???O??r???[?{?????[??(??????p????B
??????e????R?c??????B
?i?R?j?r???[?|?[?g??W??
?V?[????e??_??X?N???[?????????????????????B
???e??W??
??????e(??????e?@)??s???w????B
glMatrixMode(GL_PROJECTION);
???I???????s???P??s?????[?h???B
glLoadIdentity();
?r???[?{?????[??(??????w?????B
???????????A?E?A??A?A??N???b?v??A???N???b?v????W???`
glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 7.0);
??s???e????p???????AglOrtho()??g?p???B
???f???r???[??W??
???f???r???[??s???p??????????w????B
glMatrixMode(GL_MODELVIEW);
???I???????s???P??s?????[?h???B
glLoadIdentity();
?????s??????????B
glTranslatef(0.0f, 0.0f, -5.0f);
????X?P?[???????O???????B
glScalef(2.0f, 2.0f, 2.0f);
?????]???????B
glRotatef(45, 1.0f, 0.0f, 0.0f);
?|?[?g?r???[??W??
glViewport(Left, Bottom, Width, Height);
???`????`????????A?A?X?y?N?g?????p???B
gldAspect = Width / Height;
gluPerspective(30.0f, ???p
gldAspect, ?????A?X?y?N?g?
1.0, ??N???b?v?????
100.0); ???N???b?v?????
glViewport(0, 0, Width, Height);
?????`
OpenGL???W?????????????B
GL_LIGHT0?AGL_LIGHT1?A?E?E?E?E?E?E?AGL_LIGHT7???B
?e?????A?S???^?C?v????????B
?i?P?j????ambient)?F??x??S???????????B
?i?Q?j?g???diffuse)?F??????????A?S????????B
?i?R?j????specular)?F????A????X?|?b?g??????`????????B
?i?S?j????emission)?F?????v?????????o???B
???l??z???????B
GLfloat glfLightAmbient[] = {0.1, 0.1, 0.1, 1.0};
GLfloat glfLightDiffuse[] = {0.7, 0.7, 0.7, 1.0};
GLfloat glfLightSpecular[] = {0.0, 0.0, 0.0, 1.0};
???l??z???penGL??^???B
glLightfv(GL_LIGHT0, GL_AMBIENT, glfLightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, glfLightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR,glfLightSpecular);
glLightfv??g???????
GL_AMBIENT
GL_DIFFUSE
GL_SPECULAR
GL_POSITION
GL_SPOT_DIRECTION
GL_SPOT_EXPONENT
GL_SPOT_CUTOFF
GL_CONSTANT_ATTENUATION
GL_LINEAR_ATTENUATION
GL_QUADRATIC_ATTENUATION
????A????f????L??????B
glEnable(GL_LIGHTING);
???A??????g?p????`????B
glEnable(GL_LIGHT0);
?}?e???A?????`
?V?[??????I?u?W?F?N?g?????????`???B
?i?P?j????ambient)?F?I?u?W?F?N?g?????Y??
?i?Q?j?????diffuse)?F????U???U???????A????????????B
?i?R?j????specular)?F???????????????????s????B
?i?S?j????emission)?F????X?b?|?g??????`??????B
????l??????B
?????????l??i?[???z???????BRGBA??l?B
GLfloat glfMaterialColor[] = {0.0, 0.0, 1.0, 1.0};
OpenGL??^???B
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, glfMaterialColor);
??P?p?????[?^
GL_FRONT
GL_BACK
GL_FRONT_AND_BACK
??Q?p?????[?^
GL_AMBIENT
GL_DIFFUSE
GL_SPECULAR
GL_EMISSION
GL_SHININESS
GL_AMBIENT_AND_DIFFUSE
GL_COLOR_INDEXES
????????
glMaterialfv(GL_FRONT, GL_SHININESS, 90.0f);
??R?p?????[?^??O???P?Q?W
?@????`
OpenGL??A????f????????p??????A
?I?u?W?F?N?g???_??????
?I?u?W?F?N?g????e??_????@????`???K?v?????B
OpenGL????@?????p??????_???????????????B
????@???w???????AglNormal3f()??g?p????B
??????lVertex3f()????o???A
??????_??A???@?????????????B
??j
glBegin(GL_POLYGON);
glNormal3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glEnd;
?V?F?[?f?B???O???f??
OpenGL??A?V?[????X???[?X?V?F?[?f?B???O?A?t???b?g?V?F?[?f?B???O????B
?t???b?g?V?F?[?f?B???O?F?I?u?W?F?N?g??????|???S?????
?|???S??????S??s?N?Z????P?x????
???l??h?????B
?X???[?X?V?F?[?f?B???O?F????|???S????????????????B
?t?H???V?F?[?f?B???O?A?O?[???[?V?F?[?f?B???O?????B
glShadeModel(GL_SMOOTH);
?p?????[?^
GL_FLAT
GL_SMOOTH
?f?v?X?e?X?g
??p?`??e??t?????A?e??p?`??O???W???????K?v?????B
????????A?f?v?X?e?X?g?????B
???f?v?X?e?X?g??L??????B
glEnable(GL_DEPTH_TEST);
?f?v?X?e?X?g???A????o?t?@?[??g?p????
?V?[????????_?????O?????o?t?@?[??N???A????B
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
?B???????
?B???????I??A???S???Y????A
?i?P?jZ??[?g?A???S???Y??
?i?Q?jZ?o?b?t?@?[?A???S???Y??
1280x1024x32bit = 5MBytes???o?b?t?@?[??K?v???B
?i?R?j?X?L???????C???A???S???Y??
???????B
?_?u???o?b?t?@??
?_?u???o?b?t?@?????????A
OpenGL??_?u???o?b?t?@???????????m????K?v?????B
?t?????g?^?o?b?N?o?b?t?@?[??????????????????B
???A???????A??p?v???b?g?z?[?????????????????B
????AWindows???m?F??????B
?????h??W?A???[?J????W
???I?u?W?F?N?g??W??????I?u?W?F?N?g?????????A
?????h????[?J??????????_??p????W????l?????
??P??????????B
?????h??W???_??A?R???f?J???g??W???_?????B
???[?J????W???_??A?I?u?W?F?N?g????S?????B
???n??p????A?u???b?N??????????A
?R???I?u?W?F?N?g?????????????B
????A??L???????????????B
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f);
glRotatef(m_angle2, 0.0f, 1.0f, 0.0f);
auxSolidCube(1.0f);
glTranslatef(0.0f, -1.1f, 0.0f);
auxSolidCube(0.9f);
glTranslatef(0.0f, 2.1f, 0.0f);
auxSolidCube(0.75f);
glFlush();
?`????
?o?b?t?@?????O????penGL?`???????????B
glFlush(void);
?o?b?t?@?????O????penGL?`?????????A
???????????????????????B
glFinish(void);
?s??X?^?b?N
??{????f???r???[????????A
???s????W?????s?????A
????A???s???????
?i??{????f???r???[?????????s???j
???????B
?????????????A?s??X?^?b?N???B
glPushMatrix()?AglPopMatrix()???B
[??{????f???r???[????
glPushMatrix();
[???s????W???
[?`??
glPopMatrix();
[?????f???r???[????
glNewList
glNewList(List?? GL_COMPILE) ? glEndList()
????L????penGL???
[List???????O??L??????B
????A??? glCallList(List?? ????o????B
?}?`???`?????B
glNewList(DRAWCUBE, GL_COMPILE);
[???`???`???
glEndList ();
???A??L???????o????B
for (i=-3.0;i <= 3.0; i++) {
for (j=-3.0;j <= 3.0; j++){
for (k=-3.0;k <= 3.0; k++){
glPushMatrix;
glTranslatef(i, j, k);
glCallList(DRAWCUBE);
glPopMatrix;
}
}
}
???
?????L??
glEnable(GL_BLEND);
???????
glDisable(GL_BLEND);
?????????
glBlendFunc(GLenum sfactor, GLenum dfactor);
??P?p?????[?^ sfactor?FRGBA??[?X????????????w?
GL_ZERO
GL_ONE
GL_DST_COLOR
GL_ONE_MINUS_DST_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA
GL_SRC_ALPHA_SATURATE
??Q?p?????[?^ dfactor?FRGBA?e?X?e?B?l?[?V????????????????w?
GL_ZERO
GL_ONE
GL_SRC_COLOR
GL_ONE_MINUS_SRC_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA
??jglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
?Q????p?`??????d?????????B???d???
?????[?X?A???????e?X?e?B?l?[?V?????????B
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0,1,1,1);
[?e?X?e?B?l?[?V??????p?`?`??
glColor4f(1,0,0,0.5);
[??[?X??p?`?`??
glFlush();
glDisable(GL_BLEND);
??????????A2?x???lColor4f(1,0,0,0.5)??A???t?@?l0.5??g?p?????B
??[?X??d????????e?s?N?Z????????{?A???t?@?l????????B
???A???????e?X?e?B?l?[?V??????d????????e?s?N?Z????????A
?i?P?|?{?A???t?@?l?j????????B
?????A?A???t?@?l???????s??????B
?A???t?@?l????????????B
???????
?????????I?u?W?F?N?g??`???????A
?f?v?X?e?X?g????i???[?h?I?????[?j??????K?v???????B
?????A
?i?P?j?f?v?X?e?X?g?L?
?i?Q?j?s????I?u?W?F?N?g??S??`?
?i?R?j?f?v?X?e?X?g????[?h?I?????[???
?i?S?j?????I?u?W?F?N?g??`?
?i?T?j?f?v?X?e?X?g????[?h?I?????[?^???C?g???
????`?????K?v???????B
??j
glClearColor(0.3,0.3,0.3,0.0);
glClear(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE, GL_ZERO);
GLfloat lightAmbient[] = {0.1f, 0.1f, 0.1f, 0.0f};
GLfloat lightDiffuse[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat lightSpecular[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat lightPosition[] = {2.0f, 0.5f, 3.0f, 1.0f};
GLfloat materialSpecular[] = {1.0f, 1.0f, 1.0f, 0.0f};
GLfloat materialSphere1[] = {1.0f, 0.0f, 0.0f, 0.0f};
GLfloat materialSphere2[] = {0.0f, 1.0f, 0.0f, 0.0f};
GLfloat materialCube[] = {1.0f, 1.0f, 0.0f, 0.0f};
materialCube[] = {1.0f, 1.0f, 0.0f, 0.5f};
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);
glMaterialf(GL_FRONT, GL_SHININESS, 50.0f);
glTranslatef(-1.5f, 0.5f, -3.0f);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialSphere1);
auxSolidSphere(1.0);
glTranslatef(2.0f, -0.8f, 3.0f);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialSphere2);
auxSolidSphere(0.75);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialCube);
glTranslatef(-1.0f, 0.0f, -1.5f);
glRotatef(40.0f, 1.0f, 0.0f, 0.0f);
glRotatef(40.0f, 0.0f, 1.0f, 0.0f);
auxSolidCube(1.0);
glFlush();
glDepthMask(GL_TRUE);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
?A???`?G???A?V???O
?X?N???[??????W???M?[????????????????B
?i?P?j?A???`?G???A?V???O??L????
glEnable(GL_LINE_SMOOTH);
????AGL_POINT_SMOOTH?AGL_POLYGON_SMOOTH???????B
?i?Q?j?????L??
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
?i?R?jOpenGL??X???[?W???O??q???g???
glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
??P?p?????[?^
( GL_FOG_HINT )
GL_LINE_SMOOTH_HINT
( GL_PERSPECTIVE_CORRECTION_HINT )
GL_POINT_SMOOTH_HINT
GL_POLYGON_SMOOTH_HINT
??Q?p?????[?^
GL_DONT_CARE:?D???????
GL_FASTTEST:??????@??g?p??
GL_NICEST:??m???@??g?p??
??j???A???`?G???A?V???O
glClearColor(0.3,0.3,0.3,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth(2.0f);
glShadeModel(GL_FLAT);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
auxWireSphere(1.0);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
?t?H?O
?i?P?j?t?H?O??L??
glEnable(GL_FOG);
?i?Q?j?t?H?O???????
glFogi(GL_FOG_MODE,GL_LINEAR);
??P?p?????[?^
GL_FOG_MODE
??Q?p?????[?^
GL_LINEAR, GL_EXP, GL_EXP2
????AGL_LINEAR?????????A
?t?H?O??J??_??I??_????????B
glFogf(GL_FOG_START, 0.0f);
glFogf(GL_FOG_END,10.0f);
???AGL_EXP, GL_EXP2?????????A
?t?H?O??Z?x??w??????B
glFogf(GL_FOG_DENSITY, 3.0f);
?i?R?j?t?H?O??F???
glFloat fogc[]={0.6f,0.6f,0.5f,1.0f};
glFogfv(GL_FOG_COLOR,fogc);
?i?S?j?t?H?O??q???g???
glHint(GL_FOG_HINT,GL_DONT_CARE);
??P?p?????[?^
GL_FOG_HINT
??Q?p?????[?^
GL_DONT_CARE:?D???????
GL_FASTTEST:??????@??g?p??
GL_NICEST:??m???@??g?p??
??_?z?????p
OpenGL Ver 1.1?????B
???w?I?v???~?e?B?u??????_?????O????????B
?i?P?j???U???z???L???????B
glEnableClientState(GL_NORMAL_ARRAY); ???@?
glEnableClientState(GL_VERTEX_ARRAY); ??_??W
????A GL_COLOR_ARRAY:RGBA?J???[
GL_INDEX_ARRAY:?J???[??W
GL_TEXTURE_COLORD_ARRAY:?e?N?X?`????W
GL_EDGE_FLAG_ARRAY:?|???S????G?b?W?t???O
?????B
????????AglDisableClientState(GL_NORMAL_ARRAY);
?i?Q?j?z??f?[?^???
????A
static GLint vert{25,25,
100,325,
175,25,
175,325};
?i?R?jOpenGL??z???w?
glVertexPointer(size,type,stride,pointer)
glVertexPointer(2,GLint,0,vert);
????A
glColorPointer()
glNormalPointer()
gltexCoordPointer()
glEdgeFlagPointer()
glInterleavedArrays(format,stride,pointer)
?????????z???w??????B
?f?[?^?z???A?e???f?[?^????????????B
?i?S?j?????_?????O
glArrayElement(i)
?L???z?????????Ai?????_????o????B
??j
glBegin(GL_TRIANGLES);
glArrayElement(1);
glArrayElement(2);
glArrayElement(3);
glEnd();
glDrawElements(mode,count,type,indices)
count???v?f??g?p???Amode??????z?B
type??Aindices??^??w?????B
indices??A?f?[?^?z??B
glDrawArrays(mode,first,count)
?L?????z???irst???irst+count-1???z??v?f??p???A
?????????B
PR
Comment
ブログ内検索
カウンター
アクセス解析
最新記事のフィルム