Kamis, 12 Oktober 2017

Membuat Primitive Drawing

Reshape 1

Sintak:

#include <GL/glut.h>

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glEnable (GL_LINE_STIPPLE);
glLineStipple(1, 0x10ff);

glBegin(GL_LINE_STRIP);
glVertex2f(325, 75);
glVertex2f(5, 75);
glEnd();
glDisable (GL_LINE_STIPPLE);
glFlush();
}

void reshape1(int w, int h)
{
glViewport(0, 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(400, 150);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape1);
glutMainLoop();
return 0;
}

Output:













Reshape 2

Sintak:

#include <GL/glut.h>
#include <stdlib.h>
#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
glVertex2f ((x1),(y1)); \
glVertex2f ((x2),(y2)); \
glEnd();

void init(void)
{

glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);

}

void display(void)
{
int i;
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 1.0, 0.0);
glEnable (GL_LINE_STIPPLE);
glLineStipple (1, 0x0101); /* dotted */
drawOneLine (50.0, 125.0, 150.0, 125.0);
glLineStipple (1, 0x00FF); /* dashed */
drawOneLine (150.0, 125.0, 250.0, 125.0);
glLineStipple (1, 0x1C47); /* dash/dot/dash */
drawOneLine (250.0, 125.0, 350.0, 125.0);
glLineWidth (50.0);
glLineStipple (1, 0x0101); /* dotted */
drawOneLine (50.0, 100.0, 150.0, 100.0);
glLineStipple (1, 0x00FF); /* dashed */
drawOneLine (150.0, 100.0, 250.0, 100.0);
glLineStipple (1, 0x1C47); /* dash/dot/dash */
drawOneLine (250.0, 100.0, 350.0, 100.0);
glLineWidth (1.0);
glLineStipple (1, 0x1C47); /* dash/dot/dash */
glBegin (GL_LINE_STRIP);

for (i = 0; i < 7; i++)
glVertex2f (50.0 + ((GLfloat) i * 50.0), 75.0);
glEnd ();

for (i = 0; i < 6; i++)
{
drawOneLine (50.0 + ((GLfloat) i * 50.0), 50.0,
50.0 + ((GLfloat)(i+1) * 50.0), 50.0);
}

glLineStipple (5, 0x1C47); /* dash/dot/dash */
drawOneLine (50.0, 25.0, 350.0, 25.0);
glDisable (GL_LINE_STIPPLE);
glFlush ();
}

void reshape (int w, int h)
{
glViewport (0, 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 (400, 150);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);

init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;
}

Output:













Reshape 3

Sintak:
#include <GL/glut.h>

void display(void)

{
GLubyte fly[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60,
0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20,
0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC,
0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0,
0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0,
0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30,
0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08,
0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08,
0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08
};

glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.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 (argv[0]);

init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;
}

Output:














Reshape 4

Sintak:

#include <GL/glut.h>

int board[3][3]; /* jumlah warna untuk tiap kotak */
/* Clear nilai warna untuk setiap kotak pada board */

void init(void)
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j ++)
board[i][j] = 0;
glClearColor (0.0, 0.0, 0.0, 0.0);
}

void drawSquares(GLenum mode)
{
GLuint i, j;
for (i = 0; i < 3; i++)
{
if (mode == GL_SELECT)
glLoadName (i);
for (j = 0; j < 3; j ++)
{
if (mode == GL_SELECT)
glPushName (j);
glColor3f ((GLfloat) i/3.0, (GLfloat) j/3.0, (GLfloat)
board[i][j]/3.0);
glRecti (i, j, i+1, j+1);
if (mode == GL_SELECT)
glPopName ();
}
}
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
drawSquares (GL_RENDER);
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, 3.0, 0.0, 3.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (400, 400);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);

init ();
glutReshapeFunc (reshape);
glutDisplayFunc(display);
glutMainLoop();

return 0;
}

Output:























Reshape 5

Sintak:

#include <string.h>
#include <GL/glut.h>

void *font = GLUT_BITMAP_TIMES_ROMAN_24;
void *fonts[] ={GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10,
GLUT_BITMAP_TIMES_ROMAN_24};
char defaultMessage[] = "Pustaka GLUT opengGL";
char *message = defaultMessage;

void selectFont(int newfont)
{
font = fonts[newfont];
glutPostRedisplay();
}

void selectMessage(int msg)
{
switch (msg)
{
case 1:
message = "glut openGL...kecil.";
break;

case 2:
message = "GLUT OPENGL...BESAR.";
break;
}
}

void selectColor(int color)
{
switch (color)
{
case 1:
glColor3f(0.0, 1.0, 0.0);
break;

case 2:
glColor3f(1.0, 0.0, 0.0);
break;

case 3:
glColor3f(1.0, 1.0, 1.0);
break;
}

glutPostRedisplay();

}

void tick(void)
{
glutPostRedisplay();
}

void output(int x, int y, char *string)
{
int len, i;
glRasterPos2f(x, y);
len = (int) strlen(string);

for (i = 0; i < len; i++)
{
glutBitmapCharacter(font, string[i]);
}
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
output(0, 24, "HELLO SAYA BELAJAR GLUT bitmap font.");
output(100, 100, message);
output(0, 145, "(Posisidalam PIXEL dengan dimulai atas kiri,...xixixixi)");
glutSwapBuffers();
}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char **argv)
{
int i, msg_submenu, color_submenu;
glutInit(&argc, argv);

for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-mono"))
{
font = GLUT_BITMAP_9_BY_15;
}
}

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 150);
glutCreateWindow("GLUT bitmap font example");
glClearColor(0.0, 0.0, 0.0, 1.0);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(tick);
msg_submenu = glutCreateMenu(selectMessage);
glutAddMenuEntry("huruf kecil", 1);
glutAddMenuEntry("HURUF BESAR", 2);
color_submenu = glutCreateMenu(selectColor);
glutAddMenuEntry("HIJAU", 1);
glutAddMenuEntry("MERAH", 2);
glutAddMenuEntry("PUTIH", 3);
glutCreateMenu(selectFont);
glutAddMenuEntry("Default", 0);
glutAddMenuEntry("Times Roman 10", 1);
glutAddMenuEntry("Times Roman 24", 2);
glutAddSubMenu("Messages", msg_submenu);
glutAddSubMenu("Warna", color_submenu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();

return 0;
}

Output:










Reshape 6

Sintak:

#include <GL/glut.h>

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 1.0);
glEnable (GL_LINE_STIPPLE);
// glLineStipple (1, 0x0101); /* membuat titik */
glLineStipple (1, 0x00ff); /* membuat strip-strip */
//glLineStipple (1, 0x10ff); /* membuat strip titik strip */
glBegin(GL_LINE_STRIP);
glVertex2f (127, 80);
glVertex2f (500, 100);
glEnd();
glDisable (GL_LINE_STIPPLE);
glFlush ();
}

void reshape (int w, int h)
{
glViewport (0, 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 (600, 150);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;
}

Output:










Reshape 7

Sintak:

#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 (5.0, 0.1, 0.2);
   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 ("Reshape7");
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutMainLoop();
   return 0;
}

Output:
















Penjelasan:

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

Rabu, 04 Oktober 2017

Membuat Bangun Datar dengan FreeGlut

Membuat Segitiga

Sintak:

#include <GL/glut.h>

void garis();
main(int argc, char** argv)
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(600,800);
  glutInitWindowPosition(100,100);
  glutCreateWindow("Triangle");
  glClearColor(0.0,0.0,0.0,0.0);
  glMatrixMode(GL_PROJECTION);
  glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
  glutDisplayFunc(garis);
  glutMainLoop();
}

void garis()
{
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_LINES);
  glColor3f(0.0,0.0,1.0);
  glVertex2f(0.25,0.5);
  glVertex2f(0.75,0.5);
  glColor3f(5.0,0.0,0.0);
  glVertex2f(0.75,0.5);
  glVertex2f(0.5,0.8);
  glColor3f(0.0,2.0,0.0);
  glVertex2f(0.25,0.5);
  glVertex2f(0.5,0.8);
  glPointSize(50.0f) ;
  glEnd();
  glFlush();

}

Output:






















Membuat Kubus

Sintak:

#include<GL/glut.h>
void titik();
void titik1();
main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,800);
glutInitWindowPosition(100,100);
glutCreateWindow("Cube");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glutDisplayFunc(titik);
glutMainLoop();

}

void titik()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);

glColor3f(5.0,5.0,5.0);
glVertex2f(0.25,0.5);
glVertex2f(0.57,0.5);

glColor3f(2.0,0.0,0.0);
glVertex2f(0.57,0.5); 
glVertex2f(0.57,0.8); 

glColor3f(0.0,0.0,2.0);
glVertex2f(0.25,0.5); 
glVertex2f(0.25,0.8);

glColor3f(2.0,0.0,2.0);
glVertex2f(0.57,0.8); 
glVertex2f(0.25,0.8);

glColor3f(2.0,0.0,2.0);
glVertex2f(0.25,0.5); 
glVertex2f(0.45,0.6);

glColor3f(2.0,0.0,0.0);
glVertex2f(0.25,0.8); 
glVertex2f(0.45,0.85);

glColor3f(0.0,0.0,2.0);
glVertex2f(0.45,0.6); 
glVertex2f(0.45,0.85);

glColor3f(0.0,0.0,2.0);
glVertex2f(0.45,0.6); 
glVertex2f(0.7,0.6);

glColor3f(5.0,5.0,5.0);
glVertex2f(0.57,0.5);
glVertex2f(0.7,0.6);

glColor3f(2.0,2.0,2.0);
glVertex2f(0.7,0.85);
glVertex2f(0.57,0.80);

glColor3f(0.0,0.2,2.0);
glVertex2f(0.7,0.85);
glVertex2f(0.7,0.6);

glColor3f(0.0,0.2,2.0);
glVertex2f(0.7,0.85);
glVertex2f(0.45,0.85);

glPointSize(50.0f) ;
glEnd();
glFlush();
}

Output:





















Membuat Garis Pelangi

Sintak:
#include <GL/glut.h>

void garis();
main(int argc, char** argv) 
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,800);
glutInitWindowPosition(100,100);
glutCreateWindow("Rainbow Lines");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glutDisplayFunc(garis);
glutMainLoop();
}

void garis()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(1.0,0.0,0.0);
glVertex2f(0.65,0.5);
glVertex2f(0.3,0.5);

glColor3f(1.0,1.0,0.0);
glVertex2f(0.65,0.51); 
    glVertex2f(0.3,0.51);
    
    glColor3f(0.0,1.0,0.0);
glVertex2f(0.65,0.52); 
    glVertex2f(0.3,0.52);
    
    glColor3f(0.0,0.0,1.0);
glVertex2f(0.65,0.53); 
    glVertex2f(0.3,0.53);
    
    glColor3f(1.0,0.5,0.0);
glVertex2f(0.65,0.54); 
    glVertex2f(0.3,0.54);
    
    glColor3f(1.0,0.0,1.0);
glVertex2f(0.65,0.55); 
    glVertex2f(0.3,0.55);
    
    glColor3f(1.0,1.0,0.0);
glVertex2f(0.65,0.56); 
    glVertex2f(0.3,0.56);
    
glPointSize(50.0f) ;
glEnd();
glFlush();

}

Output:























Membuat Persegi dalam Persegi

Sintak:
#include <GL/glut.h>

void garis();
main(int argc, char** argv) 
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,800);
glutInitWindowPosition(100,100);
glutCreateWindow("Ironi didalam Ironi");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glutDisplayFunc(garis);
glutMainLoop();
}

void garis()
{
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0);
glVertex2f(-0.5,-0.5);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();

glBegin(GL_POLYGON);
glColor3f(5.0,0.0,0.0);
glVertex2f(-0.3,-0.3);
glVertex2f(-0.3,0.3);
glVertex2f(0.3,0.3);
glVertex2f(0.3,-0.3);
glEnd();
glFlush();
}

Output:























Penjelasan

- glClear() merupakan sintaks yang digunakan untuk membersihkan semua pixel
- glBegin() merupakan sintaks untuk memulai membuat gambar
- glVertex() merupakan sintaks untuk memberikan titik pada gambar
- glEnd() merupakan sintaks penutup
- glFlush() merupakan sintaks untuk memastikan gambar bisa dieksekusi
- glutCreateWindow() merupakan sintaks untuk membuat dan menampilkan window
- glutDisplayFunc(mydisplay) merupakan sintaks untuk memanggil method mydisplay
- glutMainLoop() merupakan sintaks untuk me-looping atau mengulang fungsi/method main

Cara Membuat Titik, Garis, dan Strip dengan FreeGlut

Membuat Titik

Sintaknya:

#include<GL/glut.h>

void titik ();
main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600,800);
glutInitWindowPosition(100,100);
glutCreateWindow("Percobaan 1");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(1.0,1.0,1.0,1.0,-1.0,1.0);
glutDisplayFunc(titik);
glutMainLoop();
}

void titik()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(5.5);
glBegin(GL_POINTS);
glColor3f(1.0,1.0,1.0);
glBegin(GL_POINTS);
glColor3f(1.0,1.0,1.0);
glVertex2f(0.25,0.25);
glColor3f(0.1,1.0,1.0);
glVertex2f(0.5,0.5);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(0.55,0.55);
glColor3f(0.5, 1.0, 0.5);
glVertex2f(0.45,0.45);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(0.55,0.55);
glColor3f(1.0, 1.5, 8.0);
glVertex2f(0.65,0.65);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(0.75,0.75);
glColor3f(0.75, 0.75, 0.75);
glVertex2f(0.85,0.85);
glEnd();
glFlush();
}

output:


















Membuat Garis

Sintaknya:

#include<GL/glut.h>

void garis();
main(int argc, char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
glutCreateWindow("Percobaan II");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glutDisplayFunc(garis);
glutMainLoop();
}

void garis()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(1.0,1.0,1.0);
glVertex2f(0.25,0.25);
glColor3f(0.1,1.0,1.0);
glVertex2f(0.5,0.5);
glVertex2f(0.75,0.5);
glVertex2f(0.5,0.8);
glPointSize(50.0f);
glEnd();
glFlush();
}

Outputnya:



















Membuat Strip

Sintaknya:

#include<GL/glut.h>

void strip();
main(int argc, char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
glutCreateWindow("Percobaan III");
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glutDisplayFunc(strip);
glutMainLoop();
}

void strip()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_STRIP);
glColor3f(1.0,0.0,0.0);
glVertex2f(0.25,0.25);
glColor3f(0.1,1.0,0.0);
glVertex2f(0.5,0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.75,0.5);
glVertex2f(0.7,0.8);
glPointSize(50.0f);
glEnd();
glFlush();
}

Output:



















Penjelasan
- glClear() merupakan sintaks yang digunakan untuk membersihkan semua pixel
- glBegin() merupakan sintaks untuk memulai membuat gambar
- glVertex() merupakan sintaks untuk memberikan titik pada gambar
- glEnd() merupakan sintaks penutup
- glFlush() merupakan sintaks untuk memastikan gambar bisa dieksekusi
- glutCreateWindow() merupakan sintaks untuk membuat dan menampilkan window
- glutDisplayFunc(mydisplay) merupakan sintaks untuk memanggil method mydisplay
- glutMainLoop() merupakan sintaks untuk me-looping atau mengulang fungsi/method main

Rabu, 13 September 2017

Cara Instal dan Setting OpenGL di Dev.C++

Program yang diperlukan:
     1. Dev.C++ versi terbaru (5.11)
     2.  Freeglut-MinGW-3.0.0-1


Cara Instal:

     1.      Ekstrak terlebih dahulu, kemudian kalian buka file freeglut dan kalian
           akan menemukan folder beserta sub-sub foldernya.
           
           



     2.     Kemudian copykan filenya ke:
                 -  Isi folder bin ke C:\Windows\System32
                 -  Isi folder include ke C:\Program Files 
                   (x86)\DevCpp\MinGW64\x86_64-w64-mingw32\include\GL
                 -  Isi folder lib ke C:\Program Files 
                   (x86)\Dev- Cpp\MinGW64\x86_64w64-mingw32\lib
    


      3.  Setelah kalian sudah mengcopy semua file di atas, sekarang 
           buka Dev.C kemudian klik File > New > Project
         

    
  4.  Pilih Console Application > OK, beri nama sesuai dengan
       gambar dan kalian simpan di documents agar memudahkan kalian
       menemukannya.
           


 5.   Setelah itu, klik kanan di Project anda dan pilih Project Option
     

 6.   Kemudian pilih Parameters > Linker > dan ketikkan -lopengl32, - 
       lfreeglut, -lglu32 lalu OK







Dan seperti itulah cara menginstalnya.

Mohon maaf jika masih banyak kekurangan dan kesalahan saya dalam memberi cara menginstal ini.


Sekian dan terima kasih.         





Stay Lit.