Menggambar Geometri Primitif OpenGL di C++

#include <GL/glut.h>

//=======================================================
void tampilan(){
glClear(GL_COLOR_BUFFER_BIT); // Menghapus layar

// membuat titik
glBegin(GL_POINTS);
glVertex2f(-200,-200); // membuat titik pada koordinat (0,0)
glEnd();

// membuat garis
glBegin(GL_LINES);
glColor3f(0,1,0); // memberi warna
glVertex2f(0,0);
glVertex2f(200,200);
glVertex2f(220,-10);
glVertex2f(220,-50);
glEnd();

// membuat
glBegin(GL_LINE_STRIP);
glColor3f(1,0,0);
glVertex2f(0,0);
glVertex2f(-100,0);
glVertex2f(-100,200);
glVertex2f(0,10);
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(0,0,1);
glVertex2f(0,-100);
glVertex2f(0,-200);
glVertex2f(-100,-200);
glVertex2f(-100,-100);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex2f(100,0);
glColor3f(1,1,0);
glVertex2f(200,0);
glColor3f(1,0,0);
glVertex2f(180,-100);
glColor3f(0,1,0);
glVertex2f(120,-100);
glEnd();

glBegin(GL_TRIANGLES);
glVertex2f(-150,-50);
glVertex2f(-200,-80);
glVertex2f(-100,-80);
glEnd();

glBegin(GL_TRIANGLE_FAN);
glVertex2f(-240,0);
glVertex2f(-200,0);
glVertex2f(-220,50);
glEnd();

glBegin(GL_TRIANGLE_STRIP);
glColor3f(1,1,0);
glVertex2f(150,-200);
glColor3f(1,0,0);
glVertex2f(100,-200);
glColor3f(1,0,1);
glVertex2f(125,-125);
glEnd();

glBegin(GL_QUADS);
glVertex2f(0,-240);
glVertex2f(-50,-240);
glVertex2f(-50,-200);
glVertex2f(0,-200);
glEnd();

glFlush();
}
//=======================================================
int main(int argc, char** argv){
glutInit(&argc,argv);
glutInitWindowPosition(400,200);
glutInitWindowSize(500,500);
glutCreateWindow(“Dasar-dasar OpenGL dan glut “);
glutDisplayFunc(tampilan);
//glClearColor(1,1,1,0);
gluOrtho2D(-250,250,-250,250);
glutMainLoop();
return 0;
}
//=======================================================

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s