Membuat huruf menggunakan GLUT Dev C
Label: ke-Ilkom-anSabtu, 22 September 2012
buat agan agan yang sedang menggeluti glut untuk tugas dan lainnya, saya ada contoh kodingannya. sok di pelajari. sebenarnya tinggal disesuaikan dengan posisi vertexnya. smoga bermanfaat
#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>
void init(void)
{
glClearColor(0.5, 0.5, 0.5, 0.5);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15.0, 15.0, -15.0, 15.0, -15.0, 15.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf S1
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-6.0,5.0);
glColor3f(0.0,0.0,1.0);glVertex2f(-6.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf S2
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-8.0,3.0);
glColor3f(0.0,0.0,1.0);glVertex2f(-8.0,5.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf S3
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-6.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-6.0,3.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf S4
glColor3f(1.0,0.1,0.0);glVertex2f(-7.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-7.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-6.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-6.0,2.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf S5
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-9.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-6.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(-6.0,0.0);
glEnd();
//MEMBUAT U
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf u1
glColor3f(1.0,0.1,0.0);glVertex2f(-5.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-5.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-4.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(-4.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf u2
glColor3f(1.0,0.1,0.0);glVertex2f(-4.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-4.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-2.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(-2.0,0.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf u3
glColor3f(1.0,0.1,0.0);glVertex2f(-2.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-2.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-1.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(-1.0,6.0);
glEnd();
//c
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//c1
glColor3f(1.0,0.1,0.0);glVertex2f(0.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(0.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(3.0,5.0);
glColor3f(0.0,0.0,1.0);glVertex2f(3.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf c2
glColor3f(1.0,0.1,0.0);glVertex2f(0.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(0.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(1.0,0.0);
glColor3f(0.0,0.0,1.0);glVertex2f(1.0,5.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf c3
glColor3f(1.0,0.1,0.0);glVertex2f(0.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(0.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(3.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(3.0,0.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf i
glColor3f(1.0,0.1,0.0);glVertex2f(4.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(4.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(5.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(5.0,6.0);
glEnd();
//membuat r
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf r1
glColor3f(1.0,0.1,0.0);glVertex2f(7.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(7.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(8.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(8.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf r2
glColor3f(1.0,0.1,0.0);glVertex2f(8.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(8.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(11.0,5.0);
glColor3f(0.0,0.0,1.0);glVertex2f(11.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf r3
glColor3f(1.0,0.1,0.0);glVertex2f(10.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(10.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(11.0,3.0);
glColor3f(0.0,0.1,0.0);glVertex2f(11.0,5.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf r4
glColor3f(1.0,0.1,0.0);glVertex2f(8.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(8.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(11.0,2.0);
glColor3f(0.0,0.0,1.0);glVertex2f(11.0,3.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf r5
glColor3f(1.0,0.1,0.0);glVertex2f(9.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(10.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(11.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(10.0,2.0);
glEnd();
//huruf E
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf e1
glColor3f(1.0,0.1,0.0);glVertex2f(12.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(12.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(16.0,5.0);
glColor3f(0.0,0.0,1.0);glVertex2f(16.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf e2
glColor3f(1.0,0.1,0.0);glVertex2f(12.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(12.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(13.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(13.0,5.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf e3
glColor3f(1.0,0.1,0.0);glVertex2f(13.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(13.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(16.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(16.0,0.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf e4
glColor3f(1.0,0.1,0.0);glVertex2f(13.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(13.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(16.0,2.0);
glColor3f(0.0,0.0,1.0);glVertex2f(16.0,3.0);
glEnd();
//buat z
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf z1
glColor3f(1.0,0.1,0.0);glVertex2f(17.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(17.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(20.0,5.0);
glColor3f(0.0,0.0,1.0);glVertex2f(20.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf z2
glColor3f(1.0,0.1,0.0);glVertex2f(19.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(17.0,1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(18.0,1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(20.0,5.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf z3
glColor3f(1.0,0.1,0.0);glVertex2f(17.0,1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(17.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(18.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(18.0,1.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf z4
glColor3f(1.0,0.1,0.0);glVertex2f(18.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(18.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(20.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(20.0,0.0);
glEnd();
//membuat k
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf k1
glColor3f(1.0,0.1,0.0);glVertex2f(21.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(21.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(22.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(22.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf k2
glColor3f(1.0,0.1,0.0);glVertex2f(22.0,4.0);
glColor3f(1.0,0.1,0.0);glVertex2f(22.0,2.5);
glColor3f(1.0,0.1,0.0);glVertex2f(26.0,4.5);
glColor3f(0.0,0.0,1.0);glVertex2f(26.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf k3
glColor3f(1.0,0.1,0.0);glVertex2f(22.0,2.5);
glColor3f(1.0,0.1,0.0);glVertex2f(22.0,1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(26.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(26.0,0.5);
glEnd();
//huruf y
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf y1
glColor3f(1.0,0.1,0.0);glVertex2f(27.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(27.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(28.0,2.0);
glColor3f(0.0,0.0,1.0);glVertex2f(28.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf y2
glColor3f(1.0,0.1,0.0);glVertex2f(28.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(28.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(30.0,2.0);
glColor3f(0.0,0.0,1.0);glVertex2f(30.0,3.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf y3
glColor3f(1.0,0.1,0.0);glVertex2f(30.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(30.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(31.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(31.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf y4
glColor3f(1.0,0.1,0.0);glVertex2f(27.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(27.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(30.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(30.0,0.0);
glEnd();
//membuat huruf F
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf F1
glColor3f(1.0,0.1,0.0);glVertex2f(33.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(33.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(34.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(34.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf F2
glColor3f(1.0,0.1,0.0);glVertex2f(34.0,6.0);
glColor3f(1.0,0.1,0.0);glVertex2f(34.0,5.0);
glColor3f(1.0,0.1,0.0);glVertex2f(37.0,5.0);
glColor3f(0.0,0.0,1.0);glVertex2f(37.0,6.0);
glEnd();
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);//membuat huruf F3
glColor3f(1.0,0.1,0.0);glVertex2f(34.0,3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(34.0,2.0);
glColor3f(1.0,0.1,0.0);glVertex2f(37.0,2.0);
glColor3f(0.0,0.0,1.0);glVertex2f(37.0,3.0);
glEnd();
//buat titik
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);
glColor3f(1.0,0.1,0.0);glVertex2f(38.0,0.0);
glColor3f(1.0,0.1,0.0);glVertex2f(38.0,-1.0);
glColor3f(1.0,0.1,0.0);glVertex2f(39.0,-1.0);
glColor3f(0.0,0.0,1.0);glVertex2f(39.0,0.0);
glEnd();
//membuat garis bawah
glTranslatef(0,0.0,0.0);
glBegin(GL_QUADS);
glColor3f(1.0,0.1,0.0);glVertex2f(-10.0,-3.0);
glColor3f(1.0,0.1,0.0);glVertex2f(-10.0,-4.0);
glColor3f(1.0,0.1,0.0);glVertex2f(40.0,-4.0);
glColor3f(0.0,0.0,1.0);glVertex2f(40.0,-3.0);
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
//huruf-huruf di keyboard yang mengendalikan grafik
switch (key)
{
case 'w':
case 'W':
glRotatef(3.0, 1.0, 0.0, 0.0); /* rotasi kedepan */
break;
case 'x':
case 'X':
glRotatef(-3.0, 1.0, 0.0, 0.0); /* rotasi kebelakang */
break;
case 'a':
case 'A':
glRotatef(3.0, 0.0, 1.0, 0.0); /* rotasi kekanan */
break;
case 'd':
case 'D':
glRotatef(-3.0, 0.0, 1.0, 0.0); /* rotasi kekiri */
break;
case 'q':
case 'Q':
glRotatef(3.0, 0.0, 0.0, 1.0); /* rotasi berputar ke arah kiri */
break;
case 'e':
case 'E':
glRotatef(-3.0, 0.0, 0.0, 1.0); /* rotasi berputar ke arah kanak */
break;
case '-':
case '_':
glScaled(0.2, 0.2, 0.0); /* skala -*/
case '=':
case '+':
glScaled(2.0, 2.0, 0.0); /* skala +*/
break;
case '1':
case '!':
glTranslatef( -1.0f, 0.0f, 0.0f ); //translasi ke kiri
break;
case '2':
case '@':
glTranslatef( 1.0f, 0.0f, 0.0f ); //translasi ke kanan
break;
case '3':
case '#':
glTranslatef( 0.0f, 1.0f, 0.0f ); //translasi ke atas
break;
case '4':
case '$':
glTranslatef( 0.0f, -1.0f, 0.0f ); //translasi ke bawah
}
display(); /* repaint the window */
}
void catchMainMenu(int cmd)
{
if (cmd==1)
{
exit(0);
}
}
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 800);
glutInitWindowPosition(50, 50);
glutCreateWindow("Nama Suci Rezky F");
init();
glutCreateMenu(catchMainMenu);
glutAddMenuEntry("Out", 1);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
//selamat bereksperimen :D
Langganan:
Posting Komentar
(
Atom
)

0 komentar :
Posting Komentar