Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // glfw_30.cpp : Defines the entry point for the console application.
- #include "stdafx.h"
- #include <time.h>
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <GL/glew.h>
- #include <GL\glut.h>
- #include <GLFW/glfw3.h>
- #include <vector>
- #include <algorithm>
- #include <cstdlib>
- #define SCREEN_WIDTH 800
- #define SCREEN_HEIGHT 600
- #define SCREEN_POS_X 100
- #define SCREEN_POS_Y 100
- #define DATA_FORMAT 3
- #define BUFFER_SIZE SCREEN_WIDTH*SCREEN_HEIGHT*DATA_FORMAT
- #define PXL_INDX(X,Y,COMP) (((Y)*SCREEN_WIDTH+(X))*DATA_FORMAT+(COMP))
- typedef struct point{
- int x, y;
- point* incident_prev;
- point* incident_next;
- bool extremum;
- } point;
- typedef struct {
- point a, b;
- int x_min, x_max;
- int y_min, y_max;
- }edge;
- bool draw_flag, fill_flag, anti_aliacing_flag, update_flag, thick_flag, clear_flag;
- int x_max, x_min, y_max, y_min;
- GLfloat *contour;
- GLfloat *intrails;
- GLfloat *blur;
- std::vector<point> vertices;
- std::vector<edge> edges;
- std::vector<std::vector<int>> edge_table;
- bool is_white(GLfloat *buff_source, int x, int y)
- {
- if (buff_source[PXL_INDX(x, y, 0)] == 1 &&
- buff_source[PXL_INDX(x, y, 1)] == 1 &&
- buff_source[PXL_INDX(x, y, 2)] == 1
- )
- return true;
- return false;
- }
- bool is_black(GLfloat *buff_source, int x, int y)
- {
- if (buff_source[PXL_INDX(x, y, 0)] == 0 &&
- buff_source[PXL_INDX(x, y, 1)] == 0 &&
- buff_source[PXL_INDX(x, y, 2)] == 0
- )
- return true;
- return false;
- }
- int get_color(int x, int y)
- {
- float red = blur[PXL_INDX(x, y, 0)];
- float green = blur[PXL_INDX(x, y, 1)];
- float blue = blur[PXL_INDX(x, y, 2)];
- return (int)(red*1000.0) + (int)(green*100.0) + (int)(blue*10.0);
- }
- bool even_vertex(int x, int y)
- {
- bool connected_to_top = false;
- bool connected_to_bot = false;
- bool connected_to_side = false;
- if ((contour[PXL_INDX(x - 1, y + 1, 0)] == 1 && contour[PXL_INDX(x - 1, y + 1,1)] == 1 && contour[PXL_INDX(x - 1, y + 1, 2)] == 1) ||
- (contour[PXL_INDX(x, y + 1, 0)] == 1 && contour[PXL_INDX(x, y + 1, 1)] == 1 && contour[PXL_INDX(x, y + 1, 2)] == 1) ||
- (contour[PXL_INDX(x + 1, y + 1, 0)] == 1 && contour[PXL_INDX(x + 1, y + 1, 1)] == 1 && contour[PXL_INDX(x + 1, y + 1, 2)] == 1)) {
- connected_to_top = true;
- }
- if ((contour[PXL_INDX(x - 1, y - 1, 0)] == 1 && contour[PXL_INDX(x - 1, y - 1, 1)] == 1 && contour[PXL_INDX(x - 1, y - 1, 2)] == 1) ||
- (contour[PXL_INDX(x, y - 1, 0)] == 1 && contour[PXL_INDX(x, y - 1, 1)] == 1 && contour[PXL_INDX(x, y - 1, 2)] == 1) ||
- (contour[PXL_INDX(x + 1, y - 1, 0)] == 1 && contour[PXL_INDX(x + 1, y - 1, 1)] == 1 && contour[PXL_INDX(x + 1, y - 1, 2)] == 1)) {
- connected_to_bot = true;
- }
- if ((contour[PXL_INDX(x - 1, y, 0)] == 1 && contour[PXL_INDX(x - 1, y, 1)] == 1 && contour[PXL_INDX(x - 1, y, 2)] == 1) ||
- (contour[PXL_INDX(x+1, y, 0)] == 1 && contour[PXL_INDX(x+1, y, 1)] == 1 && contour[PXL_INDX(x+1, y, 2)] == 1)) {
- connected_to_side = true;
- }
- if (
- ((connected_to_top || connected_to_side) && (connected_to_bot || connected_to_side)) ||
- (connected_to_top && connected_to_bot) ||
- ((connected_to_top && connected_to_side) && (connected_to_bot && connected_to_side))
- )
- return true;
- return false;
- }
- void changeSize(int w, int h)
- {
- if (0 == h) h = 1;
- float ratio = w * 1.0 / h;
- // Use the Projection Matrix
- glMatrixMode(GL_PROJECTION);
- // Reset Matrix
- glLoadIdentity();
- // Set the viewport to be the entire window
- glViewport(0, 0, w, h);
- // Set the correct perspective.
- gluOrtho2D(0, (GLdouble)w, 0, (GLdouble)h);
- // Get Back to the Modelview
- glMatrixMode(GL_MODELVIEW);
- }
- void clear_vector(std::vector<point>& vector)
- {
- vector.clear();
- vector.shrink_to_fit();
- }
- void clear_buffers()
- {
- for (int i = 0; i < BUFFER_SIZE; i++) {
- contour[i] = 0;
- intrails[i] = 0;
- blur[i] = 0;
- }
- }
- void copy_buffer(GLfloat *buff_source, GLfloat *buff_dest)
- {
- for (int i = 0; i < BUFFER_SIZE; i++) {
- buff_dest[i] = buff_source[i];
- }
- }
- void create_buffers()
- {
- contour = new GLfloat[BUFFER_SIZE];
- intrails = new GLfloat[BUFFER_SIZE];
- blur = new GLfloat[BUFFER_SIZE];
- }
- void set_vertices()
- {
- int i;
- //for 0th vertex
- vertices[0].extremum = false;
- vertices[0].incident_next = &vertices[1];
- vertices[0].incident_prev = &vertices[vertices.size()-1];
- //for other vertices
- for (i = 1; i < vertices.size() - 1; i++) {
- vertices[i].incident_next = &vertices[(i + 1) % vertices.size()];
- vertices[i].incident_prev = &vertices[i - 1];
- vertices[i].extremum = false;
- }
- //find extermums
- for (i = 0; i < vertices.size(); i++) {
- if (
- ((*vertices[i].incident_next).y > vertices[i].y && (*vertices[i].incident_prev).y > vertices[i].y) ||
- ((*vertices[i].incident_next).y < vertices[i].y && (*vertices[i].incident_prev).y < vertices[i].y)
- ) {
- vertices[i].extremum = true;
- }
- }
- }
- void Bresenham2(int x1, int y1, int const x2, int const y2)
- {
- int prev, curr;
- prev = y1;
- curr = y1;
- int delta_x(x2 - x1);
- signed char const ix((delta_x > 0) - (delta_x < 0));
- delta_x = std::abs(delta_x) << 1;
- int delta_y(y2 - y1);
- signed char const iy((delta_y > 0) - (delta_y < 0));
- delta_y = std::abs(delta_y) << 1;
- if (0) {
- edge_table[y1 - y_min].push_back(x1);
- edge_table[y1 - y_min].push_back(x1);
- }
- else {
- edge_table[y1 - y_min].push_back(x1);
- }
- if (delta_x >= delta_y)
- {
- int error(delta_y - (delta_x >> 1));
- while (x1 != x2)
- {
- if ((error >= 0) && (error || (ix > 0)))
- {
- error -= delta_x;
- y1 += iy;
- curr = y1;
- }
- error += delta_y;
- x1 += ix;
- if (curr > prev) {
- if (0) {
- edge_table[y1 - y_min].push_back(x1);
- edge_table[y1 - y_min].push_back(x1);
- }
- else {
- edge_table[y1 - y_min].push_back(x1);
- }
- }
- prev = curr;
- }
- }
- else
- {
- int error(delta_x - (delta_y >> 1));
- while (y1 != y2)
- {
- if ((error >= 0) && (error || (iy > 0)))
- {
- error -= delta_y;
- x1 += ix;
- }
- error += delta_x;
- y1 += iy;
- if (0) {
- edge_table[y1 - y_min].push_back(x1);
- edge_table[y1 - y_min].push_back(x1);
- }
- else {
- edge_table[y1 - y_min].push_back(x1);
- }
- }
- }
- }
- void Bresenham(int x1, int y1, int const x2, int const y2)
- {
- int delta_x(x2 - x1);
- // if x1 == x2, then it does not matter what we set here
- signed char const ix((delta_x > 0) - (delta_x < 0));
- delta_x = std::abs(delta_x) << 1;
- int delta_y(y2 - y1);
- // if y1 == y2, then it does not matter what we set here
- signed char const iy((delta_y > 0) - (delta_y < 0));
- delta_y = std::abs(delta_y) << 1;
- //plot(x1, y1);
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1, i)] = 1;
- //========================================
- if (thick_flag) {
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 - 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 - 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 - 1, i)] = 1;
- }
- //========================================
- if (delta_x >= delta_y)
- {
- // error may go below zero
- int error(delta_y - (delta_x >> 1));
- while (x1 != x2)
- {
- if ((error >= 0) && (error || (ix > 0)))
- {
- error -= delta_x;
- y1 += iy;
- }
- // else do nothing
- error += delta_y;
- x1 += ix;
- //plot(x1, y1);
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1, i)] = 1;
- //========================================
- if (thick_flag) {
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 - 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 - 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 - 1, i)] = 1;
- }
- //========================================
- }
- }
- else
- {
- // error may go below zero
- int error(delta_x - (delta_y >> 1));
- while (y1 != y2)
- {
- if ((error >= 0) && (error || (iy > 0)))
- {
- error -= delta_y;
- x1 += ix;
- }
- // else do nothing
- error += delta_x;
- y1 += iy;
- //plot(x1, y1);
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1, i)] = 1;
- //========================================
- if (thick_flag) {
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 + 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 - 1, y1 - 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1, y1 - 1, i)] = 1;
- for (int i = 0; i < DATA_FORMAT; i++) contour[PXL_INDX(x1 + 1, y1 - 1, i)] = 1;
- }
- //========================================
- }
- }
- }
- void draw_complex_line2(point a, point b)
- {
- Bresenham2(a.x, a.y, b.x, b.y);
- }
- void set_contour()//D
- {
- for (int i = 0; i < vertices.size() - 1; i++)
- Bresenham(vertices[i].x, vertices[i].y, vertices[i + 1].x, vertices[i + 1].y);
- }
- void draw_contour()//D
- {
- glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_FLOAT, (void*)contour);
- }
- void init_edges()
- {
- int i;
- edge temp_edge;
- for (i = 0; i < vertices.size(); i++) {
- temp_edge.a = vertices[i];
- temp_edge.b = vertices[(i + 1) % vertices.size()];
- edges.push_back(temp_edge);
- }
- }
- void set_edges()
- {
- set_vertices();
- init_edges();
- int i;
- edge_table.resize(y_max);
- for (i = 0; i < edge_table.size(); i++)
- edge_table[i].resize(0);
- for (int i = 0; i < vertices.size(); i++)
- Bresenham2(vertices[i].x, vertices[i].y, vertices[(i + 1) % vertices.size()].x, vertices[(i + 1) % vertices.size()].y);
- for (i = 0; i < edge_table.size(); i++)
- std::sort(edge_table[i].begin(), edge_table[i].end());
- }
- void set_intrails_vector()//F
- {
- int x, y, k, l, i, j, m, a, component = 0, height;
- bool inside = false, stop_not_found = false;
- int start, stop;
- //copy_buffer(contour, intrails);
- int vector_size = y_max - y_min;
- edge_table.resize(vector_size);
- for (y = y_min + 2, k = 0; y <= y_max - 2; y++, k++) {
- inside = false;
- for (x = x_min - 1; x <= x_max + 1; x++) {
- if (is_white(contour, x, y) && even_vertex(x, y)) {
- inside = true;
- while (is_white(contour, x, y)) {
- x++;
- }
- edge_table[k].push_back(x);
- while (is_black(contour, x, y) && x <= x_max+1 && inside) {
- for (a = 0; a < DATA_FORMAT; a++) {
- intrails[PXL_INDX(x, y, a)] = 1;
- }
- x++;
- }
- edge_table[k].push_back(x);
- while (is_white(contour, x, y)) {
- x++;
- }
- }
- }
- }
- /*
- for (y = y_min + 2, k = 0; y < y_max; y++, k++) {
- start = x_min;
- stop = x_min;
- for (x = x_min - 1; x < x_max + 1; x++) {
- if (is_black(contour, x, y) && is_white(contour, x+1, y)) {
- x++;
- while (is_white(contour, x, y)) {
- x++;
- }
- start = x;
- }
- x++;
- if (is_white(contour, x, y) && is_black(contour, x + 1, y)) {
- stop = x + 1;
- x++;
- while (is_white(contour, x, y)) {
- x++;
- }
- }
- x++;
- if (start < stop) {
- for (i = start; i < stop; i++) {
- intrails[PXL_INDX(i, y, 0)] = 1;
- intrails[PXL_INDX(i, y, 1)] = 1;
- intrails[PXL_INDX(i, y, 2)] = 1;
- }
- }
- }
- }
- */
- /*
- for (y = y_min, k = 0; y < y_max; y++, k++) {
- for (x = x_min, l = 0; x < x_max - 1; x++, l++) {
- stop_not_found = false;
- if (contour[PXL_INDX(x, y, component)] == 0 && contour[PXL_INDX(x+1, y, component)] == 1) {
- m = x;
- while (contour[PXL_INDX(m, y, component)] == 0 && m < x_max) {
- stop_not_found = true;
- m++;
- }
- if (stop_not_found) break;
- edge_table[k].push_back(x);
- }
- }
- }*/
- }
- void set_intrails_pixels()
- {
- int i, j, x, y, z, k;
- int start, stop;
- for (i = 0; i < edge_table.size(); i++) {
- if (edge_table[i].size() % 2 == 0 && 0 != edge_table[i].size()) {
- for (int j = 0; j < edge_table[i].size() - 1; j += 2) {
- int start = edge_table[i][j];
- int stop = edge_table[i][j + 1];
- for (z = start; z < stop; z++) {
- for (int a = 0; a < 3; a++) {
- intrails[PXL_INDX(z, i + y_min, a)] = 1;
- }
- }
- }
- }
- }
- }
- void draw_intrails()//F
- {
- glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_FLOAT, (void*)intrails);
- }
- void postfiltration()//S
- {
- int i, j, k, x, y, num, color;
- GLfloat r, g, b;
- copy_buffer(contour, blur);
- for (y = 0; y < SCREEN_HEIGHT; y++) {
- for (x = 0; x < SCREEN_WIDTH; x++) {
- r = 0;
- g = 0;
- b=0;
- num = 0;
- color = 0;
- if (x + 1 < SCREEN_WIDTH && y + 1 < SCREEN_HEIGHT) {
- num++;
- color += get_color(x + 1, y + 1);
- r += intrails[PXL_INDX(x + 1, y + 1, 0)];
- g += intrails[PXL_INDX(x + 1, y + 1, 1)];
- b += intrails[PXL_INDX(x + 1, y + 1, 2)];
- }
- if (y + 1 < SCREEN_HEIGHT) {
- num++;
- color += get_color(x, y + 1);
- r += intrails[PXL_INDX(x, y + 1, 0)];
- g += intrails[PXL_INDX(x, y + 1, 1)];
- b += intrails[PXL_INDX(x, y + 1, 2)];
- }
- if (x - 1 > 0 && y + 1 < SCREEN_HEIGHT) {
- num++;
- color += get_color(x - 1, y + 1);
- r += intrails[PXL_INDX(x - 1, y + 1, 0)];
- g += intrails[PXL_INDX(x - 1, y + 1, 1)];
- b += intrails[PXL_INDX(x - 1, y + 1, 2)];
- }
- if (x + 1 < SCREEN_WIDTH) {
- num++;
- color += get_color(x + 1, y);
- r += intrails[PXL_INDX(x + 1, y, 0)];
- g += intrails[PXL_INDX(x + 1, y, 1)];
- b += intrails[PXL_INDX(x + 1, y, 2)];
- }
- if (1) {
- num++;
- color += get_color(x, y);
- r += intrails[PXL_INDX(x, y, 0)];
- g += intrails[PXL_INDX(x, y, 1)];
- b += intrails[PXL_INDX(x, y, 2)];
- }
- if (x - 1 > 0) {
- num++;
- color += get_color(x - 1, y);
- r += intrails[PXL_INDX(x - 1, y, 0)];
- g += intrails[PXL_INDX(x - 1, y, 1)];
- b += intrails[PXL_INDX(x - 1, y, 2)];
- }
- if (x + 1 < SCREEN_WIDTH && y - 1 > 0) {
- num++;
- color += get_color(x + 1, y - 1);
- r += intrails[PXL_INDX(x + 1, y - 1, 0)];
- g += intrails[PXL_INDX(x + 1, y - 1, 1)];
- b += intrails[PXL_INDX(x + 1, y - 1, 2)];
- }
- if (y - 1 > 0) {
- num++;
- color += get_color(x, y - 1);
- r += intrails[PXL_INDX(x, y - 1, 0)];
- g += intrails[PXL_INDX(x, y - 1, 1)];
- b += intrails[PXL_INDX(x, y - 1, 2)];
- }
- if (x - 1 > 0 && y - 1 > 0) {
- num++;
- color += get_color(x - 1, y - 1);
- r += intrails[PXL_INDX(x - 1, y - 1, 0)];
- g += intrails[PXL_INDX(x - 1, y - 1, 1)];
- b += intrails[PXL_INDX(x - 1, y - 1, 2)];
- }
- //r = (float)color / 1000.0;
- //g = (float)color / 100.0;
- //b = (float)color / 10.0;
- blur[PXL_INDX(x, y, 0)] = r / (GLfloat)num;
- blur[PXL_INDX(x, y, 1)] = g / (GLfloat)num;
- blur[PXL_INDX(x, y, 2)] = b / (GLfloat)num;
- }
- }
- /*
- for (y = 0; y < SCREEN_HEIGHT; y++) {
- for (x = 0; x < SCREEN_WIDTH; x++) {
- if (contour[PXL_INDX(x, y, 0)] == 1 &&
- contour[PXL_INDX(x, y, 1)] == 1 &&
- contour[PXL_INDX(x, y, 2)] == 1
- ) {
- for (i = 0; i < 3; i++) {
- blur[PXL_INDX(x, y, i)] = 1;
- }
- }
- }
- }*/
- }
- void draw_smoothness()//S
- {
- glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_FLOAT, (void*)blur);
- }
- void figure_pos()
- {
- int max_x = 0, min_x = SCREEN_WIDTH;
- int max_y = 0, min_y = SCREEN_HEIGHT;
- for (int i = 0; i < vertices.size(); i++) {
- if (vertices[i].x > max_x) max_x = vertices[i].x;
- if (vertices[i].x < min_x) min_x = vertices[i].x;
- if (vertices[i].y > max_y) max_y = vertices[i].y;
- if (vertices[i].y < min_y) min_y = vertices[i].y;
- }
- x_max = max_x;
- x_min = min_x;
- y_max = max_y;
- y_min = min_y;
- }
- void renderScene(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if (draw_flag) {
- if (0 != vertices.size()) {
- set_contour();
- draw_contour();
- }
- }
- if (fill_flag) {
- set_edges();
- //set_intrails_vector();
- set_intrails_pixels();
- draw_intrails();
- }
- if (anti_aliacing_flag) {
- postfiltration();
- draw_smoothness();
- }
- if (clear_flag) {
- clear_buffers();
- clear_vector(vertices);
- }
- glutSwapBuffers();
- }
- void mouseButton(int button, int state, int x, int y)
- {
- if (GLUT_LEFT_BUTTON == button) {
- point a;
- if (GLUT_DOWN == state) {
- a.x = x;
- a.y = SCREEN_HEIGHT - y;
- printf("%d %d\n", a.x, a.y);
- vertices.push_back(a);
- figure_pos();
- glutPostRedisplay();
- }
- if (GLUT_UP == state) {
- glutPostRedisplay();
- }
- }
- }
- void keyboardButton(unsigned char key, int x, int y)
- {
- if ('d' == key || 'D' == key) {
- draw_flag = !draw_flag;
- figure_pos();
- printf("x_min=%d x_max=%d\ny_min=%d y_max=%d\n", x_min, x_max, y_min, y_max);
- draw_flag ? printf("drawing:ON\n") : printf("drawing:OFF\n");
- glutPostRedisplay();
- }
- if ('s' == key || 'S' == key) {
- anti_aliacing_flag = !anti_aliacing_flag;
- anti_aliacing_flag ? printf("mode:PS4 / XBOX one\n") : printf("mode:PC\n");
- glutPostRedisplay();
- }
- if ('f' == key || 'F' == key) {
- fill_flag = !fill_flag;
- figure_pos();
- fill_flag ? printf("filling:ON\n") : printf("filling:OFF\n");
- glutPostRedisplay();
- }
- /*if ('z' == key || 'Z' == key) {
- if (0 < vertices.size()) {
- vertices.pop_back();
- figure_pos();
- glutPostRedisplay();
- }
- }*/
- if ('a' == key || 'A' == key) {
- Bresenham(vertices[vertices.size() - 1].x, vertices[vertices.size() - 1].y, vertices[0].x, vertices[0].y);
- glutPostRedisplay();
- }
- if ('q' == key || 'Q' == key) {
- thick_flag = !thick_flag;
- thick_flag ? printf("thick lines:ON\n") : printf("thick lines:OFF\n");
- glutPostRedisplay();
- }
- if ('w' == key || 'W' == key) {
- clear_flag = !clear_flag;
- printf("cleared\n");
- glutPostRedisplay();
- }
- if ('t' == key || 'T' == key) {
- printf("table_size=%d\n", edge_table.size());
- for (int i = 0; i < edge_table.size(); i++) {
- printf("[%d](%d):", i, edge_table[i].size());
- for (int j = 0; j < edge_table[i].size(); j++) {
- printf("%d ", edge_table[i][j]);
- }
- printf(" -> ");
- if (edge_table[i].size() % 2 == 0 && 0 != edge_table[i].size()) {
- for (int j = 0; j < edge_table[i].size() - 1; j += 2) {
- int start = edge_table[i][j];
- int stop = edge_table[i][j + 1];
- printf("%d..%d ", start, stop);
- }
- }
- printf("\n");
- }
- glutPostRedisplay();
- }
- }
- void initial_state()
- {
- glClearColor(0, 0, 0, 1);
- draw_flag = false;
- fill_flag = false;
- anti_aliacing_flag = false;
- update_flag = false;
- thick_flag = false;
- thick_flag ? printf("thick lines:ON\n") : printf("thick lines:OFF\n");
- x_max = 0;
- x_min = SCREEN_WIDTH;
- y_max = 0;
- y_min = SCREEN_HEIGHT;
- create_buffers();
- clear_buffers();
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(SCREEN_POS_X, SCREEN_POS_Y);
- glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
- glutCreateWindow("Anthony's Project: Lab 4");
- glutDisplayFunc(renderScene);
- glutReshapeFunc(changeSize);
- glutIdleFunc(renderScene);
- glutMouseFunc(mouseButton);
- glutKeyboardFunc(keyboardButton);
- initial_state();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement