SlideShare a Scribd company logo
1 of 6
Download to read offline
Tutorial 07. Transparency
Salah satu efek yang dapat ditampilkan dari blending adalah transparency, yaitu bagaimana membuat
suatu permukaan tampak transparant. Hal ini dicapai dengan menggunakan warna blending putih (full-
brightness) dengan transparansi satu dengan fungsi:
glColor4f(1.0f, 1.0f, 1.0f, 0.5); // Full Brightness. 50% Alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
Program 10 menampilkan perubahan yang terjadi pada void init() dan void mydisplay() pada Program
9 (Texture Mapping) sebelumnya, untuk menghasilkan suatu box tranparan. Hasilnya bisa terlihat
pada screenshot berikut ini:
Gambar 7.1 Transparency
// Transparency
// Program ini menampilkan efek transparan pada texture
// Image Loadernya menggunakan library tambahan yaitu SOIL (Simple
OpenGL Image Library)
// Untuk mendapatkan efek transparan caranya dengan melakukan
Blending dengan warna putih dan 50% Alpha
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "SOIL.h"
#include <GL/glut.h>
float z_pos = -5.0f;
float xRot, yRot, zRot;
float rot = 0.0f;
GLfloat LightAmbient[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat LightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat LightPosition[] = {0.0f, 0.0f, 2.0f, 1.0f};
// storage for one texture
GLuint tex_2d;
/* storage for one texture */
GLuint texture[1];
GLuint LoadGLTextures();
void init();
void myKeyboard(unsigned char, int, int);
void myDisplay(void);
void myTimeOut(int);
void resize(int, int);
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Transparency");
glutDisplayFunc(myDisplay);
glutIdleFunc(myDisplay);
glutKeyboardFunc(myKeyboard);
glutReshapeFunc(resize);
glutTimerFunc(100, myTimeOut, 0);
init();
glutMainLoop();
return 0;
}
GLuint LoadGLTextures() // Load Bitmaps
And Convert To Textures
{
/* load an image file directly as a new OpenGL texture */
tex_2d = SOIL_load_OGL_texture("3.jpg", SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS |
SOIL_FLAG_INVERT_Y |
SOIL_FLAG_NTSC_SAFE_RGB |
SOIL_FLAG_COMPRESS_TO_DXT);
/* check for an error during the load process */
if(tex_2d == 0)
{
printf( "SOIL loading error: '%s'n", SOIL_last_result() );
}
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
return tex_2d; // Return Success
}
void init()
{
LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
glEnable(GL_LIGHT1);
glColor4f(1.0f, 1.0f, 1.0f, 0.545f); // Full Brightness. 50% Alpha
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
void myKeyboard(unsigned char key, int x, int y)
{
switch(key)
{
case '<':
case ',':
z_pos -= 0.1f;
break;
case '>':
case '.':
z_pos += 0.1f;
break;
case 27:
exit(0);
break;
default:
break;
}
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, z_pos);
glRotatef(xRot,1.0f,0.0f,0.0f); // Rotate On The X Axis
glRotatef(yRot,0.0f,1.0f,0.0f); // Rotate On The Y Axis
glRotatef(zRot,0.0f,0.0f,1.0f); // Rotate On The Z Axis
glEnable(GL_BLEND); // enabling BLENDING state
glDisable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
// Top Face
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
// Bottom Face
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face
glNormal3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
// Left Face
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
xRot+=0.1f; // X Axis Rotation
yRot+=0.1f; // Y Axis Rotation
zRot+=0.1f; // Z Axis Rotation
glFlush();
glutSwapBuffers();
}
void myTimeOut(int id)
{
rot += 5.0f;
glutPostRedisplay();
glutTimerFunc(100, myTimeOut, 0);
}
void resize(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLdouble)width / (GLdouble)height, 1.0,
300.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
Percobaan: Pada Program 10 seluruh bagian dari boks bersifat transparan. Coba rubah agar hanya satu
bagian saja yang menjadi transparan dengan texture yang berbeda dari permukaan boks lainnya.

More Related Content

What's hot

The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202Mahmoud Samir Fayed
 
C++ Expression Templateを使って式をコンパイル時に微分
C++ Expression Templateを使って式をコンパイル時に微分C++ Expression Templateを使って式をコンパイル時に微分
C++ Expression Templateを使って式をコンパイル時に微分masahiro nishiba
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesMichel Alves
 
The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181Mahmoud Samir Fayed
 
Diagrama de flujo de simulacion de variables
Diagrama de flujo de simulacion de variablesDiagrama de flujo de simulacion de variables
Diagrama de flujo de simulacion de variablesErickPea26
 
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196Mahmoud Samir Fayed
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Aila Gema Safitri
 
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189Mahmoud Samir Fayed
 
Ass day3 1_bd flag
Ass day3 1_bd flagAss day3 1_bd flag
Ass day3 1_bd flagRobi Parvez
 
Getting touchy - an introduction to touch and pointer events / Future of Web ...
Getting touchy - an introduction to touch and pointer events / Future of Web ...Getting touchy - an introduction to touch and pointer events / Future of Web ...
Getting touchy - an introduction to touch and pointer events / Future of Web ...Patrick Lauke
 
Programação de Jogos - Design Patterns
Programação de Jogos - Design PatternsProgramação de Jogos - Design Patterns
Programação de Jogos - Design PatternsBruno Cicanci
 
みんなで Swift 復習会 GO! in 福岡 – 5th′
みんなで Swift 復習会 GO! in 福岡 – 5th′みんなで Swift 復習会 GO! in 福岡 – 5th′
みんなで Swift 復習会 GO! in 福岡 – 5th′Tomohiro Kumagai
 

What's hot (20)

The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.8 book - Part 62 of 202
 
C++ Expression Templateを使って式をコンパイル時に微分
C++ Expression Templateを使って式をコンパイル時に微分C++ Expression Templateを使って式をコンパイル時に微分
C++ Expression Templateを使って式をコンパイル時に微分
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - Exercises
 
C++ lecture 02
C++   lecture 02C++   lecture 02
C++ lecture 02
 
The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202The Ring programming language version 1.8 book - Part 63 of 202
The Ring programming language version 1.8 book - Part 63 of 202
 
The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181
 
Diagrama de flujo de simulacion de variables
Diagrama de flujo de simulacion de variablesDiagrama de flujo de simulacion de variables
Diagrama de flujo de simulacion de variables
 
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
 
3 flow
3 flow3 flow
3 flow
 
Gambas
Gambas Gambas
Gambas
 
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189
 
Ass day3 1_bd flag
Ass day3 1_bd flagAss day3 1_bd flag
Ass day3 1_bd flag
 
Tu1
Tu1Tu1
Tu1
 
Getting touchy - an introduction to touch and pointer events / Future of Web ...
Getting touchy - an introduction to touch and pointer events / Future of Web ...Getting touchy - an introduction to touch and pointer events / Future of Web ...
Getting touchy - an introduction to touch and pointer events / Future of Web ...
 
Programação de Jogos - Design Patterns
Programação de Jogos - Design PatternsProgramação de Jogos - Design Patterns
Programação de Jogos - Design Patterns
 
Open gles
Open glesOpen gles
Open gles
 
Control flow in c
Control flow in cControl flow in c
Control flow in c
 
みんなで Swift 復習会 GO! in 福岡 – 5th′
みんなで Swift 復習会 GO! in 福岡 – 5th′みんなで Swift 復習会 GO! in 福岡 – 5th′
みんなで Swift 復習会 GO! in 福岡 – 5th′
 
変数の型 - Java 演習
変数の型 - Java 演習 変数の型 - Java 演習
変数の型 - Java 演習
 

Similar to Tutorial 07. Transparency Effect

The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210Mahmoud Samir Fayed
 
FLTK Summer Course - Part VIII - Eighth Impact - Exercises
FLTK Summer Course - Part VIII - Eighth Impact - ExercisesFLTK Summer Course - Part VIII - Eighth Impact - Exercises
FLTK Summer Course - Part VIII - Eighth Impact - ExercisesMichel Alves
 
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196Mahmoud Samir Fayed
 
Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function Jannat Jamshed
 
Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function Jannat Jamshed
 
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180Mahmoud Samir Fayed
 
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docxajoy21
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source codeBrian Goggins
 
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180Mahmoud Samir Fayed
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportBijoy679
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212Mahmoud Samir Fayed
 

Similar to Tutorial 07. Transparency Effect (20)

The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
FLTK Summer Course - Part VIII - Eighth Impact - Exercises
FLTK Summer Course - Part VIII - Eighth Impact - ExercisesFLTK Summer Course - Part VIII - Eighth Impact - Exercises
FLTK Summer Course - Part VIII - Eighth Impact - Exercises
 
Robot by gulnaz
Robot by gulnazRobot by gulnaz
Robot by gulnaz
 
Robot by gulnaz
Robot by gulnazRobot by gulnaz
Robot by gulnaz
 
The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196The Ring programming language version 1.7 book - Part 60 of 196
The Ring programming language version 1.7 book - Part 60 of 196
 
Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function
 
Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function Robot In OpenGL Using Line Function
Robot In OpenGL Using Line Function
 
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202
 
The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.5.1 book - Part 54 of 180
 
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180
 
Open GL Tutorial10
Open GL Tutorial10Open GL Tutorial10
Open GL Tutorial10
 
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source code
 
Robot by gulnaz
Robot by gulnazRobot by gulnaz
Robot by gulnaz
 
Robot by gulnaz
Robot by gulnazRobot by gulnaz
Robot by gulnaz
 
The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185The Ring programming language version 1.5.4 book - Part 54 of 185
The Ring programming language version 1.5.4 book - Part 54 of 185
 
The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180The Ring programming language version 1.5.1 book - Part 53 of 180
The Ring programming language version 1.5.1 book - Part 53 of 180
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212
 

More from Roziq Bahtiar

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profileRoziq Bahtiar
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routingRoziq Bahtiar
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemRoziq Bahtiar
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrogramanRoziq Bahtiar
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatRoziq Bahtiar
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajenRoziq Bahtiar
 
7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman strukturRoziq Bahtiar
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointerRoziq Bahtiar
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_stringRoziq Bahtiar
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsiRoziq Bahtiar
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrogramanRoziq Bahtiar
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrogramanRoziq Bahtiar
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_dataRoziq Bahtiar
 

More from Roziq Bahtiar (20)

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profile
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routing
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating Sistem
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrograman
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulat
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajen
 
Pcd 10
Pcd 10Pcd 10
Pcd 10
 
Pcd 11
Pcd 11Pcd 11
Pcd 11
 
7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman struktur
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointer
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_string
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsi
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data
 
Alpro tutor
Alpro tutorAlpro tutor
Alpro tutor
 
Pcd 7
Pcd 7Pcd 7
Pcd 7
 
Pcd 5
Pcd 5Pcd 5
Pcd 5
 
Pcd 4
Pcd 4Pcd 4
Pcd 4
 
Eigen
EigenEigen
Eigen
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

Tutorial 07. Transparency Effect

  • 1. Tutorial 07. Transparency Salah satu efek yang dapat ditampilkan dari blending adalah transparency, yaitu bagaimana membuat suatu permukaan tampak transparant. Hal ini dicapai dengan menggunakan warna blending putih (full- brightness) dengan transparansi satu dengan fungsi: glColor4f(1.0f, 1.0f, 1.0f, 0.5); // Full Brightness. 50% Alpha glBlendFunc(GL_SRC_ALPHA,GL_ONE); Program 10 menampilkan perubahan yang terjadi pada void init() dan void mydisplay() pada Program 9 (Texture Mapping) sebelumnya, untuk menghasilkan suatu box tranparan. Hasilnya bisa terlihat pada screenshot berikut ini: Gambar 7.1 Transparency
  • 2. // Transparency // Program ini menampilkan efek transparan pada texture // Image Loadernya menggunakan library tambahan yaitu SOIL (Simple OpenGL Image Library) // Untuk mendapatkan efek transparan caranya dengan melakukan Blending dengan warna putih dan 50% Alpha #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include "SOIL.h" #include <GL/glut.h> float z_pos = -5.0f; float xRot, yRot, zRot; float rot = 0.0f; GLfloat LightAmbient[] = {0.5f, 0.5f, 0.5f, 1.0f}; GLfloat LightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat LightPosition[] = {0.0f, 0.0f, 2.0f, 1.0f}; // storage for one texture GLuint tex_2d; /* storage for one texture */ GLuint texture[1]; GLuint LoadGLTextures(); void init(); void myKeyboard(unsigned char, int, int); void myDisplay(void); void myTimeOut(int); void resize(int, int); int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow("Transparency"); glutDisplayFunc(myDisplay); glutIdleFunc(myDisplay);
  • 3. glutKeyboardFunc(myKeyboard); glutReshapeFunc(resize); glutTimerFunc(100, myTimeOut, 0); init(); glutMainLoop(); return 0; } GLuint LoadGLTextures() // Load Bitmaps And Convert To Textures { /* load an image file directly as a new OpenGL texture */ tex_2d = SOIL_load_OGL_texture("3.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); /* check for an error during the load process */ if(tex_2d == 0) { printf( "SOIL loading error: '%s'n", SOIL_last_result() ); } // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, tex_2d); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); return tex_2d; // Return Success } void init() { LoadGLTextures(); glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
  • 4. glEnable(GL_LIGHT1); glColor4f(1.0f, 1.0f, 1.0f, 0.545f); // Full Brightness. 50% Alpha glBlendFunc(GL_SRC_ALPHA, GL_ONE); } void myKeyboard(unsigned char key, int x, int y) { switch(key) { case '<': case ',': z_pos -= 0.1f; break; case '>': case '.': z_pos += 0.1f; break; case 27: exit(0); break; default: break; } } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLoadIdentity(); glTranslatef(0.0f, 0.0f, z_pos); glRotatef(xRot,1.0f,0.0f,0.0f); // Rotate On The X Axis glRotatef(yRot,0.0f,1.0f,0.0f); // Rotate On The Y Axis glRotatef(zRot,0.0f,0.0f,1.0f); // Rotate On The Z Axis glEnable(GL_BLEND); // enabling BLENDING state glDisable(GL_DEPTH_TEST); glBegin(GL_QUADS); // Front Face glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face glNormal3f( 0.0f, 0.0f,-1.0f);
  • 5. glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Face glNormal3f( 0.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Face glNormal3f( 0.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face glNormal3f( 1.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Left Face glNormal3f(-1.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); xRot+=0.1f; // X Axis Rotation yRot+=0.1f; // Y Axis Rotation zRot+=0.1f; // Z Axis Rotation glFlush(); glutSwapBuffers(); } void myTimeOut(int id) { rot += 5.0f; glutPostRedisplay(); glutTimerFunc(100, myTimeOut, 0); } void resize(int width, int height) {
  • 6. glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (GLdouble)width / (GLdouble)height, 1.0, 300.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } Percobaan: Pada Program 10 seluruh bagian dari boks bersifat transparan. Coba rubah agar hanya satu bagian saja yang menjadi transparan dengan texture yang berbeda dari permukaan boks lainnya.