Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Sample Code for Highlighting an object with a circle

  1. #1
    Junior Member Newbie
    Join Date
    May 2002
    Location
    SouthField, MI, USA
    Posts
    5

    Sample Code for Highlighting an object with a circle

    Hi,

    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.

  2. #2
    Junior Member Newbie
    Join Date
    May 2002
    Location
    SouthField, MI, USA
    Posts
    5

    Re: Sample Code for Highlighting an object with a circle

    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.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: Sample Code for Highlighting an object with a circle

    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,

    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.

  4. #4
    Intern Contributor
    Join Date
    Dec 2001
    Posts
    93

    Re: Sample Code for Highlighting an object with a circle

    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

  5. #5
    Junior Member Newbie
    Join Date
    May 2002
    Location
    SouthField, MI, USA
    Posts
    5

    Re: Sample Code for Highlighting an object with a circle

    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.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: Sample Code for Highlighting an object with a circle

    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).]

  7. #7
    Junior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    186

    Re: Sample Code for Highlighting an object with a circle

    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

  8. #8
    Junior Member Newbie
    Join Date
    May 2002
    Location
    SouthField, MI, USA
    Posts
    5

    Re: Sample Code for Highlighting an object with a circle

    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.

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    612

    Re: Sample Code for Highlighting an object with a circle

    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)

  10. #10
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: Sample Code for Highlighting an object with a circle

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •