Created
November 13, 2016 18:53
-
-
Save fushime2/9bc66c0f3fc888ff5384fd7fdaab9a29 to your computer and use it in GitHub Desktop.
OpenGLでトランプのダイヤの3を表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// トランプのダイヤの3を作成する。 | |
// ポリゴン1,2,3を作り、ポリゴン1,3をそれぞれy軸側に-0.5, +0.5 移動させる。 | |
// 全体を45度回転させる。 | |
// | |
#include <cstdlib> | |
#include <cstdio> | |
#include "GL/glut.h" | |
using namespace std; | |
void display() { | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3d(1.0, 0.0, 0.0); | |
for(int i = 0; i < 3; i++) { | |
glLoadIdentity(); // 初期化 | |
glRotatef(45, 0, 0, 1); // 回転 | |
if(i == 0) glTranslatef(0, -0.5, 0); // ポリゴン 1 を y 軸側に -0.5 移動 | |
if(i == 2) glTranslatef(0, 0.5, 0); // ポリゴン 3 を y 軸側に +0.5 移動 | |
glBegin(GL_POLYGON); | |
glVertex2f(-0.15 + 0.5*(i - 1), 0.15); | |
glVertex2f(0.15 + 0.5*(i - 1), 0.15); | |
glVertex2f(0.15 + 0.5*(i - 1), -0.15); | |
glVertex2f(-0.15 + 0.5*(i - 1), -0.15); | |
glEnd(); | |
} | |
glFlush(); | |
} | |
int main(int argc, char* argv[]){ | |
glutInit(&argc, argv); | |
glutCreateWindow("Three diamond"); | |
glutDisplayFunc(display); | |
glClearColor(1, 1, 1, 1); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment