Dosen : Adang Suhendra
Dosen Pengganti : Agam Adityas
Kelas : 3IA13
Kelompok 4
Anggota Kelompok:
1. Andi Syuryadinata (55409629)
2. Chrisvano Sandi Yudha (50409093)
3. Hamdallah Perdana Putra (50409545)
4. Lutfi Prayudi (51409697)
5. R. Gilang Donny E (52409094)
6. Tia Rachmawati B P (51409442)
Koding openGL (dengan Dev-C++)
1. Membuat Garis
#include <GL/glut.h>
#include <stdlib.h>
#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
void buat(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0); /*putih*/
glBegin (GL_LINES);
drawOneLine (50.0, 75.0, 250.0, 75.0);
glEnd();
glFlush ();
}
void ayey (int w, int h)
{
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize (300, 150);
glutCreateWindow ("garis");
glutDisplayFunc(buat);
glutReshapeFunc(ayey);
glutMainLoop();
return 0;
}
Output Garis
2. Membuat Persegi
#include <GL/glut.h>
void buat(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0); /* merah */
glVertex2d(0.75,0.75);
glColor3f(0.0, 1.0, 0.0); /* hijau */
glVertex2d(0.75,-0.75);
glColor3f(0.0, 0.0, 1.0); /* biru */
glVertex2d(-0.75,-0.75);
glColor3f(1.0, 1.0, 1.0); /* putih */
glVertex2d(-0.75,0.75);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize (300, 300);
glutCreateWindow("persegi");
glutDisplayFunc(buat);
glutMainLoop();
return 0;
}
Output Persegi
========================================================================
3. Membuat Segitiga
#include <GL/glut.h>
#include <math.h>
void buat(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 1.0); /* biru */
glVertex2d(-0.75, -(1*sqrt(3))/2);
glColor3f(0.0, 1.0, 0.0); /* ijo */
glVertex2d(0.75, -(1*sqrt(3))/2);
glColor3f(1.0, 0.0, 0.0); /* merah */
glVertex2d(0, (1*sqrt(3))/2);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize (300, 300);
glutCreateWindow("segitiga");
glutDisplayFunc(buat);
glutMainLoop();
return 0;
}
Output Segitiga
========================================================================
4. Membuat Polygon
#include <GL/glut.h>
void buat(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(0.0,1.5,0.0); /* ijo */
glVertex2f(0.0,0.75);
glColor3f(1.0,0.0,0.0); /* merah */
glVertex2f(-0.5,-0.5);
glColor3f(0.0,0.0,1.0); /* biru */
glVertex2f(0.5,-0.5);
glColor3f(1.0,1.0,0.0); /* kuning */
glVertex2f(0.75,0.25);
glColor3f(0.0,1.0,1.0); /* biru langit*/
glVertex2f(-0.75,0.25);
glColor3f(1.0,0.0,1.0); /* ungu */
glVertex2f(-0.5,-0.5);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize (300, 300);
glutCreateWindow("polygon");
glutDisplayFunc(buat);
glutMainLoop();
return 0;
}
Output Polygon
========================================================================
Sekian dan Terima Kasih :)
link terkait :
http://lutfiprayudi03.wordpress.com/2011/11/20/membuat-bangun-ruang-dengan-opengl-dev-c/
*ralat, maksudnya judulnya bangun datar bukanbangun ruang
*ralat, maksudnya judulnya bangun datar bukan
Bro ijin berbagi program opengl ane
ReplyDeleteheriadyblog.blogspot.com
manggaaa.. thanks udah mampir.. :D
Deletebaangg...ijin caplok yee baangg
ReplyDeleteizin.... bang copy
ReplyDelete