Solved

How to force a gluDisk to the foreground

Posted on 2006-07-22
11
471 Views
Last Modified: 2013-12-06
I'm using gluDisk to draw some disks.  I want these disks to be in the foreground.  However, the disks are blocked from view by the rectangles I've drawn.  I'm drawing the rectangles using glREct.  How do I force the disks to the foreground, so they draw over the rectangles?

Thanks you.
0
Comment
Question by:clintMon
  • 6
  • 5
11 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17162731
If you're doing 2D rendering here, then why not just render the disks last?
0
 

Author Comment

by:clintMon
ID: 17163675
I've tried that, and they still show up under the rectangles.  Some rectangles are drawn using glVertex3d.  I've set the 3rd parameter in this function to 0.0, which should allow ALL other ojbects to display "OVER" the rectangles.  However, my disks still show up BEHIND the rectangles.  Other rectangles are drawn using glRectd().  In the case of glRectd(), there is no parameter for the "depth".
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17163682
Hmm


Out of interest, does using glVertex2d have *any* effect?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:clintMon
ID: 17163748
When I switch from glVertex2D instead of glVertex3D, rectangle b (the rectangle that is drawn second) shows up BEHIND the retangle A (the rectangle that is drawn first, using glRect).  However, my disks, which are drawn last, still show up under both rectanlges.

Ultimately, what I want is the disks to be on top, rectangle B to display "immediately under" the disks, and rectangle A to be on the bottom.
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17163766
Hm
Any chance I could see any of your code please?
0
 

Author Comment

by:clintMon
ID: 17163789
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();

glEnable(GL_POLYGON_STIPPLE);
glRectd(dblLeft, dblYCoordBot, dbRight, dblYCoordTop);//rectangle A, which should show up on the bottom
glDisable(GL_POLYGON_STIPPLE);


//rectangle B, which should show up 2nd from bottom
glColor3f(0.6f, 0.6f, 0.5f)
glBegin(GL_POLYGON);
                        glVertex3d(dblLeft+(1 - currentDia/startDia)*scaleRadius, dblBottom, 1.0);      
                        glVertex3d(dblLeft+(1 - currentDia/startDia)*scaleRadius, dblTop, 1.0);      
                        glVertex3d(dblRight-(1 - currentDia/startDia)*scaleRadius, dblTop, 1.0);      
                        glVertex3d(dblRight-(1 - currentDia/startDia)*scaleRadius, dbltBottom, 1.0);      
glEnd();

//the disks, which should show up ON TOP of the rectangles
glColor3f(0.0f, 0.0f, 0.0f);
GLUquadricObj *quadObj;
quadObj = gluNewQuadric();
gluQuadricOrientation( quadObj, GLU_OUTSIDE );
gluQuadricDrawStyle( quadObj, GLU_FILL );
gluQuadricNormals( quadObj, GLU_SMOOTH );
gluDisk( quadObj, 0.0, .01, 450, 300);
gluDeleteQuadric( quadObj );

glPopMatrix();
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17163811
If you pass the glVertex3d() functions a z-value of -1.0 instead, then does this make a difference at all?

(Sorry, I would test this out myself, but I don't have OpenGL (or any C++ IDE's) installed on this machine).
0
 

Author Comment

by:clintMon
ID: 17163885
Yes.  That worked, but I had to make another change as well.

//for rectangle A, I replaced the call to glRect with glRect3D.  I did this because glRect3D let's you explicitly specify a Z coord (even though I'm using a 2D window).  So my new drawing for rectangle A looks like this:
glBegin(GL_POLYGON);
      glVertex3d(dblLayerLeft, dblYCoordBot, -1.0);
      glVertex3d(dblLayerLeft, dblYCoordTop, -1.0);
      glVertex3d(dblLayerRight, dblYCoordTop, -1.0);      
      glVertex3d(dblLayerRight, dblYCoordBot, -1.0);
glEnd();

//then, for rectangle B, I changed the Z parameter to -0.5.  I did this b/c I wanted the B rectangle to be drawn OVER rectangle A.  So rectangle B's code looks like this:
glColor3f(0.6f, 0.6f, 0.5f)
glBegin(GL_POLYGON);
                    glVertex3d(dblLeft+(1 - currentDia/startDia)*scaleRadius, dblBottom,-0.5);    
                    glVertex3d(dblLeft+(1 - currentDia/startDia)*scaleRadius, dblTop,-0.5);    
                    glVertex3d(dblRight-(1 - currentDia/startDia)*scaleRadius, dblTop,-0.5);    
                    glVertex3d(dblRight-(1 - currentDia/startDia)*scaleRadius, dbltBottom,-0.5);    
glEnd();

//I left the code for the disks the same, which I draw last, using gluDisk.

OK, so everything draws correctly.  One small problem.  NOW, when I click on one of my disks, the hit record shows 3 hits (because the disks are drawn over 2 rectangles).  How do I get access to the hit record for the disk that was clicked on?
0
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 500 total points
ID: 17163917
Right, we're nearly there..


For the Hit Record problem, see if this helps:
http://www.lighthouse3d.com/opengl/picking/index.php3?openglway3

You'll just need to extract the first hit, seeing as it is on top, right?
0
 

Author Comment

by:clintMon
ID: 17163968
Thank you for all your help!!!
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17163974
You're welcome :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question