PDA

View Full Version : printing text and windows over another scene.



dvm
04-13-2005, 06:41 AM
Hi once again! I've asked this question before, but since I can't seem to find the program where I had implemented it, I need to ask it again.
I'm creating a 3d scene etc. Now I'd like to create a few custom windows (using opengl quads) over this scene. It would really help if I'd change the projection from the 3d scene coordinates to the actual size of the window. What I tried so far is this:

void display()
{
// draw scene here
......
......
// draw extra window in here ///////////////////////////////////////////////
gl.glPushMatrix();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, 600, 0, 600, worldZNear, worldZFar);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();

if (leftMouseBtnDown) {
// next method transforms from window to world coordinates
makeTransform(gl, glu, lastWindowClick, lastUserClick);
if (win1.titleBarClicked(lastUserClick[0], lastUserClick[1])) {
//System.out.println("HElllooo");

}
}

gl.glEnable(GL.GL_BLEND);
win1.drawWindow(gl);
gl.glDisable(GL.GL_BLEND);
gl.glPopMatrix();
// finished drawing extra windows //////////////////////////////////////////
glFlush();
}But this destructs my projection and I can't see anything (black screen) This is actually the same problem as with printing text where one would need an orthographic projection to have proper results.
Another thing that concerns me here, is that the windows need to be transparent, so if I'm not mistaken I need to draw them in the end. Any ideas?

dvm
04-13-2005, 07:47 AM
Ok, kind of fixed it but the next problem is driving me nuts.

.. inside display after everything else is drawn.
// draw extra window in here ///////////////////////////////////////////////
gl.glPushMatrix();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glOrtho(0, 600, 600, 0, worldZNear, worldZFar);
gl.glMatrixMode(GL.GL_MODELVIEW);

//gl.glLoadIdentity();

/*if (leftMouseBtnDown) {
makeTransform(gl, glu, lastWindowClick, lastUserClick);
if (win1.titleBarClicked(lastUserClick[0], lastUserClick[1])) {
//System.out.println("HElllooo");
}
}*/

//gl.glEnable(GL.GL_BLEND);
win1.drawWindow(gl);
//gl.glDisable(GL.GL_BLEND);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
// finished drawing extra windows //////////////////////////////////////////Now I can see the scene I draw before trying to draw the window, but I can't see my window. What's more, I see a test quad using glRecti, but still no window. This is the code I use to draw my window:

public void drawWindow(GL gl) {
gl.glPushMatrix();
gl.glLoadIdentity();

gl.glRecti(50, 30, 100, 100);
gl.glBegin(GL.GL_QUADS);
// draw title bar
gl.glColor4ub(titleBarColor[0], titleBarColor[1], titleBarColor[2], alpha);
gl.glVertex2i(winLeft, winTop); // start on top left and go ccw
gl.glVertex2i(winLeft, winTop - titleBarHeight);
gl.glVertex2i(winLeft + winWidth, winTop - titleBarHeight);
gl.glVertex2i(winLeft + winWidth, winTop);
// draw window
gl.glColor4ub(winColor[0], winColor[1], winColor[2], alpha);
gl.glVertex2i(winLeft, winTop - titleBarHeight);
gl.glVertex2i(winLeft, winTop - winHeight);
gl.glVertex2i(winLeft + winWidth, winTop - winHeight);
gl.glVertex2i(winLeft + winWidth, winTop - titleBarHeight);
gl.glEnd();

// draw text
gl.glColor4ub(txtColor[0], txtColor[1], txtColor[2], (byte)255);
drawString2D(gl, windowTitle, 2, -5);
gl.glPopMatrix();
}As I said, the quad drawn with glRecti is shown, but not the window that I'm drawing with glBegin-glEnd. How can this be? The alpha value is ok, as this worked before. If it's of any assistance:
winLeft = 0;
winTop = 0;
winWidth = 300;
winHeight = 300;
Please help!!!

Relic
04-13-2005, 07:51 AM
You misunderstood glPushMatrix. It only works on the current glMatrixMode setting.
If you normally have Matrixmode modelview current all the time, this code uses the least amount of glMatrixMode calls:

gl.glPushMatrix(); // modelview!
gl.glLoadIdentity();

gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix(); // projection
gl.glLoadIdentity();
gl.glOrtho(0, 600, 0, 600, worldZNear, worldZFar);

// Your 2D stuff here. Make sure it's in between worldZNear, worldZFar.

gl.glPopMatrix(); // projection
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix(); // modelview

// Previous matrix state fully restored.Your previous code also had a bug in the inner glMatrixMode you wanted GL_MODELVIEW instead of GL_PROJECTION.

dvm
04-13-2005, 07:55 AM
Ok, I finally saw the window! Since I had an y-axis inverted projection I got mixed up with the drawing of the triangle. I'm still missing the text though so if anyone sees something. At least I'm not going crazy now!

Relic
04-13-2005, 07:59 AM
Hehe, double post, which showed that I was right.

You're drawing at z == 0.
What's worldZNear and worldZFar?
If this is that same as in your projective setup, 0 mst not draw, because worldZNear must not be 0 then.
Whatever, set it to -1 and 1 and all 2D stuff at z == 0 should be drawn. (Note that this is bad if you'd like it to work with stereo.)

What about depth buffering? Clear the depth buffer or disable depth test.

dvm
04-13-2005, 08:02 AM
Ok, everything ok, sorry for the hassle :rolleyes: