最終更新: mikk_ni3_92 2007年10月08日(月) 14:49:24履歴
現在地 >> メニュー >> サンプルコード::OpenGL >> 旗の表現
#include <iostream>
#include <cmath>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
void display();
void reshape(int w, int h);
using namespace std;
inline void GLUT_INIT()
{
glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(200,200);
}
inline void GLUT_CALL_FUNC()
{
glutDisplayFunc(display);
glutReshapeFunc(reshape);
}
double points[45][45][3];
inline void MY_INIT()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
for (int y = 0; y < 45; y++)
{
for(int x = 0; x < 45; x++)
{
points[y][x][0]=double((x/5.0)-4.5);
points[y][x][1]=double((y/5.0)-4.5);
points[y][x][2]=double(sin( ( ( (x/5.0)*40.0)/360.0) *3.141592654*2.0));
}
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
GLUT_INIT();
glutCreateWindow("window name");
GLUT_CALL_FUNC();
MY_INIT();
glutMainLoop();
return 0;
}
/********[ここからコールバック]****************************************/
void display()
{
static int r = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(15.0, 16.0, 17.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3d(0,1,0);
glBegin(GL_QUADS);
for (int y = 0; y < 44; y++)
{
for (int x = 0; x < 44; x++)
{
glVertex3d(points[y][x][0], points[y][x][1], points[y][x][2]);
glVertex3d(points[y][x+1][0], points[y][x+1][1], points[y][x+1][2]);
glVertex3d(points[y+1][x+1][0], points[y+1][x+1][1], points[y+1][x+1][2]);
glVertex3d(points[y+1][x][0], points[y+1][x][1],points[y+1][x][2]);
}
}
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
#include <iostream>
#include <cmath>
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
void display();
void reshape(int w, int h);
using namespace std;
inline void GLUT_INIT()
{
glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(200,200);
}
inline void GLUT_CALL_FUNC()
{
glutDisplayFunc(display);
glutReshapeFunc(reshape);
}
double points[45][45][3];
inline void MY_INIT()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
for (int y = 0; y < 45; y++)
{
for(int x = 0; x < 45; x++)
{
points[y][x][0]=double((x/5.0)-4.5);
points[y][x][1]=double((y/5.0)-4.5);
points[y][x][2]=double(sin( ( ( (x/5.0)*40.0)/360.0) *3.141592654*2.0));
}
}
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
GLUT_INIT();
glutCreateWindow("window name");
GLUT_CALL_FUNC();
MY_INIT();
glutMainLoop();
return 0;
}
/********[ここからコールバック]****************************************/
void display()
{
static int r = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(15.0, 16.0, 17.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3d(0,1,0);
glBegin(GL_QUADS);
for (int y = 0; y < 44; y++)
{
for (int x = 0; x < 44; x++)
{
glVertex3d(points[y][x][0], points[y][x][1], points[y][x][2]);
glVertex3d(points[y][x+1][0], points[y][x+1][1], points[y][x+1][2]);
glVertex3d(points[y+1][x+1][0], points[y+1][x+1][1], points[y+1][x+1][2]);
glVertex3d(points[y+1][x][0], points[y+1][x][1],points[y+1][x][2]);
}
}
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}