Solved

How to force a gluDisk to the foreground

Posted on 2006-07-22
11
468 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
Comment Utility
If you're doing 2D rendering here, then why not just render the disks last?
0
 

Author Comment

by:clintMon
Comment Utility
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
Comment Utility
Hmm


Out of interest, does using glVertex2d have *any* effect?
0
 

Author Comment

by:clintMon
Comment Utility
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
Comment Utility
Hm
Any chance I could see any of your code please?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:clintMon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for all your help!!!
0
 
LVL 25

Expert Comment

by:InteractiveMind
Comment Utility
You're welcome :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now