ehrenk
YaBB Newbies
Offline
Posts: 4
GLTexture. Binding?
Aug 30th , 2008, 5:13pm
So, Im trying to learn some OPENGL with the new GLGraphics library. I have written a simple brightness/contrast glsl shader to go along with the testing.. My main problem is binding a filtered texture back onto a quad (ie. sprite filtering); How does one go about this. Here is my code. import processing.xml.*; import controlP5.*; import processing.opengl.*; import codeanticode.glgraphics.*; import javax.media.opengl.*; import com.sun.opengl.util.texture.*; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; ControlP5 controlP5; PImage tex,texAlpha; PGraphicsOpenGL pgl; GL gl; GLGraphicsOffScreen glMain; float b; //brightness float c; //contrast Quad q1; float [] cpos; void setup() { size(800, 400, GLConstants.GLGRAPHICS); glMain = new GLGraphicsOffScreen(width, height, this); pgl = (PGraphicsOpenGL) g; gl = pgl.gl; q1 = new Quad(this,width/2,-height/2);} void draw() { colorMode(RGB,1.0); background(0); q1.render(); } class Quad { GLTexture img; GLTexture tex; GLTextureFilter pixelate,bc; GLTextureFilterParameters params, paramsa; PImage _image; float x,y; float b=.5; float c=.5; Quad (PApplet t, float _x, float _y){ this.x = _x; this.y=_y; img = new GLTexture(t, "sprite.jpg"); tex = new GLTexture(t,img.width,img.height); pixelate = new GLTextureFilter(t, "pixelate.xml"); paramsa = new GLTextureFilterParameters(t); bc = new GLTextureFilter(t, "bc.xml"); params = new GLTextureFilterParameters(t); } void update(float _x,float _y){ this.x=_x; this.y=_y; } void render() { float k = map(mouseX, 0, 640, -1, 1); float k1 = map(mouseX, 0, 640, 10, 0); //float k1 = -k*2.5 params.parFlt1 = k; params.parFlt2 = (-k*5)-.1; img.filter(bc, tex,params); tex.render(0,0, 200, 200); // Must copy the above from the framebuffer ? and render it onto the quad described below.. gl.glPushMatrix(); gl.glTranslatef(x, y,0); gl.glBegin(GL.GL_QUADS); gl.glEnable( GL.GL_TEXTURE_2D ); gl.glBindTexture( GL.GL_TEXTURE_2D,tex); gl.glNormal3f(0.0f,0.0f,1.0f); gl.glTexCoord2f(0, 0); gl.glVertex2f(0, 200); gl.glTexCoord2f(1, 0); gl.glVertex2f(200,200); gl.glTexCoord2f(1, 1); gl.glVertex2f(200, 0); gl.glTexCoord2f(0, 1); gl.glVertex2f(0, 0); gl.glDisable( GL.GL_TEXTURE_2D ); gl.glEnd(); gl.glPopMatrix(); }}