본문 바로가기
프로기(게임, 프로그래밍)/opengl

오픈지엘 무지개 육면체 빙글빙글

by Letssa 렛사 2019. 12. 19.

소스코드

더보기

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

GLfloat Delta = 0.0;

GLfloat MyVertices[8][3] = { {-0.25,-0.25,0.25}, {-0.25,0.25,0.25},
{0.25,0.25,0.25}, {0.25,-0.25,0.25}, {-0.25,-0.25,-0.25},
{-0.25,0.25,-0.25}, {0.25,0.25,-0.25}, {0.25,-0.25,-0.25} };

GLfloat MyColors[8][3] = { {0.2,0.2,0.2},{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} };

GLubyte MyVertexList[24] = { 0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5, 4,5,6,7, 0,1,5,4 };

void MyDisplay() {  
glClear(GL_COLOR_BUFFER_BIT);
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(3, GL_FLOAT, 0, MyColors);
glVertexPointer(3, GL_FLOAT, 0, MyVertices);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(30.0+Delta, 1.0, 1.0, 1.0);
for (GLint i = 0; i < 6; i++)
glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &MyVertexList[4 * i]);
glBegin(glRotatef);
glFlush();
}

void MyTimer(int value) {
Delta = Delta + 10;
glClear(GL_COLOR_BUFFER_BIT);
glutPostRedisplay();
glutTimerFunc(80, MyTimer, 1);
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(300, 300);
glutInitWindowPosition(0, 0);
glutCreateWindow("OpenGL Drawing Example");
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glutDisplayFunc(MyDisplay);
glutTimerFunc(80, MyTimer, 1);
glutMainLoop();
return 0;
}

728x90