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.
IndexProcessing DevelopmentLibraries,  Tool Development › PImage-like objects to maniplate opengl textures
Pages: 1 2 3 
PImage-like objects to maniplate opengl textures (Read 7999 times)
Re: PImage-like objects to maniplate opengl textur
Reply #30 - Aug 2nd, 2008, 5:50pm
 
Great to now that the off-screen mode now works! Thanks a lot for your feedback and testing!

Regarding the particle systems, the solution to the compatibility problems with ATI is more involved, since I implemented those examples using an technique called Vertex Texture Fetch (VTF) which allows to modify vertex position using vales stored inside a floating-point texture. This technique works on NVidia since the geforces 6x00, but it is not supported on the R500 GPU (the one used in the 1x00 line). I think it is supported in the next generation of Radeons (2x00 and later) but I don't have any confirmation about this.

However, there is a workaround to this problem, which consists in using an alternative technique called Render to Vertex Buffer (R2VF). This works both on NVidia and ATI, but requires some additional coding in the library. My plan is to include R2VF in the 0.9 release of GLGraphics. But, it will take some time...
Re: PImage-like objects to maniplate opengl textur
Reply #31 - Aug 2nd, 2008, 6:24pm
 
ok, thanks for the info. So how come the particle example does actually work (at least it looks like its working - I have thousands of blue balls which I can interact with using my mouse and it looks like some kind of particular fluid dynamics?). Does that extension just make the whole thing faster, and if you don't have the extension it still runs, but slower? (I get 23fps on Mac Pro and Macbook  Pro).
Re: PImage-like objects to maniplate opengl textur
Reply #32 - Aug 2nd, 2008, 6:37pm
 
Wait... I understood that it wasn't working. Well, that is interesting! So you are running SimpleGPUParticleSystem on a X1900XT, right?

23fps is what I get on a nvidia geforce 8400. To tell you the truth, I don't know why it is working, as I said, the extension I'm using to render the particles in the correct position is supposedly not supported on ATI 1x00.
Re: PImage-like objects to maniplate opengl textur
Reply #33 - Aug 2nd, 2008, 6:51pm
 
Yeh appears to be working fine, I just get
Quote:
Fragment shader compilation:  
WARNING: 0:34: extension 'GL_ARB_draw_buffers' is not supported


So no errors, just warning.
I tried replacing GL_ARB_draw_buffers with GL_ATI_draw_buffers and got the same error. So I removed the line and got no warning... but appears to run fine on both 1600 (macbook pro) and 1900 (mac pro) - and i get the same framerate (23fps) on both...

Re: PImage-like objects to maniplate opengl textur
Reply #34 - Aug 6th, 2008, 1:16pm
 
Hi Andres, I'm using the offscreen rendering now and works great. One question I have is though, how do I deal with raw opengl commands when dealing with GLGraphics? My situation is this:

I have a couple of different textures, and I don't want to draw them with the image command, but bind the texture once, and then draw a few thousand quads on one GLGraphics, and then bind another texture and draw another few thousand on another GLGraphics with a different texture etc. Also change blending functions to additive, normal, enable/disable etc. I guess I still need a global pgl and gl and do all opengl state changes on that? Can I draw raw gl commands to a GLGraphics?

cheers,
Re: PImage-like objects to maniplate opengl textur
Reply #35 - Aug 6th, 2008, 1:44pm
 
yes, you can just obtain the opengl id of the GLTexture with the getTextureID method, and then just use the opengl raw commands to texture geometric primitives with the texture. This requires defining the pgl, gl variables.
Re: PImage-like objects to maniplate opengl textur
Reply #36 - Aug 6th, 2008, 1:44pm
 
yes, you can just obtain the opengl id of the GLTexture with the getTextureID method, and then just use the opengl raw commands to texture geometric primitives with the texture. This requires defining the pgl, gl variables.
Re: PImage-like objects to maniplate opengl textur
Reply #37 - Aug 7th, 2008, 12:43am
 
Hi Andres, I can't seem to get it working. Its not the texture that is a problem, but I would like to send the opengl primitives to the offscreen buffer. Can I do that? My code is below and its not working. Am I doing it wrong? or is it a bug?

If I comment out the beginDraw and endDraw commands, then the quads are rendered straight to screen as expected - and the ellipses are not visible (again as expected). But when the functions are in I don't see the quads at all, just the ellipses - and they are white not colored. Maybe I understood the whole thing incorrectly, do I need to get a GL per offscreen texture? if so how do I do that? I saw that GLTexture has a gl field, but its protected. Or should the beginDraw() just bind the FBO so all following commands go straight there?

Thanks for your help!

Code:

import processing.opengl.*;
import javax.media.opengl.*;
import codeanticode.glgraphics.*;

GLGraphics glg1, glg2;

float mixFactor = 0.5;

PGraphicsOpenGL pgl;
GL gl;
int dlQuad; // display list for quads

void setup() {
size(640, 480, GLConstants.GLGRAPHICS);
msaInitGL();
glg1 = new GLGraphics(300, 300, this, true);
glg2 = new GLGraphics(200, 100, this, true);
}

void draw() {
background(0);
msaBeginGL();

glg1.beginDraw();
gl.glColor4f( 1, 0, 0, random(1));
drawQuad(random(0, glg1.width), random(0, glg1.height), random(20));
glg1.ellipse(random(0, glg1.width), random(0, glg1.height), random(50), random(50));
glg1.endDraw();

glg2.beginDraw();
gl.glColor4f( 0, 1, 0, random(1));
drawQuad(random(0, glg2.width), random(0, glg2.height), random(20));
glg2.ellipse(random(0, glg2.width), random(0, glg2.height), random(50), random(50));
glg2.endDraw();

msaEndGL();
// We mix the images together and scale them so the occupy the entire screen.
tint(1, 1 - mixFactor);
image(glg1.getTexture(), 0, 0, width, height);
tint(1, mixFactor);
image(glg2.getTexture(), 0, 0, width, height);

}

void mouseDragged() {
mixFactor = float(mouseX) / width;
}


void msaInitGL() {
colorMode( RGB, 1.0 ); // to make colors 0..1 (not 0..255)
pgl = (PGraphicsOpenGL) g; // processings opengl graphics object
gl = pgl.beginGL(); // JOGL's GL object
gl.setSwapInterval(1);
msaCreateQuadDisplayList(); // create a display list for drawing quads
gl.glDisable(GL.GL_DEPTH_TEST); // disable any use of zbuffer
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); // set blend mode to normal alpha
gl.glEnable( GL.GL_TEXTURE_2D ); // enable texturing
pgl.endGL();
}

// create quad display list
void msaCreateQuadDisplayList() {
dlQuad = gl.glGenLists(1);
gl.glNewList(dlQuad, GL.GL_COMPILE);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0, 0);
gl.glVertex2f( -1, -1);
gl.glTexCoord2f(1, 0);
gl.glVertex2f( 1, -1);
gl.glTexCoord2f(1, 1);
gl.glVertex2f( 1, 1);
gl.glTexCoord2f(0, 1);
gl.glVertex2f(-1, 1);
gl.glEnd();
gl.glEndList();
}

void msaBeginGL() {
pgl = (PGraphicsOpenGL) g; // processings opengl graphics object
gl = pgl.beginGL(); // JOGL's GL object
}

void msaEndGL() {
pgl.endGL();
}

void drawQuad(float x, float y, float radius) {
gl.glPushMatrix();
gl.glTranslatef(x, y, 0);
gl.glScalef( radius, radius, 1 );
gl.glCallList( dlQuad );
gl.glPopMatrix();
}
Re: PImage-like objects to maniplate opengl textur
Reply #38 - Aug 7th, 2008, 2:12am
 
ok, I found out what I need to do. Hadn't seen GLGraphics was extending PGraphicsOpenGL Tongue working code is below.

Code:

import processing.opengl.*;
import javax.media.opengl.*;
import codeanticode.glgraphics.*;

GLGraphics glg1, glg2;

float mixFactor = 0.5;

PGraphicsOpenGL pgl;
GL gl;
int dlQuad; // display list for quads

void setup() {
size(640, 480, GLConstants.GLGRAPHICS);
msaInitGL();
glg1 = new GLGraphics(300, 300, this, true);
glg2 = new GLGraphics(200, 100, this, true);
}

void draw() {
background(0);

glg1.beginDraw();
gl = msaBeginGL(glg1);
gl.glColor4f( 1, 0, 0, random(1));
drawQuad(random(0, glg1.width), random(0, glg1.height), random(20));
msaEndGL();
glg1.ellipse(random(0, glg1.width), random(0, glg1.height), random(50), random(50));
glg1.endDraw();

glg2.beginDraw();
gl = msaBeginGL(glg2);
gl.glColor4f( 0, 1, 0, random(1));
drawQuad(random(0, glg2.width), random(0, glg2.height), random(20));
msaEndGL();
glg2.ellipse(random(0, glg2.width), random(0, glg2.height), random(50), random(50));
glg2.endDraw();

// We mix the images together and scale them so the occupy the entire screen.
tint(1, 1 - mixFactor);
image(glg1.getTexture(), 0, 0, width, height);
tint(1, mixFactor);
image(glg2.getTexture(), 0, 0, width, height);

}

void mouseDragged() {
mixFactor = float(mouseX) / width;
}


void msaInitGL() {
colorMode( RGB, 1.0 ); // to make colors 0..1 (not 0..255)
pgl = (PGraphicsOpenGL) g; // processings opengl graphics object
gl = pgl.beginGL(); // JOGL's GL object
gl.setSwapInterval(1);
msaCreateQuadDisplayList(); // create a display list for drawing quads
gl.glDisable(GL.GL_DEPTH_TEST); // disable any use of zbuffer
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); // set blend mode to normal alpha
gl.glEnable( GL.GL_TEXTURE_2D ); // enable texturing
pgl.endGL();
}

// create quad display list
void msaCreateQuadDisplayList() {
dlQuad = gl.glGenLists(1);
gl.glNewList(dlQuad, GL.GL_COMPILE);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0, 0);
gl.glVertex2f( -1, -1);
gl.glTexCoord2f(1, 0);
gl.glVertex2f( 1, -1);
gl.glTexCoord2f(1, 1);
gl.glVertex2f( 1, 1);
gl.glTexCoord2f(0, 1);
gl.glVertex2f(-1, 1);
gl.glEnd();
gl.glEndList();
}

GL msaBeginGL(GLGraphics glGraphics) {
pgl = (PGraphicsOpenGL) glGraphics;
gl = pgl.beginGL();
return gl;
}

void msaEndGL() {
pgl.endGL();
}

void drawQuad(float x, float y, float radius) {
gl.glPushMatrix();
gl.glTranslatef(x, y, 0);
gl.glScalef( radius, radius, 1 );
gl.glCallList( dlQuad );
gl.glPopMatrix();
}
Pages: 1 2 3