Membuat Bintang dengan Open Gl

Posted on Updated on


Sekarang, saya akan membuat bintang-bintang berwarna-warni yang bertebaran di garis diagonal window.

Bintang-bintang ini dibuat dengan menggunakan transformasi objek yaitu translate, rotate  baiklah langsung saja ke Tkp :

dari gambar di atas source code sbb :

//silahkan di coba semoga bermanfaat

#include "stdlib.h"
#include "gl/glut.h"

void drawQuad(){

 glBegin(GL_POLYGON);
  glVertex2f(77.,70.);
  glVertex2f (80.,146.);
  glVertex2f(99.,90.);
  glVertex2f(157.,90.);
  glVertex2f (110.,55.);
  glVertex2f (128.,1.);
  glVertex2f (80.,34.);
  glVertex2f (32.,1.);
  glVertex2f (54.,55.);
  glVertex2f (3.,90.);
  glVertex2f (63.,90.);
  glVertex2f (80.,146.);
 glEnd();
 glFlush();
}
void renderScene(void){

 glClear(GL_COLOR_BUFFER_BIT);
 glPushMatrix();
 glRotatef(30,0,0,1);
 glColor3f(1,1,1);//putih
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-500,-500,0);
 glColor3f(1,0,0);//merah
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-450,-350,0);
 glRotatef(30,0,0,1);
 glScalef(0.5,0.5,0);
 glColor3f(1,1,0);//kuning
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-320,-420,0);
 glRotatef(30,0,0,1);
 glColor3f(0,0,1);//biru
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-200,-350,0);
 glScalef(0.5,0.5,0);
 glColor3f(1,0,0);//merah
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-200,-310,0);
 glRotatef(45,0,0,1);
 glScalef(1.5,1.5,0);
 glColor3f(0,1,0);//hijau
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-150,-100,0);
 glColor3f(1,0,0);//merah
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-150,0,0);
 glScalef(0.3,0.3,0);
 glColor3f(1,1,0);//kuning
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-50,-180,0);
 glScalef(0.4,0.4,0);
 glColor3f(1,1,0);//kuning
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(100,90,0);
 glRotatef(45,0,0,1);
 glScalef(1.2,1.2,0);
 glColor3f(1,1,0);//kuning
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-400,-200,0);
 glScalef(0.4,0.4,0);
 glColor3f(1,0,0);//kuning
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(50,0,0);
 glScalef(0.4,0.4,0);
 glColor3f(1,0,0);//merah
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(0,200,0);
 glScalef(0.4,0.4,0);
 glRotatef(30,0,0,1);
 glColor3f(0,1,1);//cyan
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(150,300,0);
 glRotatef(-45,0,0,1);
 glColor3f(0,0,1);//biru
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(100,300,0);
 glScalef(0.5,0.5,0);
 glColor3f(1,1,1);//putih
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(320,320,0);
 glRotatef(45,0,0,1);
 glColor3f(0,1,1);//cyan
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(320,280,0);
 glScalef(0.5,0.5,0);
 glColor3f(1,0,0);//merah
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(150,115,0);
 glScalef(0.3,0.3,0);
 glColor3f(1,0,1);//pink
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(450,400,0);
 glRotatef(45,0,0,1);
 glScalef(0.6,0.6,0);
 glColor3f(0,1,0);//hijau
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-100,115,0);
 glScalef(0.5,0.5,0);
 glColor3f(0,1,0);//hijau
 drawQuad();
 glPopMatrix();

 glPushMatrix();
 glTranslatef(180,400,0);
 glScalef(0.3,0.3,0);
 glColor3f(1,1,0);//kuning
 drawQuad();
 glPopMatrix();

 glFlush();
}
void main(int argc,char **argv){
 glutInit(&argc,argv);
 glutInitWindowPosition(200,200);
 glutInitWindowSize(480,480);
 glutCreateWindow("BINTANG BINTANG");
 gluOrtho2D(-500.,500.,-500.,500.);
 glutDisplayFunc(renderScene);
 glutMainLoop();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s