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 › the best way to add a 2D text interface over GL
Pages: 1 2 
the best way to add a 2D text interface over GL? (Read 6192 times)
the best way to add a 2D text interface over GL?
May 13th, 2005, 1:16pm
 
Hello all

Here I come again, always thirsty for answers.

I want to add some visual interface elements on an openGL sketch;

I start my draw() block with a pushMatrix(); at the end, I add a popMatrix() and draw the interface.

The problem is: it doesn't work. It interacts with the geometry fine, but the camera transformations affect the drawing position.

Is there a way to draw something in absolute terms, outside the camera and model transformations, to keep a fixed visual interface on top of the sketch?


Thanks for any ideas!
Re: the best way to add a 2D text interface over G
Reply #1 - May 13th, 2005, 4:31pm
 
I haven't explored JOGL enough to remember, but the loadIdentity function (its the function name i'm not sure about) replaces the current matrix with the identity matrix, which should do what you need. Draw your shapes, call the identity matrix, draw your interface.
Re: the best way to add a 2D text interface over G
Reply #2 - May 13th, 2005, 7:14pm
 
yeah, that was my initial approach; resetMatrix();

That that made the type disappear.
If I apply a translate with a negative Z value, it reappears - but then I lose the 100% bitmap setting;

this leaves the question:

how can I display the content at the original 100% size after a resetMatrix(); ?

(I'm sorry if I'm sound not very smart, I'm really new to  "The Matrix")
Re: the best way to add a 2D text interface over G
Reply #3 - May 13th, 2005, 7:41pm
 
ok. I almost got it;
(this is real time online learning)

I can type a translate(width/2, height/2) after the reset Matrix to recover the original x and y, but how do I figure out the original Z value?


[edit]
(I meant how can I figure out without printing the matrix, copying and pasting the value - I'm looking for the formula of the original z. Where does the height*8660253 comes from?)
Re: the best way to add a 2D text interface over G
Reply #4 - May 13th, 2005, 10:34pm
 
ok, the aftermath: I've met a dead end. the camera zoom deals with perspective, and I could not find a way to cancel it to draw the interface. resetMatrix() does not work for that... if anyone has any ideas, I would be really really grateful.
Re: the best way to add a 2D text interface over G
Reply #5 - May 13th, 2005, 10:40pm
 
If you call "camera();" it resets the camera to the default 0,0 in the top left, and width,height being bottom right.

the problem however, is that the screen has a z-index stored form all the 3D stuff. What may be happening, is that the 0,0,0 -> width,height,0 plane may be "behind" the 3D stuff you've drawn (as far as processing is concerend).

Iv'e had to fiddle with the scene I'm drawing in the game I'm writing, so that things do not project too close to the camera, and so pass through the interface.

Not knowing what you're doign in the 3D section of your code, it's ahrd to suggest possible solutions. But if possible, I'd reccomend trying to move objects away from the camera (maybe make them bigger to compensate) and see fi that helps.
Re: the best way to add a 2D text interface over G
Reply #6 - May 13th, 2005, 10:57pm
 
hi John

I fixed initially the "behind" problem, by translating the content to the original transformation matrix values.

Everything works well...but... the sketch uses camera zoom - that is implemented through perspective();

As far as I noticed, I can't set two different perspective values inside a draw() - a value for the geometry and then a value for the interface. It doesn't work.

And this is my dead end - so is it impossible to create an user interface on a 3D app? I don't think so. but how to solve this?
Re: the best way to add a 2D text interface over G
Reply #7 - May 13th, 2005, 11:08pm
 
Have you tried calling perspective(); and camera(); after the 3D part, and before the interface section, to reset the view back to the default settings?
Re: the best way to add a 2D text interface over G
Reply #8 - May 13th, 2005, 11:13pm
 
yep. camera is fine; but perspective... It doesn't matter when I call it, it applies to the whole frame...
Re: the best way to add a 2D text interface over G
Reply #9 - May 13th, 2005, 11:20pm
 
I've juse done a test with an applet where I'm doing similar to what you want (albeit without modifying perspective() previously), and I had things working fine.

What I have is:
Code:

void draw()
{
camera(cx,cy,cz,cx,cy,0,0,1,0); //set camera for 3d stuff
perspective(PI/7.0,1.0,cz/10.0,cz*10.0); // set perspective for 3d stuff
.. draw 3D stuff ...
camera(); //reset camera
perspective(); // reset perspective
image(radar,0,0);
ellipse(... etc ...);
}


This seems to work fine for me (except z-depth stuff, but that would be solved if I changed the 3D stuff to be further away because of the perspective)

Re: the best way to add a 2D text interface over G
Reply #10 - May 14th, 2005, 2:02pm
 
Hello

First of all, John, thanks for your help.

After a good night of sleep I could isolate my real problem; I was claiming that perspective couldn't be called twice on draw, because it wouldn't work.

I found my real problem; after calling perspective() again, I don't know why but I can't make the interface to be drawn over the geometry - only under. No matter the Z position, the item drawn after perspective(); gets drawn under.

Here's a code example:
(in theory, I am not supposed to see the grey box wandering around)

Code:

float fov;
float cameraZ;
void setup() {
size(500, 500, P3D);
noFill();
fov = PI/3.0;
cameraZ = (height/2.0) / tan(PI * fov / 360.0);
}

void draw() {
background(255);
perspective(fov, float(width)/float(height),
cameraZ/10.0, cameraZ*10.0);
translate(200, 200, -200);
rotateX(-PI/6);
rotateY(PI/3);
fill(122);
box(100);
resetMatrix();
perspective();
translate(0,0,-50);
fill(0,125,0);
box(45);
}
void mouseMoved() {
fov += radians(mouseY-pmouseY);
}


again, any idea that would enlight this confused topic is warmly welcomed.
Re: the best way to add a 2D text interface over G
Reply #11 - May 14th, 2005, 3:27pm
 
Having had a look, it does look like there may be some issues with perspective(...); things.
I couldn't get the box to be obscured at all.
The second call to perspective(); does reset the perspective, but doesnt stop the second box() being drawn behind the first at all times.

The only way I could get it so that the box can be "behind" the interface (or infront, if close enough) was using camera(...); to move the camera closer or further away from the object.
Re: the best way to add a 2D text interface over G
Reply #12 - May 14th, 2005, 4:04pm
 
i haven't read through this thread thoroughly, perspective() won't do much or may cause trouble if called more than once. you would be better off calling camera() to reset things because that's what it's for.
Re: the best way to add a 2D text interface over G
Reply #13 - May 14th, 2005, 4:13pm
 
The only weirdness that I've experienced so far with multiple camera/perspective calls is that lights seem to only apply for the last camera instead of per camera. Of course, this doesn't mean that this is the only weirdness, just the only weirdness I've experienced. Here's an example:

Code:
import damkjer.ocd.*;

Camera persp;
Camera orth;

void setup() {
size(320, 240, P3D);
persp = new Camera(this, 100,-150, 200);
orth = new Camera(this);
rectMode(CENTER);
}

void draw() {
lights();
background(204);

orth.feed();
rect(0, (height / 2) - 20, width, 40);

persp.feed();
rotateY(PI/3);
box(50, 50, 50);
}

void mouseMoved() {
persp.tumble(radians(mouseX-pmouseX), radians(mouseY-pmouseY));
}


-and-

Code:
import damkjer.ocd.*;

Camera persp;
Camera orth;

void setup() {
size(320, 240, P3D);
persp = new Camera(this, 100,-150, 200);
orth = new Camera(this);
rectMode(CENTER);
}

void draw() {
lights();
background(204);

persp.feed();
rotateY(PI/3);
box(50, 50, 50);

orth.feed();
rect(0, (height / 2) - 20, width, 40);
}

void mouseMoved() {
persp.tumble(radians(mouseX-pmouseX), radians(mouseY-pmouseY));
}
Re: the best way to add a 2D text interface over G
Reply #14 - May 14th, 2005, 4:51pm
 
whups, sorry.. not thinking. you're right, you shouldn't call camera() more than once per frame. it's too messy to support that, so we're not.
Pages: 1 2