Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
//#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <time.h>
#include <GL/glut.h>
using namespace std;

int pntX1, pntY1, edges, pivotX, pivotY;
vector<int> pntX;
vector<int> pntY;

double round(double d)
{
	return floor(d + 0.5);
}

void drawAxis(){
    glColor3f(0.0,0.0,0.0);
    glBegin(GL_LINES);
        {
			glVertex3f(-1000,0,0);
			glVertex3f(1000,0,0);
        }glEnd();
    glBegin(GL_LINES);
        {
			glVertex3f(0,-1000,0);
			glVertex3f(0,1000,0);
        }glEnd();
}

void drawPolygon()
{
	glBegin(GL_POLYGON);
	glColor3f(1.0, 0.0, 0.0);
	for (int i = 0; i < edges; i++)
	{
		glVertex2i(pntX[i], pntY[i]);
	}
	glEnd();
}



void myInit (void)
{
        glClearColor(1.0, 1.0, 1.0, 0.0);
        glColor3f(0.0f, 0.0f, 0.0f);
        glPointSize(4.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}





void myDisplay(void)
{
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(0.0, 0.0, 0.0);
        drawAxis();
        drawPolygon();

        glFlush();
}

int main(int argc, char** argv)
{
        cout << "For Polygon:" << endl;

	cout << "Enter no of edges: "; cin >> edges;

	for (int i = 0; i < edges; i++)
	{
		cout << "Enter co-ordinates for vertex  " << i + 1 << " : "; cin >> pntX1 >> pntY1;
		pntX.push_back(pntX1);
		pntY.push_back(pntY1);
	}


        glutInit(&argc, argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize (640, 480);
        glutInitWindowPosition (100, 150);
        glutCreateWindow ("2D object");
        glutDisplayFunc(myDisplay);

        myInit ();
        glutMainLoop();

}