Tutorial C++ : Cara Membuat Tulisan 3D Bergerak di Visual Studio | OpenGL C++
3D adalah sebuah objek yang mempunyai ruang atau mempunyai ukuran p x l x t. Dalam pemrograman openGL C++ membuat obyek 3D dapat menggunakan perintah GL_POLYGON, GL_POLYLINE_LOOP, GL_POLYLINE_STRIP, dan masih banyak lagi. Kali ini saya akan membuat sebuah tulisan 3D yang dapat bergerak dari kiri ke kanan. Saya akan menggunakan GL_POLYLINE_LOOP dan juga GL_POLYLINE_STRIP untuk membuat tulisan 3D. Berikut ini syntaks saya bagi menjadi tiga bagian dan juga hasil dari programnya :
#include <glut.h>
int berjalan = 0;
bool upup = true;
void Mahfudz(){
glBegin(GL_LINE_LOOP);//M
glVertex2f(-200,0);
glVertex2f(-200,50);//1
glVertex2f(-190,50);
glVertex2f(-170,25);
glVertex2f(-150,50);
glVertex2f(-140,50);
glVertex2f(-140,0);
glVertex2f(-150,0);
glVertex2f(-150,35);
glVertex2f(-170,15);
glVertex2f(-190,35);
glVertex2f(-190,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-200,50);glVertex2d(-190,60);
glVertex2d(-180,60);
glVertex2d(-162,35);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-150,50);
glVertex2d(-140,60);
glVertex2d(-130,60);
glVertex2d(-130,10);
glVertex2d(-140,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-190,0);
glVertex2d(-180,10);
glVertex2d(-180,25);
glEnd();//end M
glBegin(GL_LINE_LOOP);//A
glVertex2f(-125,0);
glVertex2f(-125,50);
glVertex2f(-85,50);
glVertex2f(-85,0);
glVertex2f(-95,0);
glVertex2f(-95,15);
glVertex2f(-115,15);
glVertex2f(-115,0);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2f(-115,25);
glVertex2f(-95,25);
glVertex2f(-95,40);
glVertex2f(-115,40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-125,50);
glVertex2d(-115,60);
glVertex2d(-75,60);
glVertex2d(-75,10);
glVertex2d(-85,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-115,0);
glVertex2d(-105,10);
glVertex2d(-105,15);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-95,35);
glVertex2d(-105,35);
glVertex2d(-105,40);
glEnd();//end A
glBegin(GL_LINE_LOOP);//H
glVertex2f(-70,0);
glVertex2f(-70,50);
glVertex2f(-60,50);
glVertex2f(-60,30);
glVertex2f(-25,30);
glVertex2f(-25,50);
glVertex2f(-15,50);
glVertex2f(-15,0);
glVertex2f(-25,0);
glVertex2f(-25,0);
glVertex2f(-25,20);
glVertex2f(-60,20);
glVertex2f(-60,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-60,0);
glVertex2d(-50,10);
glVertex2d(-50,20);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-60,50);
glVertex2d(-50,60);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-70,50);
glVertex2d(-60,60);
glVertex2d(-50,60);
glVertex2d(-50,40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-50,40);
glVertex2d(-25,40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-50,40);
glVertex2d(-60,30);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-25,50);
glVertex2d(-15,60);
glVertex2d(-5,60);
glVertex2d(-5,10);
glVertex2d(-15,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(-15,50);
glVertex2d(-5,60);
glEnd();//END H
glBegin(GL_LINE_LOOP);//F
glVertex2f(0,0);
glVertex2f(0,50);
glVertex2f(40,50);
glVertex2f(40,40);
glVertex2f(10,40);
glVertex2f(10,30);
glVertex2f(40,30);
glVertex2f(40,20);
glVertex2f(10,20);
glVertex2f(10,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(0,50);
glVertex2d(10,60);
glVertex2d(50,60);
glVertex2d(40,50);
glEnd();
Lanjutan :
glBegin(GL_LINE_STRIP);
glVertex2d(40,40);
glVertex2d(50,50);
glVertex2d(50,60);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(40,30);
glVertex2d(50,40);
glVertex2d(10,40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(40,20);
glVertex2d(50,30);
glVertex2d(50,40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(10,0);
glVertex2d(20,10);
glVertex2d(20,20);
glEnd();//End F
glBegin(GL_LINE_LOOP);//U
glVertex2f(55,0);
glVertex2f(55,50);
glVertex2f(65,50);
glVertex2f(65,10);
glVertex2f(85,10);
glVertex2f(85,50);
glVertex2f(95,50);
glVertex2f(95,0);
glVertex2f(55,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(85,50);
glVertex2d(95,60);
glVertex2d(105,60);
glVertex2d(95,50);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(105,60);
glVertex2d(105,20);
glVertex2d(95,0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(55,50);
glVertex2d(65,60);
glVertex2d(75,60);
glVertex2d(65,50);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(75,60);
glVertex2d(75,20);
glVertex2d(65,10);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(75,20);
glVertex2d(85,20);
glEnd();//End U
Lanjutan :
glBegin(GL_LINE_LOOP);//D
glVertex2f(110,0);
glVertex2f(110,50);
glVertex2f(130,50);
glVertex2f(145,25);
glVertex2f(130,0);
glVertex2f(110,0);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2f(120,10);
glVertex2f(125,10);
glVertex2f(135,25);
glVertex2f(125,40);
glVertex2f(120,40);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(110,50);
glVertex2d(120,60);
glVertex2d(140,60);
glVertex2d(130,50);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(140,60);
glVertex2d(155,35);
glVertex2d(145,25);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(155,35);
glVertex2d(130,0);
glEnd();//End D
glBegin(GL_LINE_LOOP);//Z
glVertex2f(160,50);
glVertex2f(160,40);
glVertex2f(180,40);
glVertex2f(160,0);
glVertex2f(195,0);
glVertex2f(195,10);
glVertex2f(175,10);
glVertex2f(195,50);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(160,50);
glVertex2d(170,60);
glVertex2d(205,60);
glVertex2d(195,50);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(205,60);
glVertex2d(175,10);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(195,10);
glVertex2d(205,20);
glVertex2d(180,20);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2d(205,20);
glVertex2d(205,10);
glVertex2d(195,0);
glEnd();//End Z
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(berjalan,0,0);
Mahfudz();
glLineWidth(3);
glColor3f(0.0,0.0,1.0);
glFlush();
glPopMatrix();
glutSwapBuffers();
}
void kecepatan(int t)
{
if (upup){
berjalan +=10;
else{
berjalan-=10;
}
if (berjalan>200){
upup=true;
}
else if(berjalan<-200)
{
upup=true;
}
glutPostRedisplay();
glutTimerFunc(205,kecepatan,0);
}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(200,20);
glutInitWindowSize(1020,720);
glutCreateWindow("Drawing by Mahfudz Syahru Romadhon SMKN 2 Karanganyar");
glClearColor(1.0,1.0,1.0,1.0);
gluOrtho2D(-320.,500.,-240.0,240.0);
glutDisplayFunc(display);
glutIdleFunc(display);
glutTimerFunc(1,kecepatan,0);
glutMainLoop();
return 0;
}
Dan berikut hasil dari syntaks di atas :
Hasil di atas akan bergerak dari arah kiri ke kanan.
Mungkin itu saja yang dapat saya sampaikan, selamat mencoba.
0 Comments
Post a Comment