Solved

How to force a gluDisk to the foreground

Posted on 2006-07-22
11
473 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the volume of a hexagonal prism where one end is bigger than the other 3 218
scores100 challenge 3 121
bunnyEars2 challenge 6 148
How Complex Is This Java Course ? 11 125
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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