We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
GLTexture. Binding? (Read 551 times)
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();

}}

Re: GLTexture. Binding?
Reply #1 - Sep 2nd, 2008, 8:16am
 
Hi,

Use tex.getTextureID() to obtain the OpenGL ID of the texture:

gl.glBindTexture( GL.GL_TEXTURE_2D, tex.getTextureID());

Andres
Page Index Toggle Pages: 1