$B$3$N%Z!<%8$O!"!V(BOpenGL $BF~Lg(B('99/5/6)$B!W$N9V=,2q;qNA$G$9!#(B
$B%*%j%8%J%k%I%-%e%a%s%H$+$iK\J8$OJQ$C$F$$$^$;$s!#(B
$B%;%s%?!<$NL>A0$O!"(B2000$BG/(B4$B7n$h$j>pJs%a%G%#%"650i%;%s%?!<$K!"(B
2006$BG/(B4$B7n$h$j>pJs4pHW%;%s%?!<$K$J$C$F$$$^$9!#(B
[$BCm(B] $B
[$BCm(B2] (ogl-k.c) PI $B$,(B define $B$5$l$F$$$J$$>l9g$K$O!"%W%m%0%i%`$N(B
$B:G=i$NJ}$K!V(B#define PI (3.141592)$B!W$rF~$l$k$+!"(B
$B%3%s%Q%$%k;~$K!V(B-DPI=3.141592$B!W$H%*%W%7%g%s;XDj$7$F$/$@$5$$!#(B
[$BCm(B3] Mac OS X $B$G%3%s%Q%$%k$9$k>l9g$K$O!"$^$:!V(B#include <GL/glut.h>$B!W$r(B
$B!V(B#include <GLUT/glut.h>$B!W$KJQ99$9$k!J(BGL/gl.h$B!"(BGL/glu.h $B$O$=$N$^$^!K$+!"(B
$B$^$?$O!"%G%#%l%/%H%j(B /usr/local/include/GL $B$r:n@.$7$=$3$K(B
/System/Library/Frameworks/GLUT.framework/Versions/A/Headers/glut.h $B$N(B
$B%7%s%\%j%C%/%j%s%/(B glut.h $B$r:n@.$7$F$/$@$5$$!#$=$N>e$G!"(B
cc -framework OpenGL -framework GLUT -framework Foundation FILENAME.c
$B$G%3%s%Q%$%k$7$F$/$@$5$$!#(B
$B9V=,2q!V(BOpenGL $BF~Lg!W$O!"7W;;5!(B ($B$3$3$G$O(B UNIX) $B$N7P83$,$"$j!"(BC $B8@8l$G(B $B%W%m%0%i%`$rAH$s$@$3$H$,$"$k?M!"$=$7$F%0%i%U%#%C%/%9$K6=L#$N$"$k?M$rBP(B $B>]$H$7$F$$$^$9!#$^$?!"K\;qNA$O9V=,2q$N$?$a$N$b$N$G$"$j!";qNA$N$_$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MQ$7$h$&$H$9$k$H!"?t3XE*!"4v2?3XE*$JCN<1$,I,MW$H(B
$B$J$C$F$-$^$9!#!V6bB0!W$N$h$&$JJ*BN!"!V%W%i%9%A%C%/!W$N$h$&$JJ*BN$rI=8=(B
$B$7$?$$>l9g$K$O!"J*M}3XE*!"8w3XE*$JCN<1$,I,MW$H$J$C$F$-$^$9!#$^$?!"?tB?(B
$B$/$"$k(B OpenGL $B$N5!G=$N#1$D$K%F%/%9%A%c%^%C%T%s%0$,$"$j$^$9!"(BOpenGL $BBP(B
$B1~$N%0%i%U%#%C%/%O!<%I%&%(%"$,$"$k>l9g$K$O$=$NA/$d$+$5$H%9%T!<%I$K6C$/(B
$B$3$H$G$7$g$&(B($B$$$d!":r:#$N%2!<%`$K47$l$?3'$5$s$O!"!V$J$s$@!"$3$s$J$b$N(B
$B$+!W$H;W$&$+$bCN$l$^$;$s$M(B ;-<)$B!#0J2<$K!";29M$H$J$k%5%$%H!"=q@R$r$"$2(B
$B$^$9!"3F<+$G4hD%$C$F$_$F$/$@$5$$!#(B$B#2!#$H$j$"$($:IA$$$F$_$k(B
2.1 $B%3%s%Q%$%k$N;EJ}(B
% gcc filename.c -L/usr/X11R6/lib -lglut -lGLU -lGL -lXmu -lXi -lXext -lX11 -lm
/*-oglcc---------------------------------------*/
gcc $* -L/usr/X11R6/lib -lglut -lGLU -lGL -lXmu -lXi -lXext -lX11 -lm
/*----------------------------------------*/
% oglcc filename.c
$B$H%3%s%Q%$%k$9$k$H!"(Ba.out $B$H$$$&L>A0$N% a.out
$B$G% /u/adm/kenji/bin/cpogl
$B$H2.2 $B%&%#%s%I%&$HD>@~(B
/*-ogl01.c---------------------------------------*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
glColor3d(1.0, 0.0, 0.0);
glVertex2d(-0.7, -0.7);
glVertex2d(0.7, -0.7);
glVertex2d(0.0, 0.7);
glEnd();
}
void keyboard(unsigned char key, int x, int y)
{
if (key == '\033') exit(0); /* '\033' $B$O(B ESC $B$N(B ASCII $B%3!<%I(B */
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glClearColor(1.0, 1.0, 1.0, 0.0);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
/*----------------------------------------*/
GL_POINTS $BE@$rBG$A$^$9!#(B
GL_LINES $B#2E@$rBP$K$7$F!"$=$N4V$rD>@~$G7k$S$^$9!#(B
GL_LINE_STRIP $B@^$l@~$rIA$-$^$9!#(B
GL_LINE_LOOP $B@^$l@~$rIA$-$^$9!#;OE@$H=*E@$N4V$b7k$P$l$^$9!#(B
GL_TRIANGLES / GL_QUADS
$B#3!?#4E@$rAH$K$7$F!";03Q7A!?;M3Q7A$rIA$-$^$9!#(B
GL_TRIANGLE_STRIP / GL_QUAD_STRIP
$B0lJU$r6&M-$7$J$,$iBS>u$K;03Q7A!?;M3Q7A$rIA$-$^$9!#(B
GL_TRIANGLE_FAN $B0lJU$r6&M-$7$J$,$i@p>u$K;03Q7A$rIA$-$^$9!#(B
GL_POLYGON $BFLB?3Q7A$rIA$-$^$9!#(B
glClearColor(1.0, 1.0, 1.0, 0.0);
$B$N?'$N;XDj$rJQ99$7$F$_$F$/$@$5$$!#$^$?!"(B
glColor3d(1.0, 0.0, 0.0);
glVertex2d(-0.7, -0.7);
$B$ND:E@(B (vertex) $B$N;XDj$rJQ99$7$?$j!"A}$d$7$?$j$7$F$_$F$/$@$5$$!#(B
$B;W$C$?DL$j$KI=<($5$l$^$7$?$+!)(B2.3 $BEI$j$D$V$7$F$_$k(B
/*-ogl02.c---------------------------------------*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3d(1.0, 0.0, 0.0);
glVertex2d(-0.7, -0.7);
glColor3d(0.0, 1.0, 0.0);
glVertex2d(0.7, -0.7);
glColor3d(0.0, 0.0, 1.0);
glVertex2d(0.0, 0.7);
glEnd();
}
/*-$B0J2
2.4 $B:BI8<4$r9M$($k(B
/*-ogl03.c---------------------------------------*/
/*-$B$3$3$^$G!"(Bogl02.c $B$HF1$8(B-*/
void resize(int w, int h) /*-$B4X?tDI2C(B-*/
{
glViewport(0, 0, w, h);
glLoadIdentity();
glOrtho(-w / 200.0, w / 200.0, -h / 200.0, h / 200.0, -1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInitWindowPosition(100, 100); /*-$BDI2C(B-*/
glutInitWindowSize(320, 240); /*-$BDI2C(B-*/
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glClearColor(1.0, 1.0, 1.0, 0.0);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(resize); /*-$BDI2C(B-*/
glutMainLoop();
return 0;
}
/*----------------------------------------*/
$B#3!#$d$C$H#3
3.1 $B@~2h$rI=<($7$F$_$k(B
/*-ogl04.c---------------------------------------*/
#include <GL/glut.h>
void display(void)
{
int i;
GLdouble vertex[8][3] = {
{ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 },
{ 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 }, { 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0 }
};
int edge[12][2] = {
{ 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 },
{ 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 },
{ 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 }
};
glClear(GL_COLOR_BUFFER_BIT);
glColor3d(0.0, 0.0, 0.0);
glBegin(GL_LINES);
for (i = 0; i < 12; i++) {
glVertex3dv(vertex[edge[i][0]]);
glVertex3dv(vertex[edge[i][1]]);
}
glEnd();
}
void keyboard(unsigned char key, int x, int y)
{
if (key == '\033') exit(0);
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glClearColor(1.0, 1.0, 1.0, 0.0);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(resize);
glutMainLoop();
return 0;
}
/*----------------------------------------*/
/*-ogl04.c-2--------------------------------------*/
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glLoadIdentity();
gluPerspective(30.0, 1.0, 1.0, 10.0);
glTranslated(0.0, 0.0, -5.0);
glRotated(5.0, 1.0, 1.0, 0.0);
}
/*----------------------------------------*/
/*-ogl04.c-3--------------------------------------*/
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glLoadIdentity();
gluPerspective(30.0, 1.0, 1.0, 10.0);
gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
/*----------------------------------------*/
3.2 $B%"%K%a!<%7%g%s(B
$B!V%b%G%j%s%0JQ49!W(B $BN)J}BN$N6u4VFb$N0LCV!"8~$-(B
$B!V%S%e!<%$%s%0JQ49!W(B $B$=$N6u4V$r8+$k;kE@!";k@~J}8~(B
$B!VEj1FJQ49!W(B $B%9%/%j!<%s$X$NEj1FJ}K!(B
/*-ogl05.c---------------------------------------*/
#include <GL/glut.h>
void idle(void)
{
glutPostRedisplay();
}
void display(void)
{
int i;
static int r = 0; /* $BN)J}BN$N2sE>3Q(B */
GLdouble vertex[8][3] = {
{ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 },
{ 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 }, { 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0 }
};
int edge[12][2] = {
{ 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 },
{ 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 },
{ 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 }
};
glClear(GL_COLOR_BUFFER_BIT);
/* $B%b%G%k%S%e!
3.3 $B%@%V%k%P%C%U%!(B
/*-ogl05.c-2--------------------------------------*/
$B!'(B
void display(void)
$B!'(B
glEnd();
glutSwapBuffers(); /* $BDI2C(B */
if (++r >= 360) r = 0;
$B!'(B
int main(int argc, char *argv[])
$B!'(B
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); /* $BJQ99(B */
$B!'(B
/*----------------------------------------*/
glRotated((GLdouble) r, 0.0, 1.0, 0.0);
$B$N2sE><4$rJQ99$7$F$_$^$7$g$&!#$&$^$/2s$j$^$7$?$+!)(B3.4 $B1#LL>C5n(B
/*-ogl06.c---------------------------------------*/
#include <GL/glut.h>
void idle(void)
{
glutPostRedisplay();
}
void display(void)
{
int i, j;
static int r = 0;
GLdouble vertex[8][3] = {
{ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 },
{ 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 }, { 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0 }
};
int face[6][4] = {
{ 0, 3, 2, 1 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 },
{ 0, 4, 7, 3 }, { 0, 1, 5, 4 }, { 2, 3, 7, 6 }
};
GLdouble color[6][3] = {
{ 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 },
{ 1.0, 1.0, 0.0 }, { 0.0, 1.0, 1.0 }, { 1.0, 0.0, 1.0 }
};
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotated((GLdouble)r, 0.0, 1.0, 0.0);
glColor3d(0.0, 0.0, 0.0);
glBegin(GL_QUADS);
for (j = 0; j < 6; j++) {
glColor3dv(color[j]);
for (i = 0; i < 4; i++) {
glVertex3dv(vertex[face[j][i]]);
}
}
glEnd();
glutSwapBuffers();
if (++r >= 360) r = 0;
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, 1.0, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y)
{
if (key == '\033') exit(0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow(argv[0]);
glClearColor(1.0, 1.0, 1.0, 0.0);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutIdleFunc(idle);
glutReshapeFunc(resize);
glutMainLoop();
}
/*----------------------------------------*/
/*-ogl06.c-2--------------------------------------*/
$B!'(B
void display(void)
$B!'(B
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT /* $B=$@5(B */);
glEnable(GL_DEPTH_TEST); /* $BDI2C(B */
$B!'(B
glEnd();
glDisable(GL_DEPTH_TEST); /* $BDI2C(B */
glutSwapBuffers();
$B!'(B
int main(int argc, char *argv[])
$B!'(B
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH /* $B=$@5(B */);
$B!'(B
/*----------------------------------------*/
$B#4!#%7%'!<%G%#%s%0(B
4.1 $B%i%$%F%#%s%0$H%^%F%j%"%k(B
/*-ogl07.c---------------------------------------*/
#include <GL/glut.h>
void idle(void)
{
glutPostRedisplay();
}
void display(void)
{
int i, j;
static int r = 0;
GLdouble vertex[8][3] = {
{ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 },
{ 1.0, 1.0, 0.0 }, { 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 }, { 1.0, 0.0, 1.0 },
{ 1.0, 1.0, 1.0 }, { 0.0, 1.0, 1.0 }
};
int face[6][4] = {
{ 0, 3, 2, 1 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 },
{ 0, 4, 7, 3 }, { 0, 1, 5, 4 }, { 2, 3, 7, 6 }
};
GLdouble normal[6][3] = {
{ 0.0, 0.0,-1.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 },
{-1.0, 0.0, 0.0 }, { 0.0,-1.0, 0.0 }, { 0.0, 1.0, 0.0 }
};
GLfloat lpos[4] = {5.0, 5.0, 0.0, 1.0};
GLfloat lcol[4] = {0.5, 1.0, 0.5, 1.0};
GLfloat mcol[4] = {1.0, 0.5, 0.5, 1.0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLoadIdentity();
gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotated((GLdouble)r, 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
for (j = 0; j < 6; j++) {
glNormal3dv(normal[j]);
for (i = 0; i < 4; i++) {
glVertex3dv(vertex[face[j][i]]);
}
}
glEnd();
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glutSwapBuffers();
if (++r >= 360) r = 0;
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, 1.0, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y)
{
if (key == '\033') exit(0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(argv[0]);
glClearColor(1.0, 1.0, 1.0, 0.0);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutIdleFunc(idle);
glutReshapeFunc(resize);
glutMainLoop();
}
/*----------------------------------------*/
/*-ogl07.c-2--------------------------------------*/
$B!'(B
void display(void)
$B!'(B
gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glLightfv(GL_LIGHT0, GL_POSITION, lpos); /* $BDI2C#1(B */
glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol); /* $BDI2C#2(B */
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mcol); /* $BDI2C#3(B */
glRotated((GLdouble)r, 0.0, 1.0, 0.0);
$B!'(B
/*----------------------------------------*/
4.2 $B%9%`!<%:%7%'!<%G%#%s%0(B
$B#5!#$5$$$4$K$b$&>/$7!D(B
5.1 $BJQ499TNs$N3,AX9=B$(B
+ + + + + +
|x'| | cos(a) sin(a) 0| |x|
|y'| = |-sin(a) cos(a) 0| * |y|
|z'| | 0 0 1| |z|
+ + + + + +
+ + + + + +
|x'| | cos(a) sin(a) 0 l| |x|
|y'| = |-sin(a) cos(a) 0 m| * |y|
|z'| | 0 0 1 n| |z|
|1 | | 0 0 0 1| |1|
+ + + + + +
5.2 $BK\Ev$N$5$$$4$K(B
5.3 $B;29M(B URL$B!"=q@R(B
OpenGL, MesaGL:
http://www.ssec.wisc.edu/~brianp/Mesa.html
http://www.sgi.com/Technology/OpenGL/Windows/index.html
ftp://ftp.microsoft.com/softlib/MSLFILES/opengl95.exe
GLUT:
http://reality.sgi.com/mjk_asd/glut3/glut3.html
------------------------------------------------------------------------
$B=q@RL>!'(B OpenGL Reference Manual ($BF|K\8lHG(B)
The Official Reference Document for OpenGL, Release 1
$BCx