Membuat Bendera Merah Putih
Berikut ini adalah tampilan Bendera Merah Putih yang dibuat dengan OpenGL. Tampilan di bawah ini merupakan salah satu contoh Transformasi Objek pada OpenGL.
Berikut ini adalah source code programnya :
#include <stdlib.h>
#include <gl/glut.h>
void drawQuad(){
//[d]
glBegin(GL_QUADS);
//[a]
glVertex2f(100.,50.);
glVertex2f(100.,0.);
//[b]
glVertex2f(-100.,0.);
glVertex2f(-100.,50.);
//[c]
glEnd();
}
void drawQuad2(){
glBegin(GL_QUADS);
glVertex2f(30.,50.);
glVertex2f(30.,-50.);
glVertex2f(-30.,-50.);
glVertex2f(-30.,50.);
glEnd();
}
void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.,0.,0.);
//merah
drawQuad();
glTranslatef(0,-50,0.);
glColor3f(1.,1.,1.);
//putih
drawQuad();
glTranslatef(0.,-50.,0.);
glTranslatef(-90.,-50.,0.);
glColor3f(1.,0.,0.);
//merah bawah kiri
drawQuad();
glTranslatef(170.,0.,0.);
glColor3f(1.,0.,0.);
//merah bawah kanan
drawQuad();
glTranslatef(-80.,-50.,0.);
glColor3f(1.,1.,1.);
//putih bawah kanan
drawQuad();
glTranslatef(0.,0.,0.);
glColor3f(0.,0.,0.);
//hitam bawah
drawQuad2();
glTranslatef(150.,400,0.);
glColor3f(1.,0.,0.);
//merah atas kanan
drawQuad2();
glTranslatef(60.,0.,0.);
glColor3f(1.,1.,1.);
//putih atas kanan
drawQuad2();
glTranslatef(-450.,0.,0.);
glColor3f(1.,1.,1.);
//putih atas kiri
drawQuad2();
glTranslatef(55.,0.,0.);
glColor3f(1.,0.,0.);
//merah atas kiri
drawQuad2();
glFlush();
}
void main(int argc, char
**argv) {
glutInit(&argc,
argv);
glutInitDisplayMode(GLUT_DEPTH
| GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(480,480);
glutCreateWindow("Ain Sayidani | Rahmi Wahyulianti");
gluOrtho2D(-320.0,320.0,-320.0,320.0);
glutDisplayFunc(renderScene);
glutMainLoop();
}
0 komentar:
Posting Komentar