PDA

View Full Version : Sample Code for Highlighting an object with a circle



bargsad
05-21-2002, 10:30 AM
Hi, http://www.opengl.org/discussion_boards/ubb/confused.gif

I am looking for a sample code , where a circle is drawn over a selected(picked) object. I have already done the picking stuff, Picking is working fine , i need to draw a circle or change the color of the the picked object. Can anybody help me with a sample code.

i dont know what to use 1. XOR highlighting
2. Direct Rendering 3. Redrawing the entire object with a different color.

Please help me with a sample code and the explanation for the method being used.

bargsad
05-21-2002, 11:52 AM
its really urgent , thats why i have posted.
please help.
thanx.
all i ask is a sample code or atleast a link to the code.

nexusone
05-21-2002, 12:00 PM
If you know how to pick the object, then just set a varaible to change the color of the object when selected.
Also same would hold true for making a circle.

example:

if (Selected)
{
glColor3fv(Selected_color);
}else glColor3fv(My_object_color);

Draw_Object();



Originally posted by bargsad:
Hi, http://www.opengl.org/discussion_boards/ubb/confused.gif

I am looking for a sample code , where a circle is drawn over a selected(picked) object. I have already done the picking stuff, Picking is working fine , i need to draw a circle or change the color of the the picked object. Can anybody help me with a sample code.

i dont know what to use 1. XOR highlighting
2. Direct Rendering 3. Redrawing the entire object with a different color.

Please help me with a sample code and the explanation for the method being used.

jpummill
05-21-2002, 01:49 PM
I can't remember who originally posted this but someone else was nice enough to add this to the forums a couple months ago:

//----------------------------------------------------------------------------------------------------------------
//-- Other Functions --
//----------------------------------------------------------------------------------------------------------------
void DrawCircle( double r )
{
DrawEllipse( r, r );
}

void DrawEllipse( double a, double b )
{
double const TWO_PI = 6.2831853071795865;
int const NSTEPS = 100;
double t = 0.;
glBegin( GL_LINE_LOOP );
for ( int i = 0; i < (NSTEPS-1); ++i )
{
glVertex2d( a * cos( t ), b * sin( t ) );
t += TWO_PI / NSTEPS;
}
glEnd();
}

Good luck,
jpummill

bargsad
05-21-2002, 03:12 PM
dear Neuxo...

the option what u have given is completely redrawing the model with the selected object alone in a different color, which is costly in my case as my model is huge and so my display lists.

dear jumphill

i think from ur code i can see that u have given code to draw a circle, thanks but should i draw this on a overlay plane(looks like it encircles the selected object), if so
how should i write it - overlay stuff.

nexusone
05-21-2002, 05:59 PM
First I think you need to understand how opengl works. Anytime you change anything in the scene in any way, you must redraw the whole scene!

There is only one other way and that would be to render your scene to a bitmap image, then go back and overlay a color filter to change the selected image. But then you said that you did not want to use a XOR type of overlay.

The correct way would be to do it per my message and redraw the screen.

Also with the Draw circle code posted by the other user is based on you redrawing the screen also.

If it is too slow to redraw the screen, then maybe need to look at a faster video card or processor for your application.


Originally posted by bargsad:
dear Neuxo...

the option what u have given is completely redrawing the model with the selected object alone in a different color, which is costly in my case as my model is huge and so my display lists.

dear jumphill

i think from ur code i can see that u have given code to draw a circle, thanks but should i draw this on a overlay plane(looks like it encircles the selected object), if so
how should i write it - overlay stuff.

[This message has been edited by nexusone (edited 05-21-2002).]

[This message has been edited by nexusone (edited 05-21-2002).]

coredump
05-22-2002, 05:24 AM
you could light your selected object. make it a little brighter than the other objects. when you roll your cursor over an object in Dungeon Siege, the object gets lit a little brighter. very cool effect.

b

bargsad
05-22-2002, 05:38 AM
Dear Nexusone Jumphill and Coredump

thanx , i understand ur replies , but i need a simple sample code which will do this , render a model and then on mouse pick of some object in that model , should highlight the object , (either increasing the brightness or drawing a circle over it or some other way)
a simple code .

thanx guys , one more thing i am new to OpenGL too, all i know is how to pick and render hits and ofcourse conceptual knowledge too.

i just want to complete my module of picking and highlighting, i could get enormous sources for picking and that works prefectly fine , highlighting i dont see much on the Net so i have come to u guys .Redrawing the entire scence , i dont think as a viable options as my model on an average consists of
500,000 elements , if it is a small model , def i would have gone for this , the problem why i dont want to use redrawing is anyway for masking that particular selected object i have to edit my display lists.

i am ready to use XOR overlays , but i am in need of a sample code for the same

sorry for bothering u all.

Mazy
05-22-2002, 05:52 AM
As mentioned earlier, opengl isnt very good at replacing one object in a scene.. and if you have so big displaylists and have to break them apart to mark smaller bits of it, why not make more, but smaller lists?

and dont put the Color in the displaylist either, just set the correct color before you call the list, then you can easily change che color if it's picked..

if you show all the 500 000 polys at the same time you have a very detaile scene, if not, then just cull all things not visible and you probably get a more resonable polycount and the update should be that bad..

if the scene is totally static (which seams to be the case, else you have the same problem when moving around:-) then render to a bitmap and play with that bitmap for the rest of the time (until you have to reload a new scene or change point of view)

nexusone
05-22-2002, 06:21 AM
If you give us a little more details as to what your program does, maybe we can help you a little better. Maybe you need to change the way you are creating your scene.


Originally posted by bargsad:
Dear Nexusone Jumphill and Coredump

thanx , i understand ur replies , but i need a simple sample code which will do this , render a model and then on mouse pick of some object in that model , should highlight the object , (either increasing the brightness or drawing a circle over it or some other way)
a simple code .

thanx guys , one more thing i am new to OpenGL too, all i know is how to pick and render hits and ofcourse conceptual knowledge too.

i just want to complete my module of picking and highlighting, i could get enormous sources for picking and that works prefectly fine , highlighting i dont see much on the Net so i have come to u guys .Redrawing the entire scence , i dont think as a viable options as my model on an average consists of
500,000 elements , if it is a small model , def i would have gone for this , the problem why i dont want to use redrawing is anyway for masking that particular selected object i have to edit my display lists.

i am ready to use XOR overlays , but i am in need of a sample code for the same

sorry for bothering u all.

bargsad
05-22-2002, 06:46 AM
thanx mazy , our application is a dynamic one. so bitmap is ruled out . we are at the same time working on display lists management too. and that is handled by my collegue.
the point here is i dont want to touch the existing models displays list .

hi Nexusone : My acutal module is masking
Mask by Pick and Mask by Window. Before the actual selected object is being masked , i need to highlight the selected object, what is thought for highlighting are two things.
1. draw a small circle around the selected object ,or 2. highlight the selected object by brightening the selected object.

i dont want to touch my model or displaylist for this .
The ways which i came across for doing this without altering the models display list are

1. Overlays 2.XOR highlighting 3.Direct Rendering.

so if i am right and clear, i need a sample code on any of the above said sections.

or else if there is a better way of doing it i will be happy in implementing the same.

please , i need a sample code .

Thanx once again .
i dont know all the three above concepts
ie overlay , XOR and Direct Rendering.

I am very happy that u people are taking so much efforts . Thanx for the same

nexusone
05-22-2002, 06:58 AM
You may find this useful, it was posted a few weeks back on object outlining. http://www.flipcode.com/articles/article_objectoutline.shtml



Originally posted by bargsad:
thanx mazy , our application is a dynamic one. so bitmap is ruled out . we are at the same time working on display lists management too. and that is handled by my collegue.
the point here is i dont want to touch the existing models displays list .

hi Nexusone : My acutal module is masking
Mask by Pick and Mask by Window. Before the actual selected object is being masked , i need to highlight the selected object, what is thought for highlighting are two things.
1. draw a small circle around the selected object ,or 2. highlight the selected object by brightening the selected object.

i dont want to touch my model or displaylist for this .
The ways which i came across for doing this without altering the models display list are

1. Overlays 2.XOR highlighting 3.Direct Rendering.

so if i am right and clear, i need a sample code on any of the above said sections.

or else if there is a better way of doing it i will be happy in implementing the same.

please , i need a sample code .

Thanx once again .
i dont know all the three above concepts
ie overlay , XOR and Direct Rendering.

I am very happy that u people are taking so much efforts . Thanx for the same

jpummill
05-22-2002, 02:24 PM
Hey, good call on the object outline code. I saw that a couple weeks ago but forgot all about it.