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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Camera Problem using PGraphicsOpenGL and Blend
Page Index Toggle Pages: 1
Camera Problem using PGraphicsOpenGL and Blend (Read 1314 times)
Camera Problem using PGraphicsOpenGL and Blend
Aug 24th, 2007, 10:53am
 
Hi there,

I'm having a problem with a sketch once I start using OpenGL like this:

import javax.media.opengl.*;

void draw(){
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  // g may change
GL gl = pgl.beginGL();  // always use the GL object returned by beginGL
 
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

MORE CODE
...

pgl.endGL();
}


So everything works, but the camera isn't looking at the same point any more as it does without that piece of code. I assume that the camera works different once I use the OpenGL object but I don't really know how.

I'm using a camera class and this is super simple code that also works fine with "normal" OpenGL Processing:

camera(this.posX, this.posY, this.posZ, // eyeX, eyeY, eyeZ
      this.targetX, this.targetY, this.targetZ, // centerX, centerY, centerZ
      0.0, 1.0, 0.0); // upX, upY, upZ

So any idea or help would be very appreciated!

Re: Camera Problem using PGraphicsOpenGL and Blend
Reply #1 - Aug 24th, 2007, 12:27pm
 
you shouldnt call camera() within beginGL and endGL..
here's your sample code with a test scene.. some random positioned boxes and a rotating camera around y-axis




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


void setup()
{
 size( 400, 400, OPENGL );
}

void draw()
{
 float time = millis() * 0.001;
 
 background( 0 );
 
 camera( sin(time*0.4)*50, 0, cos(time*0.3)*50,
         0, 0, 0,
         0, 1, 0 );
       
 PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
 GL gl = pgl.beginGL();
   
 gl.glDisable(GL.GL_DEPTH_TEST);
 gl.glEnable(GL.GL_BLEND);
 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

 pgl.endGL();

 for( int i=0; i<60; i++ )
 {
   fill( i*100 );
   pushMatrix();
   translate( random(i*5), random(i*10), random(i*8) );
   box( 10 );
   popMatrix();
 }
}
Re: Camera Problem using PGraphicsOpenGL and Blend
Reply #2 - Aug 24th, 2007, 1:19pm
 
You can maybe use the glu version of camera:

Code:
import javax.media.opengl.glu.*;

//...

GLU glu=g.glu;
glu.gluLookAt(/*same options as for camera*/);
Re: Camera Problem using PGraphicsOpenGL and Blend
Reply #3 - Aug 24th, 2007, 4:14pm
 
ofcourse, if wanting to use opengl calls.
that might be what camera() does. its up to the programmer
Re: Camera Problem using PGraphicsOpenGL and Blend
Reply #4 - Aug 24th, 2007, 5:21pm
 
Thanks for the fast reply everyone!
The simple solution by crmx already solved the problem! I assumed having no drawing commands between pgl.beginGL(); and pgl.endGL(); would be a problem, but it seems as if it wouldn't affect the drawing at all.

Will post a preview when I'm done, thanks again!
Page Index Toggle Pages: 1