Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Hearn & Baker */
- #include <windows.h>
- #include <math.h>
- #include <stdlib.h>
- #include <GL/freeglut.h>
- const double TWO_PI = 6.2831853;
- GLsizei winWidth = 700, winHeight = 700;
- GLuint regHex;
- static GLfloat rotTheta = 0.0;
- class scrPt
- {
- public:
- GLint x, y;
- };
- static void init(void)
- {
- scrPt hexVertex;
- GLdouble hexTheta;
- GLint k;
- glClearColor(1.0, 1.0, 1.0, 1.0);
- regHex = glGenLists(2);
- glNewList(regHex, GL_COMPILE);
- glColor3f(0.0, 1.0, 0.0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glBegin(GL_POLYGON);
- for (k = 0; k < 100; k++)
- {
- hexTheta = TWO_PI * k / 100;
- hexVertex.x = 150 + 100 * cos(hexTheta);
- hexVertex.y = 150 + 100 * sin(hexTheta);
- glVertex2i(hexVertex.x, hexVertex.y);
- }
- glEnd();
- glEndList();
- glNewList(regHex + 1, GL_COMPILE);
- glColor3f(0.0, 0.0, 1.0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glBegin(GL_POLYGON);
- for (k = 0; k < 100; k++)
- {
- hexTheta = TWO_PI * k / 100;
- hexVertex.x = 150 + 130 * cos(hexTheta);
- hexVertex.y = -150 + 130 * sin(hexTheta);
- glVertex2i(hexVertex.x, hexVertex.y);
- }
- glEnd();
- glEndList();
- }
- void displayHex(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0, 0.0, 0.0);
- glBegin(GL_LINES);
- glVertex2i(150, 150);
- glVertex2i(250, 150);
- glEnd();
- glBegin(GL_LINES);
- glVertex2i(150, -150);
- glVertex2i(280, -150);
- glEnd();
- glRasterPos2i(152, 152);
- glColor3f(0.0f, 0.0f, 1.0f);
- glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)"(raza = 100)");
- glRasterPos2i(152, -148);
- glColor3f(0.0, 0.0, 0.0);
- glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)"(raza = 130)");
- glCallList(regHex);
- glCallList(regHex+1);
- glPopMatrix();
- glFlush();
- }
- void winReshapeFcn(GLint newWidth, GLint newHeight)
- {
- glViewport(0, 0, (GLsizei)newWidth, (GLsizei)newHeight);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(-320.0, 320.0, -320.0, 320.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClear(GL_COLOR_BUFFER_BIT);
- }
- void main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowPosition(300, 300);
- glutInitWindowSize(winWidth, winHeight);
- glutCreateWindow("Hexagon - utilizarea listelor de display");
- init();
- glutDisplayFunc(displayHex);
- glutReshapeFunc(winReshapeFcn);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment