Just another WordPress.com site

Archive for the ‘C++’ Category

Membuat Animasi OpenGL dengan VisualC++

Wah keren ni animasi 3D dari VisualC++, ternyata kita bisa membuat animasi yang tidak kalah dengan flash maupun software animasi lainnya. kita juga bisa membuat screensaver dengan karya kita sendiri.

Pertama kita install dahulu Microsoft VisualC++, jika belum ada silahkan download dahulu softwarenya, setelah itu download juga Glut-3.7.6-bin disini,jika kedua file tersebut sudah terdownload jalankan VisualC++ dan copykan file glut32.dll pada windows system ato system32, glut.h pada VC98 paste pada folder INCLUDE, dan glut32.lib pada folder Lib.

Nah sekarang baru kita bisa membuat animasi 3D,baiklah coba perhatikan script dibawah ini :

int DrawGLScene(GLvoid)                                    // Here’s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
glLoadIdentity();                                    // Reset The View
glTranslatef(0.0f,0.0f,z);

// Pulsing Colors Based On Text Position
glColor3f(0.5f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
// Position The Text On The Screen
glRasterPos2f(-3.0f+0.05f*float(cos(cnt1)), -2.5f*float(sin(cnt2)));
glPrint(“Laskar Sampah – %1.2f”, cnt1);    // Print GL Text To The Screen
glColor3f(1.0f*float(cos(cnt1)),0.5f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
glRasterPos2f(-5.0f+0.05f*float(cos(cnt1)), 1.0f*float(sin(cnt2)));
glPrint(“Indra Budi Wijaya – %7.2f”, cnt1);    // Print GL Text To The Screen
glColor3f(0.1f*float(cos(cnt1)),0.7f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
glRasterPos2f(0.5f+0.05f*float(cos(cnt1)), 2.0f*float(sin(cnt2)));
glPrint(“Wirangga – %7.2f”, cnt1);
cnt1+=0.051f;                                        // Increase The First Counter
cnt2+=0.005f;                                        // Increase The First Counter

glRotatef(xrot,0.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);

glBindTexture(GL_TEXTURE_2D, texture[filter]);

glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,2.0f,0.0f);
glVertex3f(2.8f,2.0f,0.0f);
glVertex3f(2.8f,1.5f,0.0f);
glVertex3f(1.0f,1.5f,0.0f);

glVertex3f(1.0f,2.0f,0.0f);
glVertex3f(1.3f,2.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(0.7f,1.0f,0.0f);

glVertex3f(0.6f,0.7f,0.0f);
glVertex3f(2.8f,0.7f,0.0f);
glVertex3f(2.4f,1.0f,0.0f);
glVertex3f(0.7f,1.0f,0.0f);

glVertex3f(2.8f,-0.2f,0.0f);
glVertex3f(2.4f,-0.5f,0.0f);
glVertex3f(2.4f,1.0f,0.0f);
glVertex3f(2.8f,0.7f,0.0f);

glVertex3f(0.3f,-0.5f,0.0f);
glVertex3f(2.4f,-0.5f,0.0f);
glVertex3f(2.4f,-0.1f,0.0f);
glVertex3f(0.4f,-0.1f,0.0f);

glColor3f(0.5f,1.0f,0.0f);
glVertex3f(1.0f,2.0f,0.5f);
glVertex3f(2.8f,2.0f,0.5f);
glVertex3f(2.8f,1.5f,0.5f);
glVertex3f(1.0f,1.5f,0.5f);

glVertex3f(1.0f,2.0f,0.5f);
glVertex3f(1.3f,2.0f,0.5f);
glVertex3f(1.0f,1.0f,0.5f);
glVertex3f(0.7f,1.0f,0.5f);

glVertex3f(0.6f,0.7f,0.5f);
glVertex3f(2.8f,0.7f,0.5f);
glVertex3f(2.4f,1.0f,0.5f);
glVertex3f(0.7f,1.0f,0.5f);

glVertex3f(2.8f,-0.2f,0.5f);
glVertex3f(2.4f,-0.5f,0.5f);
glVertex3f(2.4f,1.0f,0.5f);
glVertex3f(2.8f,0.7f,0.5f);

glVertex3f(0.3f,-0.5f,0.5f);
glVertex3f(2.4f,-0.5f,0.5f);
glVertex3f(2.4f,-0.1f,0.5f);
glVertex3f(0.4f,-0.1f,0.5f);
glColor3f(1.0f,0.1f,0.0f);
glVertex3f(1.0f,2.0f,0.0f);
glVertex3f(2.8f,2.0f,0.0f);
glVertex3f(2.8f,2.0f,0.5f);
glVertex3f(1.0f,2.0f,0.5f);

glVertex3f(0.6f,0.7f,0.0f);
glVertex3f(1.0f,2.0f,0.0f);
glVertex3f(1.0f,2.0f,0.5f);
glVertex3f(0.6f,0.7f,0.5f);

glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(1.2f,1.6f,0.0f);
glVertex3f(1.2f,1.6f,0.5f);
glVertex3f(1.0f,1.0f,0.5f);

glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(2.4f,1.0f,0.0f);
glVertex3f(2.4f,1.0f,0.5f);
glVertex3f(1.0f,1.0f,0.5f);

glVertex3f(1.0f,1.5f,0.0f);
glVertex3f(2.8f,1.5f,0.0f);
glVertex3f(2.8f,1.5f,0.5f);
glVertex3f(1.0f,1.5f,0.5f);

glVertex3f(0.6f,0.7f,0.0f);
glVertex3f(2.4f,0.7f,0.0f);
glVertex3f(2.4f,0.7f,0.5f);
glVertex3f(0.6f,0.7f,0.5f);

glVertex3f(0.3f,-0.5f,0.0f);
glVertex3f(2.4f,-0.5f,0.0f);
glVertex3f(2.4f,-0.5f,0.5f);
glVertex3f(0.3f,-0.5f,0.5f);

glVertex3f(0.4f,-0.1f,0.0f);
glVertex3f(2.4f,-0.1f,0.0f);
glVertex3f(2.4f,-0.1f,0.5f);
glVertex3f(0.4f,-0.1f,0.5f);

glVertex3f(2.4f,0.7f,0.0f);
glVertex3f(2.4f,-0.1f,0.0f);
glVertex3f(2.4f,-0.1f,0.5f);
glVertex3f(2.4f,0.7f,0.5f);

glVertex3f(2.8f,0.7f,0.0f);
glVertex3f(2.8f,-0.2f,0.0f);
glVertex3f(2.8f,-0.2f,0.5f);
glVertex3f(2.8f,0.7f,0.5f);

glVertex3f(2.4f,-0.5f,0.0f);
glVertex3f(2.8f,-0.2f,0.0f);
glVertex3f(2.8f,-0.2f,0.5f);
glVertex3f(2.4f,-0.5f,0.5f);

glVertex3f(2.4f,1.0f,0.0f);
glVertex3f(2.8f,0.7f,0.0f);
glVertex3f(2.8f,0.7f,0.5f);
glVertex3f(2.4f,1.0f,0.5f);
glEnd();

xrot-=xspeed;
yrot+=yspeed;
return TRUE;

}

Download sourcecode disini..!!!

Cara Membuat Segitiga Dengan Bahasa C

Untuk yang baru belajar bahasa pemprograman, bahasa C sangat cocok untuk mengasah logika kita. Salah satunya membuat segi tiga,perhatikan script dibawah ini.

#include “stdio.h”

#include “conio.h”

main()        {

int    x, y;

for(x=1;x<=5;x++)     {

for(y=1;y<=x;y++)     {

printf(“*”);         }

printf(“\n”);      }

getch();

}

Selamat mencoba..!!!!

%d blogger menyukai ini: