티스토리 뷰


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

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};  
//GLuint listOne, listTwo, listThree;
int MyListID;
void MyCreateList(){
 MyListID=glGenLists(1);
// listOne=glGenLists(3);
// listTwo=listOne+1;
// listThree=listTwo+1;
 glNewList(MyListID,GL_COMPILE);
 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); 
    for(GLint i = 0; i < 6; i++)      
    glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &MyVertexList[4*i]);
 glEnd();
 glEndList();
}
void MyDisplay( ){ 
    glClear(GL_COLOR_BUFFER_BIT);
 glMatrixMode(GL_MODELVIEW);   
 glLoadIdentity();
 glTranslatef(0.5,0.5,0.0); // 도형이 처음 이동할 장소
  glRotatef(30.0, 1.0, 1.0, 1.0);       
 glCallList(MyListID);
 glTranslatef(-0.5,-0.2,0.0); // 도형의 이동장소인데 좌표대로 가는게 아니라 처음
                                              //그려준  위치에서 +, - 해준다.

 glRotatef(25.0, 1.0, 1.0, 1.0);      
 glCallList(MyListID);
 glTranslatef(-0.5,-0.2,0.0);
 glRotatef(25.0, 1.0, 1.0, 1.0);      
 glCallList(MyListID);
 glFlush( );     

int main(int argc, char** argv) {
    glutInit(&argc,argv);     
    glutInitDisplayMode(GLUT_RGB);  
    glutInitWindowSize(800, 800);     
    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);    
 MyCreateList();
 glutMainLoop( );
    return 0; 
}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함