Académique Documents
Professionnel Documents
Culture Documents
SOURCE CODE:
//Memanggil Library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <GL/glut.h>
//Membuat Method
void mydisplaytugas(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUAD_STRIP);
glColor3f(1, 0, 0);
glVertex2f(0.0f, 0.0f);
glVertex2f(-0.25f, 0.5f);
glVertex2f(-0.5f, 0.75f);
glVertex2f(0.0f, 0.25f);
glColor3f(0, 1, 0);
glVertex2f(0.0f, 0.0f);
glVertex2f(-0.25f, -0.75f);
glVertex2f(-0.75f, 0.0f);
glVertex2f(0.0f, -0.25f);
glColor3f(0, 0, 1);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.5f, 0.75f);
glVertex2f(0.25f, 0.25f);
glVertex2f(0.5f, -0.75f); // vertex 4
glEnd();
glFlush();
}
//Program Utama
int main(int argc, char** argv){
glutCreateWindow("simple");
glutDisplayFunc(mydisplaytugas);
glutMainLoop();
}
RPL SMK Muhammadiyah 2 Kuningan
SOURCE CODE:
//Memanggil Library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <GL/glut.h>
//Membuat Method
void mydisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(0, 1, 0);
glVertex2f(-0.5, -0.5);
glColor3f(0, 0, 1);
glVertex2f(-0.75, 0);
glColor3f(1, 0, 0);
glVertex2f(-0.5, 0.5);
glColor3f(0, 1, 0);
glVertex2f(0, 0.75);
glColor3f(0, 0, 1);
glVertex2f(0.5, 0.5);
glColor3f(1, 0, 0);
glVertex2f(0.75, 0);
glColor3f(0, 1, 0);
glVertex2f(0.5, -0.5);
glColor3f(0, 0, 1);
glVertex2f(0,-0.75);
glEnd();
glFlush();
}
//Program Utama
int main(int argc, char** argv){
glutCreateWindow("simple");
glutDisplayFunc(mydisplay);
glutMainLoop();
}
RPL SMK Muhammadiyah 2 Kuningan
3. Membuat object Polygon persegi Delapan berputar (Lihat Gambar)
//Memanggil Library
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <GL/glut.h>
//Deklarasi Variable
float z_pos = 0.0f;
float rot = 0.0f;
//Membuat Method
void mydisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0f, z_pos);
glRotatef(rot, 0, 0, 1);
glBegin(GL_POLYGON);
glColor3f(0, 1, 0);
glVertex3f(-0.5, -0.5, -5);
glColor3f(0, 0, 1);
glVertex3f(-0.75, 0, -5);
glColor3f(1, 0, 0);
glVertex3f(-0.5, 0.5, -5);
glColor3f(0, 1, 0);
glVertex3f(0, 0.75, -5);
glColor3f(0, 0, 1);
glVertex3f(0.5, 0.5, -5);
glColor3f(1, 0, 0);
glVertex3f(0.75, 0, -5);
glColor3f(0, 1, 0);
glVertex3f(0.5, -0.5, -5);
glColor3f(0, 0, 1);
glVertex3f(0, -0.75, -5);
glEnd();
glFlush();
glutSwapBuffers();
}
RPL SMK Muhammadiyah 2 Kuningan
//Program Utama
int main(int argc, char** argv)
{
glutInit(&argc, argv);
//glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("simple");
// callbacks
glutDisplayFunc(mydisplay);
glutKeyboardFunc(myKeyboard);
glutTimerFunc(100, myTimeOut, 0);
glutReshapeFunc(resize);
init();
glutMainLoop();
}