#include <windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(4);
glLineWidth(4);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
//kiri
glVertex2f(0.0,1.7);
glVertex2f(-0.7,0.2);
glVertex2f(-1.9,0.2);
glVertex2f(-0.9,-0.7);
glVertex2f(-1.4,-1.9);
glVertex2f(0.0,-0.9);
//kanan
glVertex2f(0.0,-0.9);
glVertex2f(1.4,-1.9);
glVertex2f(0.9,-0.7);
glVertex2f(1.9,0.2);
glVertex2f(0.7,0.2);
glVertex2f(0.0,1.7);
glEnd();
glFlush();
}
void myinit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-2.0,2.0,-2.0,2.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,0.0,1.0);
}
int main(int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
//glutInitWindowPosition(100,100);
glutCreateWindow("Segitiga Warna");
glutDisplayFunc(display);
myinit();
glutMainLoop();
return 0;
}
Hasil runnya seperti di bawah ini gan, dan kalau mau di besarin atau presisi, silahkan ganti vertexnya
kalau ada pertanyaan silahkan taruh di komentar gan hehe
0 Komentar