/*
* To change this template, choose Tools |
Templates
* and open the template in the editor.
*/
package org.mikeGila;
import
com.sun.opengl.util.GLUT;
import javax.media.opengl.GL;
import
javax.media.opengl.GLAutoDrawable;
import
javax.media.opengl.GLEventListener;
import
javax.media.opengl.glu.GLU;
/**
*
* @author mikegila
*/
public class isiGLPanel implements
GLEventListener {
private GLUT glut;
//textur
//
private int[] textures = new int[3];//nyimpen 3 tekstur
//lighting
private boolean lightingEnabled; // Lighting ON/OFF
private float[] lightAmbient = {0.5f, 0.5f,
0.0f, 1.0f};
private float[] lightDiffuse = {1.0f, 1.0f,
1.0f, 1.0f};
//private float[] lightPosition = {0.0f,
0.0f, 2.0f, 1.0f};
private float[] lightPosition = {4.0f,
4.0f, 8.0f, 1.0f};
public void init(GLAutoDrawable drawable) {
// Use debug pipeline
// drawable.setGL(new
DebugGL(drawable.getGL()));
GL gl = drawable.getGL();
System.err.println("INIT GL IS:
" + gl.getClass().getName());
//mike
//textures ::
http://i.istockimg.com/file_thumbview_approve/8568236/2/stock-photo-8568236-sponge-texture.jpg
/*
gl.glClearDepth(1.0f); // Depth Buffer Setup
gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To
Do
// Really Nice Perspective Calculations
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_TEXTURE_2D); */
/*
TextureReader.Texture texture = null;
try {
texture =
TextureReader.readTexture("demos/data/images/crate.png");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
*/
/*
//lighting
gl.glLightfv(GL.GL_LIGHT1,
GL.GL_AMBIENT, this.lightAmbient, 0);
gl.glLightfv(GL.GL_LIGHT1,
GL.GL_DIFFUSE, this.lightDiffuse, 0);
gl.glLightfv(GL.GL_LIGHT1,
GL.GL_POSITION, this.lightPosition, 0);
gl.glEnable(GL.GL_LIGHT1);
gl.glEnable(GL.GL_LIGHTING);
this.lightingEnabled = true;
*/
glut = new GLUT();
// Enable VSync
gl.setSwapInterval(1);
// Setup the drawing area and shading
mode
gl.glClearColor(0.0f, 0.0f, 0.0f,
0.0f);
gl.glShadeModel(GL.GL_SMOOTH); // try
setting this to GL_FLAT and see what happens.
}
public void reshape(GLAutoDrawable
drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL();
GLU glu = new GLU();
if (height <= 0) { // avoid a divide
by zero error!
height = 1;
}
final float h = (float) width / (float)
height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0,
20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable
drawable) {
GL gl = drawable.getGL();
GLU glu = new GLU();
GLUT glut = new GLUT();
//
gl.glClear(GL.GL_COLOR_BUFFER_BIT);// |
GL.GL_DEPTH_BUFFER_BIT);
gl.glColor3d(1.0, 1.0, 0.0);
//
gl.glLoadIdentity();
/*
* clear the matrix
*/
/*
* viewing transformation eyex,y,z, centerx,y,z,
upx,y,z
*/
glu.gluLookAt(2.0,0.0,4.0, 0.0,0.0,0.0,
0.0,1.0,1.0);
//kepala
gl.glPushMatrix();//save current matrix
gl.glScalef(1.0f, 1.0f, 0.4f); //untuk
mengubah ukuran tebal tipisnya benda
glut.glutWireCube(1.0f);//benda kubus
dengan satuan 1
gl.glPopMatrix();//pop biar reset
//baju
gl.glPushMatrix();
gl.glTranslatef(0.0f, -0.58f,
0.0f);//mentranslate titik koordinat atas bawah kiri kanan dsb
gl.glScalef(1.0f, 0.15f, 0.4f);
gl.glColor3d(1.0, 1.0, 1.0);
glut.glutWireCube(1.0f);
gl.glPopMatrix();
//celana
gl.glPushMatrix();
gl.glTranslatef(0.0f, -0.73f, 0.0f);//
-0.58-0.15=-0.73
gl.glScalef(1.0f, 0.15f, 0.4f);
gl.glColor3d(1.0, 0.0, 0.0);
glut.glutWireCube(1.0f);
gl.glPopMatrix();
//celana kiri
gl.glPushMatrix();
gl.glTranslatef(-0.2f, -0.84f, 0.0f);//
-0.73-0.15=-0.88
gl.glRotatef(90, 1.0f, 0.0f, 0.0f);
gl.glColor3d(1.0, 0.0, 0.0);
glut.glutWireCylinder(0.1, 0.05, 10,
10);
gl.glPopMatrix();
//celanan kanan
gl.glPushMatrix();
gl.glTranslatef(0.2f, -0.84f, 0.0f);//
-0.73-0.15=-0.88
gl.glRotatef(90, 1.0f, 0.0f, 0.0f);
gl.glColor3d(1.0, 0.0, 0.0);
glut.glutWireCylinder(0.1, 0.05, 10,
10);
gl.glPopMatrix();
//kaki kiri
gl.glPushMatrix();
gl.glTranslatef(-0.2f, -0.84f, 0.0f);//
-0.73-0.15=-0.88
gl.glRotatef(90, 1.0f, 0.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 0.0);
glut.glutWireCylinder(0.02, 0.5, 5, 5);
gl.glPopMatrix();
//kakikanan
gl.glPushMatrix();
gl.glTranslatef(0.2f, -0.84f, 0.0f);//
-0.73-0.15=-0.88
gl.glRotatef(90, 1.0f, 0.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 0.0);
glut.glutWireCylinder(0.02, 0.5, 5, 5);
gl.glPopMatrix();
//lengan baju kiri
gl.glPushMatrix();
gl.glTranslatef(-0.5f, -0.2f, 0.0f);
gl.glRotatef(90, 0.0f, -1.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 1.0);
glut.glutWireCone(0.1, 0.3, 10, 10);
gl.glPopMatrix();
//lengan baju kanan
gl.glPushMatrix();
gl.glTranslatef(0.5f, -0.2f, 0.0f);
gl.glRotatef(90, 0.0f, 1.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 1.0);
glut.glutWireCone(0.1, 0.3, 10, 10);
gl.glPopMatrix();
//lengan kiri
gl.glPushMatrix();
gl.glTranslatef(-0.5f, -0.2f, 0.0f);
gl.glRotatef(90, 0.0f, -1.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 0.0);
glut.glutWireCylinder(0.02, 1, 5, 5);
gl.glPopMatrix();
//lengan kanan
gl.glPushMatrix();
gl.glTranslatef(0.5f, -0.2f, 0.0f);
gl.glRotatef(90, 0.0f, 1.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 0.0);
glut.glutWireCylinder(0.02, 1, 5, 5);
gl.glPopMatrix();
//mata kiri
gl.glPushMatrix();
gl.glTranslatef(-0.2f, 0.0f, 0.2f);
gl.glScalef(1.0f, 1.0f, 0.4f);
gl.glColor3d(0.5, 0.7, 1.0);
glut.glutWireSphere(0.2, 10, 10);
gl.glPopMatrix();
//mata kanan
gl.glPushMatrix();
gl.glTranslatef(0.2f, 0.0f, 0.2f);
gl.glScalef(1.0f, 1.0f, 0.4f);
gl.glColor3d(0.5, 0.7, 1.0);
glut.glutWireSphere(0.2, 10, 10);
gl.glPopMatrix();
//hidung
gl.glPushMatrix();
gl.glTranslatef(0.0f, -0.15f, 0.26f);
gl.glScalef(1.0f, 1.0f, 1.5f);
gl.glColor3d(1.0, 1.0, 0.0);
glut.glutWireSphere(0.06, 10, 10);
gl.glPopMatrix();
//mulut
gl.glPushMatrix();
gl.glTranslatef(0.0f, -0.35f, 0.2f);
gl.glScalef(3.5f, 1.0f, 0.0f);
gl.glColor3d(1.0, 0.0, 0.0);
glut.glutWireSphere(0.06, 10, 10);
gl.glPopMatrix();
//gigi kiri
gl.glPushMatrix();
gl.glTranslatef(-0.04f, -0.34f, 0.2f);
gl.glScalef(0.8f, 1.1f, 0.5f);
gl.glColor3d(1.0, 1.0, 1.0);
glut.glutWireCube(0.08f);
gl.glPopMatrix();
//gigi kanan
gl.glPushMatrix();
gl.glTranslatef(0.04f, -0.34f, 0.2f);
gl.glScalef(0.8f, 1.1f, 0.5f);
gl.glColor3d(1.0, 1.0, 1.0);
glut.glutWireCube(0.08f);
gl.glPopMatrix();
gl.glFlush();
}
public void displayChanged(GLAutoDrawable
drawable, boolean modeChanged, boolean deviceChanged) {
}
}