Primitive Drawing merupakan cara mudah untuk menggambar pada layar
monitor menggunakan teori geometri sederhana. Macam-macam primitive
drawing seperti menggambar sebuah titik, garis, atau gabungan antar
keduanya. Berikut contoh dari program Primitive Drawing
Berikut ini akan saya tunjukkan awal pembuatan pola gambar menggunakan Program primitive Drawing.
1. Membuka Microsoft Excel untuk membuat pola gambar.
2. Menentukan nilai pada setiap satu kotak , apabila kotak tidak ada nilai TRUE (Blok hitam) maka dinilai 0 . (HeksaDesimal)
lihat contoh pembacaan di bawah ini :
Maka akan didapat kode berikut :
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xfc, 0x00,
0x00, 0x7f, 0xfe, 0x00,
0x00, 0xc0, 0x03, 0x00,
0x01, 0xc0, 0x03, 0x80,
0x01, 0x00, 0x00, 0x80,
0x03, 0x03, 0xc0, 0xc0,
0x06, 0x08, 0x20, 0x60,
0x04, 0x08, 0x10, 0x20,
0x0c, 0x10, 0x01, 0x30,
0x08, 0x03, 0x00, 0x20,
0x18, 0x03, 0xc0, 0x18,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x0c, 0x30, 0x08,
0x10, 0x0c, 0x30, 0x08,
0x08, 0x0c, 0x30, 0x10,
0x14, 0x00, 0x00, 0x20,
0x02, 0x00, 0x00, 0x40,
0x02, 0x00, 0x00, 0x40,
0x0c, 0x00, 0x00, 0x70,
0x0f, 0x80, 0x01, 0xc0,
0x1e, 0x40, 0x02, 0x78,
0x1c, 0x3f, 0xfc, 0x3f,
0x3c, 0x3f, 0xfc, 0x3f,
0x3c, 0x1f, 0xf8, 0x3c,
0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xfc, 0x00,
0x00, 0x7f, 0xfe, 0x00,
0x00, 0xc0, 0x03, 0x00,
0x01, 0xc0, 0x03, 0x80,
0x01, 0x00, 0x00, 0x80,
0x03, 0x03, 0xc0, 0xc0,
0x06, 0x08, 0x20, 0x60,
0x04, 0x08, 0x10, 0x20,
0x0c, 0x10, 0x01, 0x30,
0x08, 0x03, 0x00, 0x20,
0x18, 0x03, 0xc0, 0x18,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x0c, 0x30, 0x08,
0x10, 0x0c, 0x30, 0x08,
0x08, 0x0c, 0x30, 0x10,
0x14, 0x00, 0x00, 0x20,
0x02, 0x00, 0x00, 0x40,
0x02, 0x00, 0x00, 0x40,
0x0c, 0x00, 0x00, 0x70,
0x0f, 0x80, 0x01, 0xc0,
0x1e, 0x40, 0x02, 0x78,
0x1c, 0x3f, 0xfc, 0x3f,
0x3c, 0x3f, 0xfc, 0x3f,
0x3c, 0x1f, 0xf8, 0x3c,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20,
Run :
KODE :
Source Kode :
#include <GL/glut.h>
void display(void)
{
GLubyte fly[] = {
void display(void)
{
GLubyte fly[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xfc, 0x00,
0x00, 0x7f, 0xfe, 0x00,
0x00, 0xc0, 0x03, 0x00,
0x01, 0xc0, 0x03, 0x80,
0x01, 0x00, 0x00, 0x80,
0x03, 0x03, 0xc0, 0xc0,
0x06, 0x08, 0x20, 0x60,
0x04, 0x08, 0x10, 0x20,
0x0c, 0x10, 0x01, 0x30,
0x08, 0x03, 0x00, 0x20,
0x18, 0x03, 0xc0, 0x18,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x03, 0xc0, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x0c, 0x30, 0x08,
0x10, 0x0c, 0x30, 0x08,
0x08, 0x0c, 0x30, 0x10,
0x14, 0x00, 0x00, 0x20,
0x02, 0x00, 0x00, 0x40,
0x02, 0x00, 0x00, 0x40,
0x0c, 0x00, 0x00, 0x70,
0x0f, 0x80, 0x01, 0xc0,
0x1e, 0x40, 0x02, 0x78,
0x1c, 0x3f, 0xfc, 0x3f,
0x3c, 0x3f, 0xfc, 0x3f,
0x3c, 0x1f, 0xf8, 0x3c,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20,
};
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 0.0);
glRectf (25.0, 125.0, 125.0, 350.0);
glEnable (GL_POLYGON_STIPPLE);
glPolygonStipple (fly);
glRectf (200.0, 125.0, 800.0, 350.0);
glDisable (GL_POLYGON_STIPPLE);
glFlush ();
}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void reshape (int w, int h)
{
glViewport (50, 0,(GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (1000, 500);
glutCreateWindow ("Tugas");
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
Atau contoh lainnya :
Contoh 1 |
#include <GL/glut.h>
void display(void)
{
GLubyte fly[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00,
0x00, 0xC0, 0x03, 0x00, 0x06, 0x18, 0x18, 0x60,
0x06, 0x18, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00,
0x18, 0x0C, 0x30, 0x18, 0x18, 0x0C, 0x30, 0x18,
0x00, 0x00, 0x00, 0x00, 0x18, 0x06, 0x60, 0x18,
0x18, 0x06, 0x60, 0x18, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x01, 0x80, 0x60, 0x0C, 0x01, 0x80, 0x60,
0x00, 0xC0, 0x03, 0x00, 0x00, 0xCE, 0x73, 0x00,
0x00, 0x0E, 0x70, 0x00, 0x00, 0x0F, 0xF0, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x01, 0x83, 0xC1, 0x80,
0x01, 0x8F, 0xF1, 0x80, 0x0A, 0x0E, 0x70, 0x30,
0x0A, 0x0E, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x0C, 0x30, 0x18, 0x18, 0x0C,
0x00, 0x18, 0x18, 0x00, 0x0A, 0x00, 0x00, 0x30,
0x0A, 0xC0, 0x03, 0x30, 0x00, 0xC0, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.7, 0.7);
glRectf (25.0, 125.0, 125.0, 350.0);
glEnable (GL_POLYGON_STIPPLE);
glPolygonStipple (fly);
glRectf (200.0, 125.0, 800.0, 350.0);
glDisable (GL_POLYGON_STIPPLE);
glFlush ();
}
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 1.0);
glShadeModel (GL_FLAT);
}
void reshape (int w, int h)
{
glViewport (50, 0,(GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (1000, 500);
glutCreateWindow ("Afifatul_11520241022");
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
void display(void)
{
GLubyte fly[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00,
0x00, 0xC0, 0x03, 0x00, 0x06, 0x18, 0x18, 0x60,
0x06, 0x18, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00,
0x18, 0x0C, 0x30, 0x18, 0x18, 0x0C, 0x30, 0x18,
0x00, 0x00, 0x00, 0x00, 0x18, 0x06, 0x60, 0x18,
0x18, 0x06, 0x60, 0x18, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x01, 0x80, 0x60, 0x0C, 0x01, 0x80, 0x60,
0x00, 0xC0, 0x03, 0x00, 0x00, 0xCE, 0x73, 0x00,
0x00, 0x0E, 0x70, 0x00, 0x00, 0x0F, 0xF0, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x01, 0x83, 0xC1, 0x80,
0x01, 0x8F, 0xF1, 0x80, 0x0A, 0x0E, 0x70, 0x30,
0x0A, 0x0E, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00,
0x30, 0x00, 0x00, 0x0C, 0x30, 0x18, 0x18, 0x0C,
0x00, 0x18, 0x18, 0x00, 0x0A, 0x00, 0x00, 0x30,
0x0A, 0xC0, 0x03, 0x30, 0x00, 0xC0, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.7, 0.7);
glRectf (25.0, 125.0, 125.0, 350.0);
glEnable (GL_POLYGON_STIPPLE);
glPolygonStipple (fly);
glRectf (200.0, 125.0, 800.0, 350.0);
glDisable (GL_POLYGON_STIPPLE);
glFlush ();
}
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 1.0);
glShadeModel (GL_FLAT);
}
void reshape (int w, int h)
{
glViewport (50, 0,(GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (1000, 500);
glutCreateWindow ("Afifatul_11520241022");
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
Tidak ada komentar:
Posting Komentar