er

Berbagai Tutorial dan Info Menarik

Belajar, Berjuang, dan Bertaqwa

Saturday 13 December 2014

Gambar Kos 3D dengan Opengl



Source Code :

#include <stdlib.h> // standard definitions
#include <math.h> // math definitions
#include <stdio.h> // standard I/O
#include <iostream>

// include files are in a slightly different location for MacOS
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

..............................
Download source code lengkap Di Sini


Hasil :





Keterangan :
Untuk masalah gambar, gunakan gambar dengan format BMP. Letakkan gambar di folder yang sama dengan letak penyimpanan file codeblock tersebut.

Perhatikan juga hal ini :

Untuk melihat dari berbagai sudut kamar, ganti gluLookAt, berikut script-nya :
gluLookAt(1.0, 0.8,  3.3,    1.0, 0.8,  1.0,    0, 1, 0);

gluLookAt(0.7, 5.2,  1.2,    0.7, 0.0,  1.2,    0, 0, 1);

gluLookAt(0.0, 0.95,  3.0,    1.5, 0.95,  1.0,    0, 1, 0);

gluLookAt(0.0, 0.95,  2.8,    1.0, 0.95,  1.0,    0, 1, 0);

Pilih salah satu saja.
Sekian. 
Regards.

Friday 5 December 2014

Mantan Kepala Dinas Pariwisata Kabupaten Tegal Ditahan


Menurut Kepala Kejaksaan Negeri Slawi , Hj, Unaisi Hetty Nining,SH,MH mengatakan, mantan kepala Dinas Pariwisata dan kebudayaan Kabupaten Tegal, Dra. Indah Winarni ditahan dan dititipkan di Lapas kota Tegal. Sebelumnya, tersangka sudah menjalani serangkian pemeriksaan sehingga berkas tersangka dinyatakan P 21. “ Penahanan dilakukan setelah Satreskrim Polres Tegal melimpahkan berkas hasil penyidikan kasus dugaan korupsi proyek Road Race Cacaban yang sudah dinyatakan lengkap (P21). Tersangka dalam kapasitasnya sebagai pengguna anggaran,”
Baca Selengkapnya

Lumix Camera

Lumix Camera: Panasonic Lumix DMC-GF6. Comes with a 180-degree-tiltable LCD and enables unlimited artistic expression with a variety of creative filters, with new feature new self shot, perfect camera for you who like selfie. The Lumix DMC-GF6 compact mirror less digital camera delivers amazing image.



Find this cool stuff here: http://zocko.it/LHDh1

Coolpix S3500 Camera

Coolpix S3500 Camera: Nikon Coolpix S3500 Camera in orange.



Find this cool stuff here: http://zocko.it/LHDiF

Transparent Baby G Watch

Transparent Baby G Watch: Baby G BG 6900 7BDR by CASIO. Tough digital watches built Shock Proof, semi-transparent resin case and band with modern marine styles and it also stylish and cute, water resistant 200 m, EL backlight with afterglow.



Find this cool stuff here: http://zocko.it/LHDhq

Playstation 4 White

Playstation 4 White: Sony Ps 4 White 500gb. The PS4 is ready to rock your gaming world, immortalize your most epic moments and share at the press of a button, share it to witch, UStream, Facebook and Twitter. Are you ready for the new gaming experience ?



Find this cool stuff here: http://zocko.it/LHDfn

Oppo Joy Phone

Oppo Joy Phone: Oppo Joy R1001Phone 4gb. With the system of colorOS oppo joy has the new and smart function of gesture panel. And dont worry when you wearing a glove because this phone has a gloves mode, you can access your phone and touch it even when you wearing a gloves. Dual sim card.



Find this cool stuff here: http://zocko.it/LHDgN

Acer Iconia W511

Acer Iconia W511: Acer Iconia W511. More just than a tablet this smart device give you access to your data on any of your devices, over a new twist, gives benefits of a tablet with a touch, type, and view experience. This Acer Iconia is lightweight, the battery can keep up until 18 hours.



Find this cool stuff here: http://zocko.it/LHDfs

Black Strap Watch

Black Strap Watch: Men Leather Strap Watch by 24:01. Black watch with unique design, strap made of silicon and metal case, with a date and day feature, watch that can go formal or casual way, this watch will be your next favorite watch.





Find this cool stuff here: http://zocko.it/LHDe8

Wednesday 3 December 2014

3D Sederhana Dengan OpenGL

Gambar 3D sederhana

Source Code :


#include <stdlib.h> // standard definitions
#include <math.h> // math definitions
#include <stdio.h> // standard I/O
#include <iostream>

// include files are in a slightly different location for MacOS
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

GLuint texture[4];
GLint slices=16;
GLint stacks=16;
struct Image {
    unsigned long sizeX;
    unsigned long sizeY;
    char *data;
};
typedef struct Image Image;

static unsigned int getint(FILE *fp)
{
    int c, c1, c2, c3;

    // get 4 bytes
    c = getc(fp);
    c1 = getc(fp);
    c2 = getc(fp);
    c3 = getc(fp);

    return ((unsigned int) c) +
    (((unsigned int) c1) << 8) +
    (((unsigned int) c2) << 16) +
    (((unsigned int) c3) << 24);
}

static unsigned int getshort(FILE *fp)
{
    int c, c1;

    //get 2 bytes
    c = getc(fp);
    c1 = getc(fp);

    return ((unsigned int) c) + (((unsigned int) c1) << 8);
}

int ImageLoad(const char *filename, Image *image) {
    FILE *file;
    unsigned long size;                 // size of the image in bytes.
    unsigned long i;                    // standard counter.
    unsigned short int planes;          // number of planes in image (must be 1)
    unsigned short int bpp;             // number of bits per pixel (must be 24)
    char temp;                          // used to convert bgr to rgb color.

    // make sure the file is there.
    if ((file = fopen(filename, "rb"))==NULL) {
        printf("File Not Found : %s\n",filename);
        return 0;
    }

    // seek through the bmp header, up to the width/height:
    fseek(file, 18, SEEK_CUR);

    // No 100% errorchecking anymore!!!

    // read the width
    image->sizeX = getint (file);
    //printf("Width of %s: %lu\n", filename, image->sizeX);

    // read the height
    image->sizeY = getint (file);
    //printf("Height of %s: %lu\n", filename, image->sizeY);

    // calculate the size (assuming 24 bits or 3 bytes per pixel).
    size = image->sizeX * image->sizeY * 3;

    // read the planes
    planes = getshort(file);
    if (planes != 1) {
        printf("Planes from %s is not 1: %u\n", filename, planes);
        return 0;
    }

    // read the bpp
    bpp = getshort(file);
    if (bpp != 24) {
        printf("Bpp from %s is not 24: %u\n", filename, bpp);
        return 0;
    }

    // seek past the rest of the bitmap header.
    fseek(file, 24, SEEK_CUR);

    // read the data.
    image->data = (char *) malloc(size);
    if (image->data == NULL) {
        printf("Error allocating memory for color-corrected image data");
        return 0;
    }

    if ((i = fread(image->data, size, 1, file)) != 1) {
        printf("Error reading image data from %s.\n", filename);
        return 0;
    }

    for (i=0;i<size;i+=3) { // reverse all of the colors. (bgr -> rgb)
        temp = image->data[i];
        image->data[i] = image->data[i+2];
        image->data[i+2] = temp;
    }

    // we're done.
    return 1;
}
Image * loadTexture(const char *filename)
{
    Image *image1;
    // allocate space for texture
    image1 = (Image *) malloc(sizeof(Image));
    if (image1 == NULL) {
        printf("Error allocating space for image");
        exit(0);
    }
    if (!ImageLoad(filename, image1)) {
        exit(1);
    }
    return image1;
}

void setTexture(void)
{
    glClearColor(1., 0.0, 0.5, 0.0);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    Image *image1[4];

    image1[0] = loadTexture("worldmap.bmp");
    image1[1] = loadTexture("rivet_steel_1.bmp");
    image1[2] = loadTexture("test.bmp");
    image1[3] = loadTexture("black.bmp");

    glGenTextures(4, texture);
    for (int i=0; i<4; i++)
    {
        if(image1[0] == NULL)
        {
            printf("Image was not returned from loadTexture\n");
            exit(0);
        }
        glBindTexture(GL_TEXTURE_2D, texture[i]);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, 3, image1[i]->sizeX, image1[i]->sizeY, 0,
                     GL_RGB, GL_UNSIGNED_BYTE, image1[i]->data);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    }
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_FLAT);
}

void setMaterial()
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);

    glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
}

void setLighting()
{
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    // Create light components
    GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
    GLfloat diffuseLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    GLfloat specularLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    GLfloat position[] = { -2.5f, 2.0f, 3.0f, 1.0f };

    // Assign created components to GL_LIGHT0
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
}

void setCamera(){
    // setting proyeksi kamera
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, 3.0/3.0, 1, 40);

    // setting posisi kamera
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0);
}

void drawBox(float x1,float y1,float z1, float x2, float y2, float z2)
{
    glPushMatrix();
    glBegin(GL_QUADS);
    //depan
    glTexCoord2f(0.0, 0.0);glVertex3f(x1,y1,z1);
    glTexCoord2f(1.0, 0.0);glVertex3f(x2,y1,z1);
    glTexCoord2f(1.0, 1.0);glVertex3f(x2,y2,z1);
    glTexCoord2f(0.0, 1.0);glVertex3f(x1,y2,z1);
    //atas
    glTexCoord2f(0.0, 0.0);glVertex3f(x1,y2,z1);
    glTexCoord2f(0.0, 1.0);glVertex3f(x2,y2,z1);
    glTexCoord2f(1.0, 1.0);glVertex3f(x2,y2,z2);
    glTexCoord2f(1.0, 0.0);glVertex3f(x1,y2,z2);
    //belakang
    glTexCoord2f(0.0, 0.0);glVertex3f(x1,y2,z2);
    glTexCoord2f(0.0, 1.0);glVertex3f(x2,y2,z2);
    glTexCoord2f(1.0, 1.0);glVertex3f(x2,y1,z2);
    glTexCoord2f(1.0, 0.0);glVertex3f(x1,y1,z2);
    //bawah
    glTexCoord2f(0.0, 0.0);glVertex3f(x1,y1,z2);
    glTexCoord2f(1.0, 0.0);glVertex3f(x2,y1,z2);
    glTexCoord2f(1.0, 1.0);glVertex3f(x2,y1,z1);
    glTexCoord2f(0.0, 1.0);glVertex3f(x1,y1,z1);
    //samping kiri
    glTexCoord2f(0.0, 0.0);glVertex3f(x1,y1,z1);
    glTexCoord2f(1.0, 0.0);glVertex3f(x1,y2,z1);
    glTexCoord2f(1.0, 1.0);glVertex3f(x1,y2,z2);
    glTexCoord2f(0.0, 1.0);glVertex3f(x1,y1,z2);
    //samping kanan
    glTexCoord2f(0.0, 0.0);glVertex3f(x2,y1,z1);
    glTexCoord2f(1.0, 0.0);glVertex3f(x2,y2,z1);
    glTexCoord2f(1.0, 1.0);glVertex3f(x2,y2,z2);
    glTexCoord2f(0.0, 1.0);glVertex3f(x2,y1,z2);
    glEnd();
    glPopMatrix();
}

void kunci(unsigned char key, int x, int y) {
    switch (key)
    {
        case 27 :
        case 'q':
            exit(0);
        break;
    }
    glutPostRedisplay();
}

void drawPC()
{
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    drawBox(-0.5,0.0,0.5,0.5,0.7,0.45);

    glBindTexture(GL_TEXTURE_2D, texture[3]);
    drawBox(-0.55,-0.05,0.48,0.55,0.75,0.40);
    drawBox(-0.1,-0.1,0.48,0.1,-0.05,0.40);
    drawBox(-0.2,-0.15,0.6,0.2,-0.1,0.30);

       glBindTexture(GL_TEXTURE_2D, texture[2]);
    drawBox(-0.5,0.0,0.5,0.5,0.7,0.45);

    glBindTexture(GL_TEXTURE_2D, texture[3]);
    drawBox(0.55,-0.05,0.48,0.55,0.75,0.40);
    drawBox(0.1,-0.1,0.48,0.1,-0.05,0.40);
    drawBox(0.2,-0.15,0.6,0.2,-0.1,0.30);
}

void renderScene(void){
    glClearColor(1,1,1,0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glShadeModel(GL_SMOOTH);

    glPushMatrix();
    //glTranslatef(1.0,0.50,0.12);
    glScalef(0.5,0.5,0.5);
    drawPC();
    glPopMatrix();

    /*
    //CONTOH MENGGAMBAR SPHERE
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glutSolidSphere(0.5,50,50);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    */

    // Draw a red x-axis, a green y-axis, and a blue z-axis.
    glBegin(GL_LINES);
    glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(10, 0, 0);
    glColor3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(0, 10, 0);
    glColor3f(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 10);
    glEnd();

    glutSwapBuffers();
}

void init(){
    //setMaterial();
    setTexture();
    setLighting();
    setCamera();
}


int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(600,600);
    glutInitWindowPosition(100,100);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
    glutCreateWindow("Primitive Object");
    glutDisplayFunc(renderScene);
    glutKeyboardFunc(kunci);
    init();
    glutMainLoop();
    return 0;

}


Screenshot :