Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <glut.h>
- #include <stdio.h>
- #include <vector>
- #pragma comment (lib, "opengl32.lib")
- #pragma comment (lib, "glu32.lib")
- #pragma comment(lib,"glut32.lib")
- using namespace std;
- struct type_color {
- int r;
- int g;
- int b;
- };
- type_color colors;
- struct type_pair {
- double x;
- double y;
- };
- vector<vector<type_pair>> points;
- int area = 1;
- void display() {
- glPointSize(10);
- glClearColor(0, 0, 0, 0);
- glColor3ub(colors.r, colors.g, colors.b);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- for (int j = 0; j < area; j++) {
- glBegin(GL_LINE_LOOP);
- for (int i = 0; i < points[j].size(); i++) {
- glVertex2f(points[j][i].x, points[j][i].y);
- }
- glEnd();
- glBegin(GL_POINTS);
- for (int i = 0; i < points[j].size(); i++)
- glVertex2f(points[j][i].x, points[j][i].y);
- glEnd();
- }
- glutSwapBuffers();
- }
- void changeSize(int w, int h) {
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, w, 0, h, -1.0, 1.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void mouseButton(int button, int state, int x, int y) {
- if (button == GLUT_LEFT_BUTTON) {
- if (state == GLUT_DOWN) {
- type_pair elem;
- elem.x = (x - 333.0) / 333;
- elem.y = (333.0 - y) / 333;
- points[area - 1].push_back(elem);
- }
- }
- if (button == GLUT_RIGHT_BUTTON) {
- if (state == GLUT_DOWN) {
- area++;
- points.resize(area);
- }
- }
- glutPostRedisplay();
- }
- void processNormalKeys(unsigned char key, int x, int y) {
- printf("%d %d %d\n", key, x, y);
- switch (key) {
- case '1':
- colors.r = colors.g = colors.g = 255;
- printf("white");
- break;
- case '2':
- colors.r = 255;
- colors.g = colors.g = 0;
- printf("red");
- break;
- }
- }
- void processSpecialKeys(int key, int x, int y) {
- switch (key) {
- case GLUT_KEY_F1:
- glPointSize(10);
- glBegin(GL_POINTS);
- glVertex2f(0, 0.5);
- glEnd();
- case GLUT_KEY_F2:
- glPointSize(10);
- glBegin(GL_POINTS);
- glVertex2f(0, 0);
- glEnd();
- case GLUT_KEY_F3:
- glPointSize(10);
- glBegin(GL_POINTS);
- glVertex2f(-0.5, 0.5);
- glEnd();
- }
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowPosition(400, 400);
- glutInitWindowSize(666, 666);
- glutCreateWindow("New");
- points.resize(1);
- colors.r = colors.g = colors.b = 255;
- //glutReshapeFunc(changeSize);
- glutMouseFunc(mouseButton);
- //glutSpecialFunc(processSpecialKeys);
- glutKeyboardFunc(processNormalKeys);
- glutDisplayFunc(display);
- glutMainLoop();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement