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 › drawing 2D on top of orthogonal perspective
Page Index Toggle Pages: 1
drawing 2D on top of orthogonal perspective (Read 566 times)
drawing 2D on top of orthogonal perspective
Jan 9th, 2008, 10:43pm
 
I have a 3d model rendered in opengl, navigated with a camera, viewed with an orthogonal perspective. I can't find a way to draw UI elements on top without having them distorted.

I made this simple sketch to isolate the problem:

Code:

import processing.opengl.*;

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

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

ortho(-width, width, -height, height, -1000, 1000);
camera(30.0, mouseY, 220.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

fill(150);
box(100);
camera();

//perspective();

noLights();
hint(DISABLE_DEPTH_TEST);
fill(255,0,0);
rect(0,0,200,200);
unhint(DISABLE_DEPTH_TEST);
}


If the line 'perspective()' is uncommented, the default perspective overwrites the orthogonal, placing the red square where and how it should be, on the top left corner with a size of 200. But the orthogonal view of the model is lost.

Isn't there some simple way to maintain the orthogonal perspective and then draw on top under a different perspective?

I need to use opengl, so drawing the 3d to an out of screen  buffer is not an option. I could modify pixels[], but I'd rather use a faster and simpler solution, if there is one..
Re: drawing 2D on top of orthogonal perspective
Reply #1 - Jan 10th, 2008, 12:24am
 
It's working, the problem is that the ortho projection is twice the size of the sketch window. changing the ortho projection to this brings it back into line with the perspective. (if that makes sense)

Code:
ortho(-width/2, width/2, -height/2, height/2, -1000, 1000);

Re: drawing 2D on top of orthogonal perspective
Reply #2 - Jan 10th, 2008, 1:26am
 
beautiful!! and yes, it does make sense :-) my mistake. and banging my head against the wall was not helping. Thanks for saving my head..
Page Index Toggle Pages: 1