Professional Documents
Culture Documents
Pertemuan Ke-2-Grafika Komputer - Pengenalan OpenGL & GLUT
Pertemuan Ke-2-Grafika Komputer - Pengenalan OpenGL & GLUT
UNIBBA
K A
I F
R A
G
ER
T U
M P
KO
PERTEMUAN KE-2
(3 SKS – 16 X PERTEMUAN) Yaya Suharya, S.Kom., M.T.
Rabu, 15 Maret 2023 Pengenalan OpenGL & GLUT yaya.unibba@gmail.com
14:00-15:40 (Kelas 4A) yayasuharya@unibba.ac.id
19:00-21:30 (Kelas 4B) NIDN. 0407047706
HP/WA. 08112031124
NOW
Pengenalan OpenGL & GLUT
GLUT - The OpenGL Utility Toolkit
https://www.opengl.org/resources/libraries/glut/
https://
www2.cs.arizona.edu/classes/cs433/spring02/op
engl/index.html
OpenGL Tutorial - 1 | Getting Started | OpenGL in C++ with the GLUT library
https://
www.youtube.com/watch?v=3aJ8OR1C6pk&list=PLWzp0Bbyy_3jy34HlDrEWl
cG3rF99gkvk
Materi
1
0
Organisasi
Perangkat Lunak
Arsitektur OpenGL
Fungsi-fungsi
OpenGL
• Primitives
• Points
• Line Segments
• Polygons
• Attributes
• Transformations
• Viewing
• Modeling
• Control (GLUT)
• Input (GLUT)
• Query
Format Fungsi
OpenGL
function name
dimensions
glVertex3f(x,y,z)
glVertex3fv(p)
p is a pointer to an array
OpenGL #defines
• Most constants are defined in the include files
gl.h, glu.h and glut.h
• Note #include <GL/glut.h> should automatically
include the others
• Examples
• glBegin(GL_POLYGON)
• glClear(GL_COLOR_BUFFER_BIT)
type of object
location of vertex
glBegin(GL_POLYGON)
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glEnd( );
GL_POINTS GL_POLYGON
GL_LINES GL_LINE_STRIP
GL_LINE_LOOP
GL_TRIANGLES
GL_QUAD_STRIP
GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
simple.c
#include <GL/glut.h>
void mydisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
int main(int argc, char** argv){
glutCreateWindow("simple");
glutDisplayFunc(mydisplay);
glutMainLoop();
}
Event Loop
• Note that the program defines a display
callback function named mydisplay
• Every glut program must have a display callback
• The display callback is executed whenever OpenGL
decides the display must be refreshed, for example
when the window is opened
• The main function ends with the program entering an
event loop
Defaults
• simple.c is too simple
• Makes heavy use of state variable default
values for
• Viewing
• Colors
• Window parameters
• callbacks
• Display function
• Input and window functions
simple.c revisited
• In this version, we shall see the same output
but we have defined all the relevant state
values through function calls using the default
values
• In particular, we set
• Colors
• Viewing conditions
• Window properties
main.c
display callback
init();
set OpenGL state
glutMainLoop();
} enter event loop
GLUT functions
• glutInit allows application to get command line arguments and
initializes system
• gluInitDisplayMode requests properties for the window (the
rendering context)
• RGB color
• Single buffering
• Properties logically ORed together
• glutWindowSize in pixels
• glutWindowPosition from top-left corner of display
• glutCreateWindow create window with title “simple”
• glutDisplayFunc display callback
• glutMainLoop enter infinite event loop
init.c
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
viewing volume
RGB color
• Each color component is stored separately in
the frame buffer
• Usually 8 bits per component in buffer
• Note in glColor3f the color values range from
0.0 (none) to 1.0 (all), whereas in glColor3ub
the values range from 0 to 255
Indexed Color
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glVertex3f(-2.0,-2.0,0.0);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.0,2.0,0.0);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(2.0,-2.0,0.0);
glEnd();
glFlush();
}
void myinit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-2.0,2.0,-2.0,2.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,0.0,0.0);
}
return 0;
}
Referensi
• Edward Angel, “Interactive Computer Graphics
Fourth Edition”, Pearson, 2006, ch 2, p 46 – 84
• F. S. Hill, Jr., “Computer Graphics Using
OpenGL Second Edition”, Prentice Hall, 2001,
ch 2, p 39 - 63
Referensi
Pemrograman
OpenGL pada VS
• Resources
• Visual Studio
• GLUT for Win32 version 3.7.6 as of Nov 8th 2001 (glut-3.7.6-bin.zip)
• Preparation
• Unzip file glut-3.7.6-bin.zip
• Copy (asumsi Visual Studio 2010)
• glut.h: ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\GL\’
• glut32.dll: ‘C:\Windows\System32\’
Kirim ke : yaya.unibba@gmail.com,