Pages

Pengikut

30 Dis 2011

RUMAH GUNA OPEN GL

Malam ni kepala penin2 x taw nak wat cam ne.. ni sume gara-gara rumah idaman kalbu aku x siap lagi.. adoi la.
Ape-ape pun aku stil gak nak sharing gal pasal umah ni.. ni coding nye.. guna Visual C++. Mak... tolong.. da fenin.. Open GL ni aku belajar mase kelas asas grafik.. besh gak..tapi penin lagi.. da nak abeh kelas baru la paham cikit.. 2 baru cikit je.. yang banyak x taw la cam ne final ni..
contoh aturcara nya:
// testing rumah izzuera
#include <GL/glut.h>
void rumah( void)
{
    //rumah saya

glBegin(GL_QUADS);//rumput
glColor3f(0,1,0);glVertex3f(640,280,0);
glColor3f(0,1,0);glVertex3f(0,280,0);
glColor3f(0,1,0);glVertex3f(0,150,0);
glColor3f(0,1,0);glVertex3f(640,150,0);
glEnd();

glBegin(GL_QUADS);//rumah segiempat
glColor3f(1,0.1,0.1);glVertex3f(450,340,0);
glColor3f(1.0,0.1,0.1);glVertex3f(200,340,0);
glColor3f(1.0,0.1,0.1);glVertex3f(200,200,0);
glColor3f(1.0,0.1,0.1);glVertex3f(450,200,0);
glEnd();

glBegin(GL_QUADS); //pintu
glColor3f(1,1,1);glVertex3f(350,200,0);
glColor3f(1,1,1);glVertex3f(300,200,0);
glColor3f(0.7,0.0,0.0);glVertex3f(300,270,0);
glColor3f(0.7,0.0,0);glVertex3f(350,270,0);
glEnd();

glBegin(GL_QUADS); //tingkap
glColor3f(0.7,0.6,0.2);glVertex3f(230,240,0);
glColor3f(0.7,0,0);glVertex3f(230,300,0);
glColor3f(0.7,0,0);glVertex3f(270,300,0);
glColor3f(1,1,1);glVertex3f(270,240,0);
glEnd();


glBegin(GL_QUADS); //tingkap
glColor3f(0.7,0.6,0.2);glVertex3f(380,240,0);
glColor3f(0.7,0,0);glVertex3f(380,300,0);
glColor3f(0.7,0,0);glVertex3f(420,300,0);
glColor3f(1,1,1);glVertex3f(420,240,0);
glEnd();


glBegin(GL_QUADS);//tapak rumah segiempat
glColor3f(0.5,0.3,0);glVertex3f(460,190,0);
glColor3f(0.5,0.2,0);glVertex3f(190,190,0);
glColor3f(1,1,1);glVertex3f(190,200,0);
glColor3f(1,1,1);glVertex3f(460,200,0);
glEnd();


glBegin(GL_QUADS);//tapak bumbung rumah segiempat
glColor3f(0.5,0.3,0.0);glVertex3f(190,350,0);
glColor3f(0.5,0.2,0.0);glVertex3f(460,350,0);
glColor3f(0.5,0.2,0.0);glVertex3f(460,340,0);
glColor3f(1,0,0);glVertex3f(190,340,0);
glEnd();  

glBegin(GL_QUADS);// bumbung
glColor3f(0,0,0);glVertex3f(190,350,0);
glColor3f(0,0,0);glVertex3f(460,350,0);
glColor3f(0,0,0);glVertex3f(400,400,0);
glColor3f(0,0,0);glVertex3f(250,400,0);
glEnd();  


glBegin(GL_QUADS);//jalan raya
glColor3f(0,0,0);glVertex3f(640,150,0);
glColor3f(0,0,0);glVertex3f(640,40,0);
glColor3f(0,0,0);glVertex3f(0,40,0);
glColor3f(0,0,0);glVertex3f(0,150,0);
glEnd();

glBegin(GL_QUADS);//rumput tepi jalan raya
glColor3f(0,1,0);glVertex3f(640,0,0);
glColor3f(0,1,0);glVertex3f(640,40,0);
glColor3f(0,1,0);glVertex3f(0,40,0);
glColor3f(0,1,0);glVertex3f(0,0,0);
glEnd();

glBegin(GL_LINES);//garisan
glColor3f(1,1,1);
glVertex2f(0.0f,100.0f);
glVertex2f(80.0f,100.0f);
glVertex2f(160.0f,100.0f);
glVertex2f(240.0f,100.0f);
glVertex2f(320.0f,100.0f);
glVertex2f(400.0f,100.0f);
glVertex2f(480.0f,100.0f);
glVertex2f(560.0f,100.0f);
glEnd();

glFlush();

}

void display( void) {

glClear(GL_COLOR_BUFFER_BIT);

rumah();//memanggil fungsi rumah()

glutSwapBuffers();

}

int main( int argc, char ** argv){

glutInit(&argc, argv);

glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB);

glutInitWindowPosition( 300,100);

glutInitWindowSize(640,480);

glutCreateWindow ("RUMAH SAYA");
glClearColor( 0.0, 0.8, 0.8, 0.8);

gluOrtho2D(0.0, 600.0,0.0,480.0);

glutIdleFunc(display);

glutDisplayFunc(display);

glutMainLoop();

return 0;

}

ni lak hasil nye..huhu.. cun x?? cam ni la..budak baru nelajar bab open GL..


1 ulasan:

  1. apa yg awk melalut ni?? huhuhu..dgn sy2 pun jd pening..

    ~sierra

    BalasPadam

Related Posts Plugin for WordPress, Blogger...