- Titik (vertex)
- Garis (line)
- Bangun 2D (face)
Beberapa fungsi yang bisa digunakan untuk membuat objek-objek primitif tersebut adalah :
- GL_POINTS
- GL_LINES
- GL_LINE_STRIP
- GL_LINE_LOOP
- GL_TRIANGLES
- GL_TRIANGLE_STRIP
- GL_TRIANGLE_FAN
- GL_QUADS
- GL_QUAD_STRIP
- GL_POLYGON
Contoh script untuk membuat objek primitif
#include <stdlib.h>
#include <glut/glut.h>
void drawPoligon(int x, int y) {
glBegin(GL_POLYGON);
glVertex2i(x-100,y);
glVertex2i(x-100,y+100);
glVertex2i(x,y+100);
glVertex2i(x,y);
glVertex2i(x+100,y);
glVertex2i(x+100,y-100);
glVertex2i(x-20,y-100);
glVertex2i(x-150,y-150);
glEnd();
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
drawPoligon(0, 0);
glFlush();
}
void main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,240);
glutCreateWindow(" Pemrograman Grafis GLUT ");
gluOrtho2D(-320.,320.,-240.,240.);
glutDisplayFunc(renderScene);
glutMainLoop();
}
Hasil
5/2/13
tutorial
0 Response to Membuat Objek Primitif di GLUT (OpenGL Utility Toolkit)
Post a Comment