Sign in to follow this  
bushimports

Using c++ container classes with OpenGL Picking

Recommended Posts

I have a program that I am working on that creates graphics objects at runtime and it works fine until I add the gl selection to it. Actually I added it to another program that I set up with gl selection. When I click a button to draw a cube or a plane nothing draws. I just wondered, is it not possible to use any of the c++ conainers with openGL selection/picking? If anyone knows how I can do this I would appreciate any help I can get. If I can't do it with one of the container classes how can I do it? Much Thanks, Jody Bush

Share this post


Link to post
Share on other sites
All you do it pass data to OpenGL, so it does not, nor cannot, know how your objects are stored. Standard containers or not, OpenGL just cannot know, and so it cannot make a difference either. If you have problems to draw the objects, then it is a problem with drawing them only, not storing them. Post code.

Share this post


Link to post
Share on other sites
Here are the global pointers I am using. I am using a pointer to an abstract class so I can create the objects at runtime.

Object* obj; //pointer to abstract class
list<Object*> Objects;
list<Object*>::const_iterator it;

Here is part of the code from the section where I was putting the items to be drawn for picking. Everything was working fine until I exchanged what I was using before with the iterator pointer and the for loop. Actually what I was using before was incorrect. I was not using a base class, I was just creating one object for the Cube class and another for the Plane class and then I was deleting the objects. When I clicked a button it just redrew the same object.
The part of the code for picking the indivdual parts of the objects is in the derived classes draw functions.


if(drawcube == true){

glPushMatrix();
glTranslated(0.0,-2.0,-5.0);
glPushName(num);
glPassThrough((GLfloat)num);
for ( it = Objects.begin(); it != Objects.end(); ++it )
{
(*it)->Draw();

}
glPopName();
glPopMatrix();
}


if(drawplane == true){
glPushMatrix();
glTranslated(0.0,-2.0,-5.0);
glPushName(num);
glPassThrough((GLfloat)num);
for ( it = Objects.begin(); it != Objects.end(); ++it )
{
(*it)->Draw();

}
glPopName();
glPopMatrix();
}



Much Thanks for your help, Jody Bush

Share this post


Link to post
Share on other sites
Ok Brother Bob I got one of the two prorgams to draw in selction mode using the container and iterator pointer,but I have some strange unacceptable behavior. The circle which is supposed to be blue is black and if the circle is drawn the other two shapes are black. Also everything is being drawn at 0,0,0 regardless of what the objects are initialized to. What would cause that? Maybe the derived classes are not overriding the abstract base class, I don't know. I had to wait untill I started getting old to learn anything and I don't retain what I read as well as I did when I was young. I still have a lot to learn not just about c++ but about programming in general. Thanks for your time and effort to try and help me, Jody Bush

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this