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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <gl glut.h="">
#define width 600
#define height 400
 
void my_reshape(int w, int h) // 생성된 윈도우창이 움직이거나 변환 되었을때 호출되는 함수
{
 glViewport(0, 0, w, h); // 창 내에서 OpenGL의 렌더링이 진행될 영역을 설정
 // x와 y는 시작되는 위치이고 넓이와 높이는 시작되는 위치에서넓이와 높이를 의미
    glMatrixMode(GL_PROJECTION); // 투영행렬과 모델행렬을 불러오는 함수
    glLoadIdentity(); // 현재 행렬을 초기화 시킨다
 glOrtho(0, 600, 0, 400, -1, 1); // 화면상의 좌표축을 설정하는 함수
}
 
void my_display(void)
{
 glClear(GL_COLOR_BUFFER_BIT);
 glClearColor(0.0, 0.0, 0.0, 1.0);
  
 glColor3f(1.0, 1.0, 0.0); //물체의 색 정의
 glBegin(GL_QUADS); //여러개의 사각형 정의
 glVertex2f(0.0, 0.0); //2차원정수
 glVertex2f(600.0, 0.0);
 glVertex2f(600.0, 400.0);
 glVertex2f(0.0, 400.0);
 glEnd();
  
 glColor3f(1.0, 0.0, 0.0); //물체의 색 정의
 glBegin(GL_LINES); //여러개의 선분 정의
 glVertex2f(0.0, 200.0); //2차원정수
 glVertex2f(600.0, 200.0);
 glEnd();
  
 glColor3f(0.0, 0.0, 1.0); //물체의 색 정의
 glBegin(GL_LINES); //여러개의 선분 정의
 glVertex2f(300.0, .0); //2차원정수
 glVertex2f(300.0, 400.0);
 glEnd();
  
 glColor3f(0.0, 1.0, 0.0); //물체의 색 정의
 glBegin(GL_QUADS); //여러개의 사각형 정의
 glVertex2f(400.0, 350.0); //2차원정수
 glVertex2f(400.0, 250.0);
 glVertex2f(500.0, 250.0);
 glVertex2f(500.0, 350.0);
 glEnd();
  
 glFlush(); // 드라이버에게 더 이상 명령어를 쌓지 말고 현재까지 쌓인 명령어 모두를 무조건 프로세서에게 전달하도록 강제하는 명령
}
 
void my_keyboard(unsigned char key, int x, int y)
{
 switch(key)
 {
 case '1': glViewport(width/2, height/2, width/2, height/2);
  break;
 case '2': glViewport(0, height/2, width/2, height/2);
  break;
 case '3': glViewport(0,0, width/2, height/2);
  break;
 case '4': glViewport(width/2,0, width/2, width/2);
  break;
 case '5': glViewport(width/4, height/4, width/2, height/2);
  break;
 case '6': glViewport(0,0,  width, height);
  break;
 default : break;
 }
  
 glutPostRedisplay();
}
 
void main(int argc, char** argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
 glutInitWindowSize(600, 400);
 glutInitWindowPosition(200,100);
 glutCreateWindow("Viewport_test"); // 새로운 윈도우를 생성하라는 명령
 glutDisplayFunc(my_display); // Mydisply 라는 함수를 디스플레이 이벤트에 대한 콜백함수로 등록
 glutReshapeFunc(my_reshape);
 glutKeyboardFunc(my_keyboard);
 glutMainLoop(); // 메인함수의 마지막은 항상 MainLoop
}
 
 
</gl>






Posted by 코딩하는 야구쟁이
,