したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

2578774さん:2010/08/01(日) 18:22:29
#define _WCHAR_T_DEFINED

#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>

GLdouble vertex[][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[][4] = {
{ 0, 1, 2, 3 },
{ 1, 5, 6, 2 },
{ 5, 4, 7, 6 },
{ 4, 0, 3, 7 },
{ 4, 5, 1, 0 },
{ 3, 2, 6, 7 }
};

GLdouble color[][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 },
{ 1.0, 0.0, 1.0 },
{ 0.0, 1.0, 1.0 }
};

static int g_screen_w = 0, g_screen_h = 0;

void DrawImage(unsigned int frame){
glRotated((double)frame / 10, 0.0, 1.0, 0.0);

glColor3d(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
for(int i = 0; i < 6; ++i){
glColor3dv(color[i]);
for(int j = 0; j < 4; ++j){
glVertex3dv(vertex[face[i][3 - j]]);
}
}
glEnd();

glPushMatrix();
glTranslated(1.1, -1.1, 0.0);
glBegin(GL_QUADS);
for(int i = 0; i < 6; ++i){
glColor3dv(color[i]);
for(int j = 0; j < 4; ++j){
glVertex3dv(vertex[face[i][3 - j]]);
}
}
glEnd();
glPopMatrix();

glPushMatrix();
glTranslated(0.0, -1.1, -1.1);
glBegin(GL_QUADS);
for(int i = 0; i < 6; ++i){
glColor3dv(color[i]);
for(int j = 0; j < 4; ++j){
glVertex3dv(vertex[face[i][3 - j]]);
}
}
glEnd();
glPopMatrix();

glPushMatrix();
glTranslated(1.1, 0.0, -1.1);
glBegin(GL_QUADS);
for(int i = 0; i < 6; ++i){
glColor3dv(color[i]);
for(int j = 0; j < 4; ++j){
glVertex3dv(vertex[face[i][3 - j]]);
}
}
glEnd();
glPopMatrix();
}

void DisplayProc(){
static unsigned int frame = 0;
//バッファクリア
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


//左目------------------------------------------
glViewport(0, 0, g_screen_w / 2, g_screen_h);

//変換行列
glLoadIdentity();
gluLookAt(2.5, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

DrawImage(frame);

//右目------------------------------------------
glViewport(g_screen_w / 2, 0, g_screen_w / 2, g_screen_h);

//変換行列
glLoadIdentity();
gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

DrawImage(frame);

//画面スワップ
glutSwapBuffers();

frame++;
}

void ResizeProc(int w, int h){
g_screen_w = w;
g_screen_h = h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, (double)(w / 2) / (double)h, 1.0, 100.0);

glMatrixMode(GL_MODELVIEW);
}

void IdleProc(){
glutPostRedisplay();
}

void Initialize(){
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
}

int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(argv[0]);

glutDisplayFunc(DisplayProc);
glutReshapeFunc(ResizeProc);
glutIdleFunc(IdleProc);

Initialize();

glutMainLoop();
return 0;
}


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板