Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I draw one cube and one sphere. I load the cube's name but don't load the sphere's name. When I select the sphere by cursor, The program shows the cube's name. The code like this:
C#
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Translate the whole scene out and into view
glTranslatef(-80.0f, 0.0f, -300.0f);
// Initialize the names stack
glInitNames();
glPushName(0);
// Set material color, Yellow
// Cube
glRGB(255, 255, 0);
glLoadName(CUBE);
glutSolidCube(75.0f);

// Draw Sphere
glRGB(128,0,0);
glTranslatef(120.0f, 0.0f, 0.0f);
glutSolidSphere(50.0f, 15, 15);

glRGB(128,0,0);
glTranslatef(0.0f, -80.0f, 0.0f);
glutSolidSphere(20.0f, 15, 15);
// Restore the matrix state
glPopMatrix();  // Modelview matrix
Posted

1 solution

Could you please try like this.

Here CUBE name is given to glutSolidCube and SPHERES name is given to sphere drawing.
Now you will get SPHERES on picking sphere objects in screen.
C#
// Set material color, Yellow
// Cube
glRGB(255, 255, 0);
// Set Drawing object name to CUBE
glLoadName(CUBE);
glutSolidCube(75.0f);

// Set Drawing object name to SPHERES
glLoadName(SPHERES);
// Draw Sphere
glRGB(128,0,0);
glTranslatef(120.0f, 0.0f, 0.0f);
glutSolidSphere(50.0f, 15, 15);

// Other drawing..........
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900