当日のOHP資料です。
Download : sample-001.c ( SJIS 版 )
/*
* CDATE sample-001.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (1) : 空のウィンドウを開く
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#4.1
* 利用方法
* コンパイル
* make
* 実行
* sample-001
*/
#include <GL/glut.h>
void display(void)
{
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
C:\usr\c>sample-001 C:\usr\c>
Download : sample-002.c ( SJIS 版 )
/*
* CDATE sample-002.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (2) : ウィンドウを塗りつぶす
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#4.2
* 利用方法
* コンパイル
* make
* 実行
* sample-002
*/
#include <GL/glut.h>
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void init(void)
{
glClearColor(0.0, 0.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-002 C:\usr\c>
Download : sample-003.c ( SJIS 版 )
/*
* CDATE sample-003.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (3) : 線を引く
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#5.1
* 利用方法
* コンパイル
* make
* 実行
* sample-003
*/
#include <GL/glut.h>
#include <GL/glut.h>
void display(void)
{
glBegin(GL_LINE_LOOP);
glVertex2d(-0.9, -0.9);
glVertex2d(0.9, -0.9);
glVertex2d(0.9, 0.9);
glVertex2d(-0.9, 0.9);
glEnd();
}
void init(void)
{
glClearColor(0.0, 0.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-003 C:\usr\c>
Download : sample-004.c ( SJIS 版 )
/*
* CDATE sample-004.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (4) : 線に色を付ける
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#5.3
* 利用方法
* コンパイル
* make
* 実行
* sample-004
*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3d(1.0, 0.0, 0.0);
glBegin(GL_LINE_LOOP);
glVertex2d(-0.9, -0.9);
glVertex2d(0.9, -0.9);
glVertex2d(0.9, 0.9);
glVertex2d(-0.9, 0.9);
glEnd();
glFlush();
}
void init(void)
{
glClearColor(0.0, 0.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-004 C:\usr\c>
Download : sample-005.c ( SJIS 版 )
/*
* 2013/11/22 sample-005.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (5-1) : 図形を塗りつぶす
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#5.4
* 利用方法
* コンパイル
* make
* 実行
* sample-005
*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3d(1.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d(-0.9, -0.9);
glVertex2d(0.9, -0.9);
glVertex2d(0.9, 0.9);
glVertex2d(-0.9, 0.9);
glEnd();
glFlush();
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-005 C:\usr\c>
Download : sample-006.c ( SJIS 版 )
/*
* 2013/11/22 sample-006.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (5-2) : 図形を塗りつぶす
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#5.4
* 利用方法
* コンパイル
* make
* 実行
* sample-006
*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3d(1.0, 0.0, 0.0); /* 赤 */
glVertex2d(-0.9, -0.9);
glColor3d(0.0, 1.0, 0.0); /* 緑 */
glVertex2d(0.9, -0.9);
glColor3d(0.0, 0.0, 1.0); /* 青 */
glVertex2d(0.9, 0.9);
glColor3d(1.0, 1.0, 0.0); /* 黄 */
glVertex2d(-0.9, 0.9);
glEnd();
glFlush();
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-006 C:\usr\c>
Download : sample-007.c ( SJIS 版 )
/*
* 2013/11/22 sample-007.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (6) : 座標軸とビューポート
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#6.1
* 利用方法
* コンパイル
* make
* 実行
* sample-007
*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3d(1.0, 0.0, 0.0); /* 赤 */
glVertex2d(-0.9, -0.9);
glColor3d(0.0, 1.0, 0.0); /* 緑 */
glVertex2d(0.9, -0.9);
glColor3d(0.0, 0.0, 1.0); /* 青 */
glVertex2d(0.9, 0.9);
glColor3d(1.0, 1.0, 0.0); /* 黄 */
glVertex2d(-0.9, 0.9);
glEnd();
glFlush();
}
void resize(int w, int h)
{
/* ウィンドウ全体をビューポートにする */
glViewport(0, 0, w, h);
/* 変換行列の初期化 */
glLoadIdentity();
/* スクリーン上の表示領域をビューポートの大きさに比例させる */
glOrtho(-w / 200.0, w / 200.0, -h / 200.0, h / 200.0, -1.0, 1.0);
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(resize);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-007 C:\usr\c>
Download : sample-008.c ( SJIS 版 )
/*
* 2013/11/22 sample-008.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (7) : 位置やサイズを指定してウィンドウを開く
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#6.2
* 利用方法
* コンパイル
* make
* 実行
* sample-008
*/
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3d(1.0, 0.0, 0.0); /* 赤 */
glVertex2d(-0.9, -0.9);
glColor3d(0.0, 1.0, 0.0); /* 緑 */
glVertex2d(0.9, -0.9);
glColor3d(0.0, 0.0, 1.0); /* 青 */
glVertex2d(0.9, 0.9);
glColor3d(1.0, 1.0, 0.0); /* 黄 */
glVertex2d(-0.9, 0.9);
glEnd();
glFlush();
}
void resize(int w, int h)
{
/* ウィンドウ全体をビューポートにする */
glViewport(0, 0, w, h);
/* 変換行列の初期化 */
glLoadIdentity();
/* スクリーン上の表示領域をビューポートの大きさに比例させる */
glOrtho(-w / 200.0, w / 200.0, -h / 200.0, h / 200.0, -1.0, 1.0);
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInitWindowPosition(100, 100);
glutInitWindowSize(320, 240);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(resize);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-008 C:\usr\c>
Download : sample-009.c ( SJIS 版 )
/*
* 2013/11/22 sample-009.c
*/
/*
* (C) 床井浩平 (1997-2013)
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html
*
* グラフィックスの利用 (8) : マウスボタンをクリックする
* http://www.wakayama-u.ac.jp/~tokoi/opengl/libglut.html#7.1
* 利用方法
* コンパイル
* make
* 実行
* sample-009
*/
#include <GL/glut.h>
#include <stdio.h>
#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
/* 途中削除 */
glFlush();
}
void resize(int w, int h)
{
/* ウィンドウ全体をビューポートにする */
glViewport(0, 0, w, h);
/* 変換行列の初期化 */
glLoadIdentity();
/* 以下削除 */
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
printf("left");
break;
case GLUT_MIDDLE_BUTTON:
printf("middle");
break;
case GLUT_RIGHT_BUTTON:
printf("right");
break;
default:
break;
}
printf(" button is ");
switch (state) {
case GLUT_UP:
printf("up");
break;
case GLUT_DOWN:
printf("down");
break;
default:
break;
}
printf(" at (%d, %d)\n", x, y);
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}
int main(int argc, char *argv[])
{
glutInitWindowPosition(100, 100);
glutInitWindowSize(320, 240);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(resize);
glutMouseFunc(mouse);
init();
glutMainLoop();
return 0;
}
C:\usr\c>sample-009 C:\usr\c>
ありません