Here is a tutorial at nehe that shows how to use glTranslate. There is also delphi code at the bottom of the page to download.
http://nehe.gamedev.net/da
Main Topics
Browse All TopicsI am totally new to openGL (I use Delphi) so this may be a naive question.
I am drawing a graph with the following outline code:
glBegin(GL_LINE_STRIP);
// loop
// assign x, y
glVertex2i(x1, y1);
glVertex2i(x2, y2);
// end loop
glEnd();
This works OK.
However I now wish to generate a sphere, with
FSphereQuadratic := gluNewQuadric();
..
gluSphere(FSphereQuadratic
(This is all take from an example provided by OG.DELCODE.COM).
What I need to do is to locate the sphere on the graph at a specific XY location.
Is there a transformation from a 3-D perspective view to 2-D co-ordinates that will allow me to do this.
Alternatively, how do I save the sphere as a bitmap, and how do I then display the bitmap at the right place?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here is a tutorial at nehe that shows how to use glTranslate. There is also delphi code at the bottom of the page to download.
http://nehe.gamedev.net/da
Thanks - that has got me started with a gluDisk. The code (which works) is:
FSphereQuadratic := gluNewQuadric();
..
glPushMatrix();
glColor3ub (255, 128, 0);
glMatrixMode(GL_MODELVIEW)
glLoadIdentity();
glTranslatef(FCircleX, FCircleY, 0);
gluDisk(FSphereQuadratic, annRadius, FCircleRadius, 32, 32);
glPopMatrix();
However when I try the following with a gluSphere:(only the indented code has changed)
FSphereQuadratic := gluNewQuadric();
..
glPushMatrix();
glColor3ub (255, 128, 0);
glMatrixMode(GL_MODELVIEW)
glLoadIdentity();
glTranslatef(FCircleX, FCircleY, 0);
glMaterialfv(GL_FRONT, GL_AMBIENT, @no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, @mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, @no_mat);
glMaterialf(GL_FRONT, GL_SHININESS, no_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, @no_mat);
glColor3f(1, 0, 0); // Set our current rendering colour to red
gluSphere(FSphereQuadratic
glPopMatrix();
then I get a ghostly outline but nothing in the middle! Am I missing something?
As I said I am a complete beginner with openGL, and still awaiting delivery of my "blue book", but I need this in a hurry :)
The code is below. There is probably a lot of redundant stuff, as I have been cutting and pasting from various working examples. I have not yet had time to clean it all up (with the aid of the "blue book" which I have now received).
The line drawing works fine, but the attempt to draw the sphere does not.
Ok, lets simplify it and clean up.
- Switch off alpha blending, material and switch on wirframe, if that works we will go back it later.
- Make near and far plane larger, 2 last arguments of glOrtho, depending on size of FCircleRadius.
- Set Line width back to 1 after drawing lines
- each glPushMatrix must have an associated glPopMatrix
etc ..
Please post a screenshot from this code:
Plus do some reading on the nehe-tutorials here:
http://nehe.gamedev.net/
OpenGL is not exactly very hands-on, its very hard, if you dont know it and copy some code together, its most likely not gonna work.
Better start from the scratch, the red book is very good too.
Sorry - must have made a mistake in transcribing the original. I have now checked and the proper wire frame is displayed, as shown in the enclosed, with your original code (post 04/11/09 01:10 PM, ID: 25738899).
When I replaced the glOrtho() call with your 05:07pm suggestion, I got the identical wireframe ball, but the underlying curve has disappeared.
>> I got the identical wireframe ball, but the underlying curve has disappeared.
Ok, lets find the right values. Whats the radius of the circle? Those values define how far the near- and far-plane are away from the camera. All objects must be between those values, in order to see them.
Now we can make the objects solid again.
replace those:
glPolygonMode(GL_FRONT_AND
with this:
glPolygonMode(GL_FRONT_AND
enable color use as material color
glEnable(GL_COLOR_MATERIAL
and add a light
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0);
If you use lighting, make sure to generate normals for your sphere with:
gluQuadricNormals(FSphereQ
after you created it with gluNewQuadric
http://www.ugrad.cs.ubc.ca
Getting better. I needed to disable lighting for the curve part (also anti-aliased - a lot better). Have not yet played around with lighting params and other features (sphere is now basic and rather dark), but will do this in the next couple of days. I think I am beginning to get the hang of this.
Thanks v much for your help so far. Could I keep this one open for a couple of days in case my efforts don't work? Inclined to up your points when it's all done. You have been very helpful.
Well, to be blunt, if the solution works, you should close the question.
If you have new questions, you should ask a new question.
However, you can still ask something in this question when you closed it.
But it should be related to the solution, i.e. "displaying an openGL gluSphere at specific X/Y coordinates".
How can I do this-and-that in OpenGL should be covered in a new question, hope you understand that.
ike
Business Accounts
Answer for Membership
by: ikeworkPosted on 2009-11-01 at 15:43:49ID: 25716224
Yes, just call glTranslate with the center-coords of the sphere right before you render it.
This will *move* the sphere to the coords that you pass to glTranslate.