Created
July 6, 2011 22:03
-
-
Save getflourish/1068462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codeanticode.glgraphics.*; | |
import processing.opengl.*; | |
import javax.media.opengl.*; | |
import java.nio.IntBuffer; | |
import java.nio.ByteBuffer; | |
GL gl; | |
GLSLShader shader; | |
PGraphicsOpenGL pgl; | |
ByteBuffer byteBuffer; | |
IntBuffer intBuffer; | |
int[] envMapTextureID = {0}; | |
GLTexture tex; | |
void setup () { | |
size(400, 400, GLConstants.GLGRAPHICS); | |
hint(ENABLE_OPENGL_4X_SMOOTH); | |
pgl = (PGraphicsOpenGL) g; | |
gl = pgl.gl; | |
shader = new GLSLShader(this, "fluxus.vert", "fluxus.frag"); | |
tex = new GLTexture(this, "fu.jpg"); | |
tex.loadPixels(); | |
byteBuffer = ByteBuffer.allocate(tex.pixels.length * 4); | |
intBuffer = byteBuffer.asIntBuffer(); | |
for (int i = 0; i < intBuffer.capacity(); i++) { | |
intBuffer.put(tex.pixels[i]); | |
} | |
// intBuffer.put(tex.pixels); | |
// init cubemap textures | |
gl.glGenTextures(1, envMapTextureID, 0); | |
gl.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, envMapTextureID[0]); | |
gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); | |
gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); | |
gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE); | |
gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); | |
gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); | |
for (int i = 0; i < 6; i++) { | |
gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL.GL_RGBA, tex.width, tex.height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, byteBuffer); | |
} | |
} | |
void draw () { | |
background(255); | |
fill(255); | |
shader.setFloatUniform("RefractionIndex", 0.5); | |
translate(mouseX, mouseY, 0); | |
shader.start(); | |
sphere(100); | |
shader.stop(); | |
image(tex, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment