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 › New Library: SuperPoint & SuperTri
Pages: 1 2 
New Library: SuperPoint & SuperTri (Read 9177 times)
Re: New Library: SuperPoint & SuperTri
Reply #15 - Mar 26th, 2009, 1:03pm
 
I'm testing using a Display List right now and it is very fast, but I'd like to try a VBO as I'm probably going to want to update the data.
Re: New Library: SuperPoint & SuperTri
Reply #16 - Mar 26th, 2009, 3:40pm
 
Here is my Display List that I'd like to convert into a VBO.

Code:

int nodeList;
void initNodes(){
pgl.beginGL();
nodeList = gl.glGenLists(1);
gl.glNewList(nodeList, GL.GL_COMPILE);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
textureImg.bind();
textureImg.enable();
noStroke();
shader.startShader();
gl.glBegin(gl.GL_QUADS);
gl.glColor3f(1, 1, 1);
for (int i = 0; i < Nodes.length; i++) {
gl.glTexCoord4f(Nodes[i].x, Nodes[i].y, Nodes[i].z, Nodes[i].w );
gl.glVertex2f( -1.0f, -1.0f );
gl.glVertex2f( +1.0f, -1.0f );
gl.glVertex2f( +1.0f, +1.0f );
gl.glVertex2f( -1.0f, +1.0f );
}
gl.glEnd();
shader.endShader();
textureImg.disable();
gl.glEndList();
pgl.endGL();
}
Re: New Library: SuperPoint & SuperTri
Reply #17 - Mar 27th, 2009, 7:59am
 
And if you know the magic on how to turn those four vertex's into point sprites, I would sure like to know.  I keep trying but am not having much luck with displaying it.  I have current mac hardware so I wouldn't think my video card would be an issue.  I think I'm just doing it wrong.. though I can't figure out why.
Re: New Library: SuperPoint & SuperTri
Reply #18 - Mar 27th, 2009, 10:46am
 
I tried to do point sprites once but never managed it.

As for your code above, your'e doing some weird stuff with those tex-coords.

95% of code I've seen has a texCoord for each vertex, e.g.
gl.glTexCoord2f(0,0);
gl.glVertex2f(-1,-1);
gl.glTexCoord2f(1,0);
gl.glVertex2f(1,-1);
//etc...

If you build buffers in that way, one pair of tex coords per vertex, then you should be able to just do buffers directly:
Code:

gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
//...
gl.glBindBuffer(GL.GL_ARRAY_BUFFER,vertexBufferID);
gl.glVertexPointer(2,GL.GL_FLOAT,0,0);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER,textureBufferID);
gl.glTexCoordPointer(2,GL.GL_FLOAT,0,0);
gl.glDrawArrays(GL.GL_QUADS,0,numQuads);
Re: New Library: SuperPoint & SuperTri
Reply #19 - Apr 21st, 2010, 11:52am
 
I've noticed a really weird bug. When you call perspective(), it seems to flip the Y-axis of anything rendered with SuperPoint/SuperTri.

Code:

import com.hardcorepawn.*;
import processing.opengl.*;

SuperPoint p;

void setup() {
 size(512, 512, OPENGL);
 p=new SuperPoint(this);
 for(int i = 0; i < 100000; i++) {
   p.addPoint(
random(-100,100), random(-100,100), random(-100,100),
random(1), random(1), random(1), random(1));
 }
}

void draw() {
 background(0);
 if(mousePressed) {
   float cameraZ = (height / 2.0) / tan(PI * 60.0 / 360.0);
   perspective(PI / 3.0, (float) width / (float) height, cameraZ / 10.0, cameraZ * 10.0);
 }
 translate(mouseX, mouseY, -512);
 box(200);
 p.draw(3);
}



If you run this sketch and alternate holding the mouse down, you'll notice the box() and the SuperPoint cloud either being in the same space or mirroring each other.

Any ideas?
Re: New Library: SuperPoint & SuperTri
Reply #20 - Apr 21st, 2010, 1:18pm
 
processing likes to keep it's positive Y pointing down, that might be it. a quick fix is for you to invert the Y direction. use a scale(1, -1, 1) on the superthingy. that might work
Re: New Library: SuperPoint & SuperTri
Reply #21 - Apr 21st, 2010, 2:11pm
 
Thanks for the idea -- but I've tried that already and it just inverts everything (i.e., the box and the cloud just exchange positions).

I think it's something more insidious that has to do with the OpenGL projection matrix not being reset immediately when you call perspective().

If I simplify the code a bit:

Code:

if(mousePressed)
perspective();


It still doesn't work... but strangely, if I move that call to another thread:

Code:

void mouseMoved() {
perspective();
}


There is no issue.

That's what makes me think it's a problem with calling perspective() every frame... I just don't understand what the difference is between the way box() is drawn and the way a SuperPoint is drawn.
Re: New Library: SuperPoint & SuperTri
Reply #22 - Apr 21st, 2010, 2:24pm
 
no, you can't use that to scale the whole world. just one of them
in your case, the box or the points.

my guess is that the super point library is using system coordinate of opengl, while procesing uses a flipped Y.
so if you flip one of them using that trick it will work fine.

for that you do something like

pushMatrix();
scale( 1, -1, 1 );
//render here
popMatrix();

// render second part here
Re: New Library: SuperPoint & SuperTri
Reply #23 - Apr 21st, 2010, 10:14pm
 
Ah, I see -- that doesn't really work either, though, as I want to apply the same series of rotations/translations to both objects:

Code:

background(0);
if(mousePressed)
perspective();

translate(mouseX, mouseY, -512);

pushMatrix();
if(mousePressed)
scale(1, -1, 1);
box(200);
popMatrix();

p.draw(3);


(scale() would have to be before the first translate().)

In this simple case, I could always just use two separate translates... but the actual usage is more complicated, and I have a bunch of translates/rotates/etc. that are applied to SuperPoint and non-SuperPoint objects...

Is there maybe some way of forcing SuperPoint to use the same modelview matrix as Processing? All it's doing is basically:

Code:

gl = ((PGraphicsOpenGL)p.g).beginGL();
...
gl.glDrawArrays(GL.GL_TRIANGLES, 0, numTris * 3);
((PGraphicsOpenGL)p.g).endGL();


So maybe the Processing matrix just hasn't been "applied" to the GL context yet?
Re: New Library: SuperPoint & SuperTri
Reply #24 - Apr 22nd, 2010, 5:22am
 
well, if you have access to the point list, and it is in object space (center point of center of coord system, them just multiply every point by -1.

other option is doing what i told you. doesn't matter how many transformations you have to do, just need to do it right. imagine how many transformation is going one per frame on a game like Crysis or old as Quake ?? alot more than you have i'm sure, and still they run in realtime =)

so don't be afraid and just try it. its a good practice =)
Re: New Library: SuperPoint & SuperTri
Reply #25 - Apr 22nd, 2010, 8:43pm
 
Hey Victor -- just want to say thanks so much for all your help so far Smiley

It's not that I'm worried about the complexity of the transform. Just that the order is important. If both the box() and the SuperPoint need to move mouseY distance vertically, but one in the positive direction and the other in the negative direction, then I need to call scale() before I call translate() -- but have it only apply in one case and not the other (which doesn't really make sense).

Furthermore, I think it's more than just a scale(1, -1, 1) difference between the two cases. Here's a sketch that calls perspective() every frame so long as you're holding the mouse down:

Code:

import com.hardcorepawn.*;
import processing.opengl.*;

SuperPoint p;

void setup() {
 size(640, 480, OPENGL);
 p=new SuperPoint(this);
 for(int i = 0; i < 100000; i++) {
   p.addPoint(
     random(-100,100), random(-100,100), random(-100,100),
     random(1), random(1), random(1), random(1));
 }
}

void draw() {
 background(0);
 if(mousePressed)
   perspective();
 
 pushMatrix();
 translate(mouseX, mouseY, -512);
 rotateX(radians(mouseY));
 rotateY(radians(mouseX));
 rotateZ(radians(mouseX));
 box(200);
 popMatrix();
 
 pushMatrix();
 if(mousePressed) {
   if(keyPressed) {
     translate(0, height, 0);
     scale(1, -1, 1);
     translate(mouseX, mouseY, -512);
     rotateX(radians(mouseY));
     rotateY(radians(mouseX));
     rotateZ(radians(mouseX));
   } else {
     translate(mouseX, height - mouseY, -512);
     rotateX(-radians(mouseY));
     rotateY(radians(mouseX));
     rotateZ(-radians(mouseX));
   }
 } else {
   translate(mouseX, mouseY, -512);
   rotateX(radians(mouseY));
   rotateY(radians(mouseX));
   rotateZ(radians(mouseX));
 }
 p.draw(3);
 popMatrix();
}


You can see that the corollary of:

Code:

translate(mouseX, mouseY, -512);
rotateX(radians(mouseY));
rotateY(radians(mouseX));
rotateZ(radians(mouseX));


Can't be accomplished by simply preceding it with a scale(1, -1, 1), but has to be done:

Code:

translate(mouseX, height - mouseY, -512);
rotateX(-radians(mouseY));
rotateY(radians(mouseX));
rotateZ(-radians(mouseX));


If you have an idea of something I can tell OpenGL that will effectively accomplish this same thing (negative scale with height offset, negative x and z rotations)... that would be super helpful!
Re: New Library: SuperPoint & SuperTri
Reply #26 - Apr 22nd, 2010, 9:37pm
 
I found a relevant post that seems to go through quite a process to get "pure" OpenGL and Processing happening in the same space. http://processing.org/discourse/yabb2/num_1248632000.html

Which makes me think you can't do what I wanted, where you apply the transformations once and then draw with P5 and OpenGL with the same sequence of transforms.

I might be able to convert my code to just using OpenGL, so I'm going to go for that instead...
Re: New Library: SuperPoint & SuperTri
Reply #27 - Apr 23rd, 2010, 7:32am
 
i've tested your example and here it is working.

Code:
import com.hardcorepawn.*;
import processing.opengl.*;

SuperPoint p;

void setup()
{
 size(640, 480, OPENGL);
 p=new SuperPoint(this);
 for(int i = 0; i < 100000; i++) {
   p.addPoint(
random(-100,100), random(-100,100), random(-100,100),
random(1), random(1), random(1), random(1));
 }
}

void draw()
{
 background(0);
 
 perspective();// PI*0.25, 4.0/3.0, 1, 2000 );
 
 pushMatrix();
 translate( width*0.5, height*0.5 );    // processing likes top-left as center.. i don't like that neither does opengl in perspective mode
 translate( mouseX-(width*0.5), mouseY-(height*0.5), -512);
 rotateX(radians(mouseY));
 rotateY(radians(mouseX));
 rotateZ(radians(mouseX));
 box(200);
 popMatrix();

 pushMatrix();
 translate( width*0.5, height*0.5 );    // processing likes top-left as center.. i don't like that neither does opengl in perspective mode
 translate( mouseX-(width*0.5), (HEIGHT-mouseY)+(height*0.5), -512); // invert y. the offset is just to get the mouse motion/anim as you had before
 rotateX(-radians(mouseY)); // rotations also play different
 rotateY(radians(mouseX));
 rotateZ(-radians(mouseX));
 p.draw(3);
 popMatrix();
}


Pages: 1 2