상세 컨텐츠

본문 제목

OpenGL - 클릭 시 원 그리기

개발 환경/Graphics

by cepiloth 2018. 9. 4. 22:04

본문

728x90
반응형

Visual Studio 2012 에서 Glut 라이브러리를 사용하여 마우스 클릭 시 원 그리는 소스 입니다.


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
87
88
89
90
91
92
93
#include "DrawCircle.h"
 
void drawCircle(int argc, char** argv) {
    glutInit(&argc, argv);
 
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 
    glutInitWindowSize(640480);
 
    glutInitWindowPosition(100100);
 
    glutCreateWindow("Interactive drawing");
 
    init();
 
    glutDisplayFunc(display);
 
    glutMouseFunc(mouse);
 
    glutKeyboardFunc(keyboard);
 
    glutMainLoop();
}
 
void keyboard (unsigned char key, int x, int y)
{
    switch(key)
    {
    case 'q':
    case 'Q':
        exit(0);   
        break;
 
    default:
        break;
    }
}
 
void mouse (int button, int state, int x, int y)
    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        if( num_pts < 100 )
        {
            pts[num_pts][0= x;
            pts[num_pts][1= y;
            num_pts++;
        }
    }
 
    glutPostRedisplay();
}
 
void init (void)
{
    glClearColor(1.0f, 1.0f, 1.0f,1.0f);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0640.0480.0.);
}
 
void display(void)
{
 
    float radius = 25.0f;
 
    //  clear all pixels
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(1.0f, 1.0f, 1.0f,1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glColor3f(1.0f, 0.0f, 1.0f);
 
    for(int i=; i < num_pts ; i++)
    {
        glPushMatrix();
        glTranslatef(pts[i][0],pts[i][1],0.0f);
 
        glBegin(GL_POLYGON);
        for(float fAngle = 0.f ; fAngle < 360.f; fAngle+= 1.0f ) {
            glVertex2f(cos(fAngle) * radius , sin(fAngle) * radius);
 
        }
        glEnd();
        glPopMatrix();
    }
 
    glFlush();
 
}
 
 

cs




728x90
반응형

관련글 더보기

댓글 영역