Created
November 11, 2019 12:42
-
-
Save dwichan0905/25df57dd567426ce4d5d140a5befe0af to your computer and use it in GitHub Desktop.
Membuat Segitiga Berwarna dengan C++ OpenGL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdarg.h> | |
#include <GL\glut.h> | |
#include <stdlib.h> | |
#include "stdlib.h" | |
#include "GL/glut.h" | |
void triangle(void) { | |
//Disini tempat untuk menggambar | |
glBegin(GL_TRIANGLES); //menggambar segitiga | |
glColor3f(1, 0, 0); glVertex3f(-250, -100, 0); //titik kiri | |
glColor3f(0, 1, 0); glVertex3f(0, 150, 0); //titik atas | |
glColor3f(0, 0, 1); glVertex3f(250, -100, 0); //titik kanan | |
glEnd(); | |
glFlush(); //untuk memastikan bahwa perintah gambar di eksekusi | |
} | |
void display(void) { | |
glClear(GL_COLOR_BUFFER_BIT); //membersihkan semua pixel | |
triangle();//memanggil fungsi triangle() | |
glutSwapBuffers(); | |
} | |
int main(int argc, char ** argv){ | |
//untuk inisialisasi GLUT dengan parameter baris perintah | |
glutInit(&argc, argv); | |
//seting display mode | |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | |
//seting posisi window | |
glutInitWindowPosition(300, 100); | |
//seting ukuran window | |
glutInitWindowSize(640, 480); | |
//membuat window dengan caption di atasnya | |
glutCreateWindow("SEGITIGA TRIANGEL"); | |
//seting warna background | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
//inisialisasi nilai pengamatan | |
gluOrtho2D(-500., 500., -240.0, 240.0); | |
glutIdleFunc(display); | |
//memanggil fungsi display | |
glutDisplayFunc(display); | |
//Memasukan GLUT event loop | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment