?
Solved

How to force a gluDisk to the foreground

Posted on 2006-07-22
11
Medium Priority
?
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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