Untitled
unknown
plain_text
2 months ago
1.0 kB
2
Indexable
#include <GL/glut.h> #include <iostream> using namespace std; void myinit(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0); } void drawPolygon() { glColor3f(1.0, 0.0, 0.0); // Set color to red glBegin(GL_POLYGON); // Define vertices of the polygon (pentagon example) GLfloat polygonVertices[5][2] = { {250, 350}, {200, 275}, {225, 200}, {275, 200}, {300, 275} }; for (int i = 0; i < 5; i++) { glVertex2f(polygonVertices[i][0], polygonVertices[i][1]); } glEnd(); glFlush(); } void display() { glClear(GL_COLOR_BUFFER_BIT); drawPolygon(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(640, 480); glutInitWindowPosition(10, 10); glutCreateWindow("Simple Polygon"); myinit(); glutDisplayFunc(display); glutMainLoop(); return 0; }
Editor is loading...
Leave a Comment