the 4 points

Pemrograman Grafis Dengan OpenGL dan GLUT

TUtorial ini berisi bagaimana cara membuat program grafis dengan Open GL dan GLUT

Catatan include pada code di bawah bervariasi tergantung letak library header GL.h, GLU.h, glut.h yang diinstall. walaupun ditulis dengan C GLUT hanya sedikit mirip C atau C++.

#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>
#include <gl\glut.h>


//<<<<<<<<<<<<<<<<<<<<<<< my initialization >>>>>>>>>>>>>>>>>>>>>>>>>>>>

//inisialisasi world dan display OpenGL

void myInit()
{
glClearColor(1.0,1.0,1.0,0);// setbackground to bright white
glColor3f(0.0f,0.0f,0.0f);//set drawing color to black
glPointSize(4.0);// set point size to 4 x 4 pixels
glMatrixMode(GL_PROJECTION); // set matrix projection
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);//set 2D viewport
}

//baris baris kode berisi apa yang akan ditampilkan selama program berjalan atau main display loop. Disebut demikian karena fungsi ini akan dieksekusi berulang ulang selama program berjalan dengan suatu periode tertentu. Lebih lanjut periode tersebut dapat disetting dengan rentang waktu yang diinginkan.

void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT); //clear the screen
glBegin(GL_POINTS);//draw some point
glVertex2i(100,50);
glVertex2i(100,130);
glVertex2i(150,130);
glVertex2i(300,130);
glEnd();
glFlush();//send all output into display
}

inisialisasi program termasik inisialisasi GLUT inisialisasi Window dan main Display loop

//<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char **argv)
{
glutInit(&argc,argv); // initialize glut toolkit
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //set display mode
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("my first OGL app");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}

bila dieksekusi output resultnya :

the 4 points

contoh program sederhana,membuat 4 titik pada coordinate tertentu terhadap viewport dengan ukuran titik 4 x 4 pixel dan berwarna hitam,
prerequisite : akan lebih mudah bila anda memahami dulu dasar-dasar computer graphics
terdapat isu2 mengenai beberapa incompatibility pada GLUT 3.7

source :

http://stackoverflow.com/questions/14264/using-glut-with-visual-c-express-edition
http://www.xmission.com/~nate/glut.html
http://www.lighthouse3d.com/opengl/glut/
http://www.fshilljr.com
Computer Graphics 3rd Edition Using OpenGL, FS.Hill, JR., STEPHEN M. KELLEY, Pearson

One thought on “Pemrograman Grafis Dengan OpenGL dan GLUT”

Leave a comment