[vtkusers] [Fwd: Re: Using OpenGl with VTK] Color using glColor3f

Francois Bertel francois.bertel at kitware.com
Wed Aug 20 17:21:23 EDT 2008


What doesn't work?...

1 With pushattrib you save the current OpenGL state in the stack
(actually some of it, not everything can be saved anyway).
2. You override whatever you need for your algorithm.
3. With popattrib you restore the OpenGL state as it was at step 1.

On Wed, Aug 20, 2008 at 5:17 PM, Mohammed Amine SAHTARI
<msahtari at gmail.com> wrote:
> I apologize, you are right : I mean glPopAttrib() for (3). I try it but it
> doesn't work......do you have any suggestion please?
>
> 2008/8/20, Francois Bertel <francois.bertel at kitware.com>:
>>
>> What do you mean by glPopAttrib() for (2)? It should be for (3).
>>
>>
>>
>> On Wed, Aug 20, 2008 at 12:04 PM, Mohammed Amine SAHTARI
>> <msahtari at gmail.com> wrote:
>> >
>> > Thank you very much François. It works!
>> >
>> > In order to be able ,in future, to copy a large code of OpenGl directly
>> > without checking each time all the OpenGl states. Is there a way to:
>> >
>> > 1) Store the whole state of the VTK/OpenGl properties
>> > :  light,colors,.....
>> > 2) copy the code OpenGl code in my function
>> > 3) restore VTK/OpenGl state properties
>> >
>> > For example, I try glPushAttrib(GL_ALL_ATTRIB_BITS) for (1) , and
>> > glPopAttrib() for (2) but it doesn't work.
>> >
>> > Do you have any idea ?
>> >
>> > Thank you for responding,
>> >
>> > Amine
>> >
>> > 2008/8/20 Francois Bertel <francois.bertel at kitware.com>
>> >>
>> >> Maybe lighting is on. In this case, the color is the result of the
>> >> lighting equation involving material properties, normals and lights
>> >> properties instead of the current OpenGL color:
>> >>
>> >> Try glDisable(GL_LIGHTING);
>> >>
>> >> On Wed, Aug 20, 2008 at 4:43 AM, Mohammed Amine SAHTARI
>> >> <msahtari at gmail.com> wrote:
>> >> > The background is gray and The OpenGl lines has been dispalyed as
>> >> > gray !
>> >> > When I  change  the  background of my screen  I was able to visualize
>> >> > the
>> >> > Opengl lines/faces.
>> >> >
>> >> > I am wondering why the OpenGL lines is grey knowing that i am using
>> >> > glColor3f [(1,0,0);(0,1,0),..] in RenderOpaqueGeometry which should
>> >> > affect
>> >> > other colors to the lines ?!
>> >> >
>> >> > Shall I enable/change an option to fix this matter ? ...Please help!
>> >> >
>> >> > Amine
>> >> >
>> >> >
>> >> >
>> >> > 2008/8/19 Mohammed Amine SAHTARI <msahtari at gmail.com>
>> >> >>
>> >> >>   Thank you very much Amy. The program compiles without any errors!
>> >> >>
>> >> >>   However , I still have a problem : The OpenGl lines doesn't
>> >> >> display
>> >> >> on
>> >> >> the screen.
>> >> >>
>> >> >>   I check In Debug Mode, the RenderOpaqueGeometry function is
>> >> >> executed
>> >> >> permanently ( following the pipeline).
>> >> >>
>> >> >>
>> >> >>
>> >> >> ----- In the main propram----------
>> >> >>
>> >> >>     .............
>> >> >>
>> >> >>      vtkRenderer  *renderer = vtkRenderer  ::New();
>> >> >>
>> >> >>       vtkMyDerivedProp-> RenderOpaqueGeometry(renderer);
>> >> >>
>> >> >>       renderer->AddProp(vtkMyDerivedProp);
>> >> >>
>> >> >>       ...........
>> >> >>
>> >> >> ---- In  Myderived class----------------
>> >> >>
>> >> >> virtual int RenderOpaqueGeometry(vtkViewPort* )
>> >> >>
>> >> >> {
>> >> >>
>> >> >>             glBegin (GL_LINES);
>> >> >>
>> >> >>              glVertex2f (-2.5, 2.5);
>> >> >>              glVertex2f (2.5, -2.5);
>> >> >>              glEnd ();
>> >> >> }
>> >> >>
>> >> >> Any suggestions ? Did I miss something ?
>> >> >>
>> >> >> Thank you in advance,
>> >> >> Amine
>> >> >>
>> >> >>
>> >> >> 2008/8/19 Amy Squillacote <ahs at cfdrc.com>
>> >> >>>
>> >> >>> Hi Amine,
>> >> >>>
>> >> >>> You cannot use VTK_RENDERING_EXPORT since you are not adding your
>> >> >>> class
>> >> >>> to the vtkRendering library. You'll need to create your own export
>> >> >>> macro.
>> >> >>> There is an example of setting up your own additional library for
>> >> >>> VTK
>> >> >>> in the
>> >> >>> VTK/Examples/Build/vtkLocal directory of the VTK source tree.
>> >> >>>
>> >> >>> - Amy
>> >> >>>
>> >> >>> Mohammed Amine SAHTARI wrote:
>> >> >>>>
>> >> >>>> I use vtkStandardNewMacro to add New macro. The problem is that I
>> >> >>>> got
>> >> >>>> 5
>> >> >>>> link errors even if I include the librairies of VTK (In VS 8).
>> >> >>>>
>> >> >>>> Hereby, you find my derived class (.h & .cxx).
>> >> >>>>
>> >> >>>> ---------------- vtkMyDerivedProp.h -------------------------
>> >> >>>>
>> >> >>>> #ifndef __vtkMyDerivedProp_h
>> >> >>>> #define __vtkMyDerivedProp_h
>> >> >>>> #include "vtkProp.h"
>> >> >>>>
>> >> >>>> class VTK_RENDERING_EXPORT vtkMyDerivedProp : public vtkProp
>> >> >>>> {
>> >> >>>> public:
>> >> >>>>
>> >> >>>>  vtkTypeRevisionMacro(vtkMyDerivedProp,vtkProp);
>> >> >>>>  void PrintSelf(ostream& os, vtkIndent indent);
>> >> >>>>  static vtkMyDerivedProp* New();
>> >> >>>>
>> >> >>>> protected:
>> >> >>>>
>> >> >>>>  vtkMyDerivedProp();
>> >> >>>>  ~vtkMyDerivedProp();
>> >> >>>>
>> >> >>>> private:
>> >> >>>>
>> >> >>>>  vtkMyDerivedProp(const vtkMyDerivedProp&);  // Not implemented.
>> >> >>>>  void
>> >> >>>> operator=(const vtkMyDerivedProp&);  // Not implemented.
>> >> >>>>
>> >> >>>> };
>> >> >>>>
>> >> >>>> #endif
>> >> >>>>
>> >> >>>> ---------------- vtkMyDerivedProp.cxx -------------------------
>> >> >>>>
>> >> >>>> #include "vtkMyDerivedProp.h"
>> >> >>>>
>> >> >>>> #include "vtkObjectFactory.h"
>> >> >>>>
>> >> >>>> vtkCxxRevisionMacro(vtkMyDerivedProp, "$Revision: 1.36 $");
>> >> >>>>
>> >> >>>> vtkStandardNewMacro(vtkMyDerivedProp);
>> >> >>>>
>> >> >>>> vtkMyDerivedProp::vtkMyDerivedProp(){}
>> >> >>>>
>> >> >>>> vtkMyDerivedProp::~vtkMyDerivedProp(){}
>> >> >>>>
>> >> >>>> void vtkMyDerivedProp::PrintSelf(ostream& os, vtkIndent indent)
>> >> >>>> {
>> >> >>>>  this->Superclass::PrintSelf(os,indent);
>> >> >>>> }
>> >> >>>>
>> >> >>>> -------------------------------------- Errors
>> >> >>>> ------------------------------------------
>> >> >>>>
>> >> >>>> *I got 5 errors *
>> >> >>>>
>> >> >>>> 1>vtkMyDerivedProp.obj : error LNK2001: unresolved external symbol
>> >> >>>> "private: virtual char const * __thiscall
>> >> >>>> vtkMyDerivedProp::GetClassNameInternal(void)const "
>> >> >>>> (?GetClassNameInternal at vtkMyDerivedProp@@EBEPBDXZ)
>> >> >>>>
>> >> >>>> 1>vtkMyDerivedProp.obj : error LNK2001: unresolved external symbol
>> >> >>>> "public: virtual int __thiscall vtkMyDerivedProp::IsA(char const
>> >> >>>> *)"
>> >> >>>> (?IsA at vtkMyDerivedProp@@UAEHPBD at Z)
>> >> >>>>
>> >> >>>> 1>vtkMyDerivedProp.obj : error LNK2001: unresolved external symbol
>> >> >>>> "protected: virtual class vtkObjectBase * __thiscall
>> >> >>>> vtkMyDerivedProp::NewInstanceInternal(void)const "
>> >> >>>> (?NewInstanceInternal at vtkMyDerivedProp@@MBEPAVvtkObjectBase@@XZ)
>> >> >>>>
>> >> >>>> 1>vtkMyDerivedProp.obj : error LNK2019: unresolved external symbol
>> >> >>>> "__declspec(dllimport) const vtkMyDerivedProp::`vftable'"
>> >> >>>> (__imp_??_7vtkMyDerivedProp@@6B@) referenced in function
>> >> >>>> "protected:
>> >> >>>> __thiscall vtkMyDerivedProp::vtkMyDerivedProp(void)"
>> >> >>>> (??0vtkMyDerivedProp@@IAE at XZ)
>> >> >>>>
>> >> >>>> 1>C:\Documents and Settings\asahtari\Mes
>> >> >>>> documents\Projet\Bibillothéques\VTK\MyTest\MyLib.dll : fatal error
>> >> >>>> LNK1120:
>> >> >>>> 4 unresolved externals
>> >> >>>>
>> >> >>>> When I put vtkMyDerivedProp instead of vtkProp3D, it compiles
>> >> >>>> without
>> >> >>>> any error.
>> >> >>>> I don't understand .Is it a matter of VTK librairies ? Please
>> >> >>>> Help!
>> >> >>>>
>> >> >>>> Amine
>> >> >>>>
>> >> >>>> 2008/8/14 Utkarsh Ayachit <utkarsh.ayachit at kitware.com
>> >> >>>> <mailto:utkarsh.ayachit at kitware.com>>
>> >> >>>>
>> >> >>>>    Please keep the questions to the mailing list, so that others
>> >> >>>> can
>> >> >>>>    benefit/contribute as well.
>> >> >>>>
>> >> >>>>    To add New():
>> >> >>>>    * take a look at any concrete class in VTK eg. vtkCollection
>> >> >>>> (the
>> >> >>>>    New is
>> >> >>>>     declared in the header and defined using
>> >> >>>>    vtkStandardNewMacro(vtkCollection); in the cxx.
>> >> >>>>
>> >> >>>>    * not using the viewport in the RenderOpaqueGeometry should not
>> >> >>>> be
>> >> >>>> a
>> >> >>>>    problem. It's only provided if needed.
>> >> >>>>
>> >> >>>>    Utkarsh
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>    Mohammed Amine SAHTARI wrote:
>> >> >>>>
>> >> >>>>        Thank you very much Utkarsh.
>> >> >>>>
>> >> >>>>        I am tring to implement your solution but I have some
>> >> >>>> problems.
>> >> >>>>
>> >> >>>>        1) I create vtkMyDerivedProp.h and vtkMyDerivedProp.cxx
>> >> >>>>
>> >> >>>>         I subclass vtkProp :
>> >> >>>>              - I copy the class code of vtkProp3D (.h and .c
>> >> >>>> files)
>> >> >>>>              - I replace all the words :
>> >> >>>>                      vtkProp3D /by/ /vtkMyDerivedProp /and Prop3D
>> >> >>>> by
>> >> >>>>        /MyDerivedProp/
>> >> >>>>              - I include /"vtkGl.h"/ in vtkMyDerivedProp.h
>> >> >>>>              - I add RenderOpaqueGeometry() in vtkMyDerivedProp.h
>> >> >>>>        like this :
>> >> >>>>                      /virtual int
>> >> >>>> RenderOpaqueGeometry(vtkViewPort* )
>> >> >>>>                      {/
>> >> >>>>
>> >> >>>>        /             glBegin (GL_LINES);
>> >> >>>>
>> >> >>>>                    glVertex2f (-2.5, 2.5);
>> >> >>>>
>> >> >>>>                    glVertex2f (2.5, -2.5);
>> >> >>>>
>> >> >>>>
>> >> >>>>                    glEnd ();/
>> >> >>>>
>> >> >>>>        /               }/
>> >> >>>>
>> >> >>>>        2) In my program :           - I include and instantiate
>> >> >>>> vtkMyDerivedProp :
>> >> >>>>
>> >> >>>>           /  //# include "vtkMyDerivedProp.h"
>> >> >>>>             vtkMyDerivedProp *MyDerivedProp;/
>> >> >>>>
>> >> >>>>        -         I use  vtkMyDerivedProp :
>> >> >>>>
>> >> >>>>        /     vtkRenderer  *renderer = vtkRenderer  ::New();/
>> >> >>>>
>> >> >>>>        /      vtkMyDerivedProp-> RenderOpaqueGeometry(renderer);/
>> >> >>>>
>> >> >>>>        /      renderer->AddProp(vtkMyDerivedProp);/
>> >> >>>>
>> >> >>>>
>> >> >>>>        *Problem *: vtkMyDerivedProp is used without been defined!
>> >> >>>>
>> >> >>>>        *Question 1 :* How can I define it ?
>> >> >>>>  (vtkMyDerivedProp::New()  doesn't work)
>> >> >>>>
>> >> >>>>        *Question 2 :*  RenderOpaqueGeometry has vtkViewPort* in
>> >> >>>> input
>> >> >>>>        but doesn't use it. Is it a problem ?
>> >> >>>>
>> >> >>>>        How can I fix this?
>> >> >>>>
>> >> >>>>        Looking forward to hear from you soon,
>> >> >>>>
>> >> >>>>        Amine**
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>        2008/8/14 Utkarsh Ayachit <utkarsh.ayachit at kitware.com
>> >> >>>>        <mailto:utkarsh.ayachit at kitware.com>
>> >> >>>>        <mailto:utkarsh.ayachit at kitware.com
>> >> >>>>        <mailto:utkarsh.ayachit at kitware.com>>>
>> >> >>>>
>> >> >>>>           iren->Start() results in repeated calls to
>> >> >>>> renWin->Render()
>> >> >>>> on
>> >> >>>>           interaction. This will clear whatever you had drawn. A
>> >> >>>> better
>> >> >>>>           approach is to subclass vtkProp(or one of it's
>> >> >>>> subclasses)
>> >> >>>>        and put
>> >> >>>>           your rendering code in RenderOpaqueGeometry() /
>> >> >>>>           RenderTranslucentPolygonalGeometry()/ RenderOverlay()
>> >> >>>> etc.
>> >> >>>>        depending
>> >> >>>>           upon what pass you want it to be rendered and then add
>> >> >>>> the
>> >> >>>>        prop to
>> >> >>>>           the renderer. That way every time the renderer
>> >> >>>> re-renders,
>> >> >>>>        your code
>> >> >>>>           will be executed.
>> >> >>>>
>> >> >>>>
>> >> >>>>           Utkarsh
>> >> >>>>
>> >> >>>>           Mohammed Amine SAHTARI wrote:
>> >> >>>>
>> >> >>>>
>> >> >>>>               I want to add an OpenGl code in an application of
>> >> >>>> VTK.
>> >> >>>>
>> >> >>>>               For this purpose, I try to draw lines using commands
>> >> >>>>        OpenGL.:
>> >> >>>>
>> >> >>>>               *1) I add this on the top of the program :*
>> >> >>>>
>> >> >>>>               #include <GL/gl.h>
>> >> >>>>               *2) I place my OpenGL commands after
>> >> >>>> renWin->Render()
>> >> >>>>        but before
>> >> >>>>               iren->Start()** :  *
>> >> >>>>
>> >> >>>>
>> >> >>>>               renWin->Render();
>> >> >>>>
>> >> >>>>                  glBegin (GL_LINES);
>> >> >>>>                     glVertex2f (-2.5, 2.5);
>> >> >>>>                     glVertex2f (2.5, -2.5);
>> >> >>>>                   glEnd ();
>> >> >>>>
>> >> >>>>               iren->Start();
>> >> >>>>
>> >> >>>>
>> >> >>>>               *But it doesn't appears.*
>> >> >>>>
>> >> >>>>               did I miss something ? How can I do this work ?
>> >> >>>>               Looking forward to hear from you soon,
>> >> >>>>
>> >> >>>>               Amine
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>> ------------------------------------------------------------------------
>> >> >>>>
>> >> >>>>               _______________________________________________
>> >> >>>>               This is the private VTK discussion list.
>> >> >>>>               Please keep messages on-topic. Check the FAQ at:
>> >> >>>>               http://www.vtk.org/Wiki/VTK_FAQ
>> >> >>>>               Follow this link to subscribe/unsubscribe:
>> >> >>>>               http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>    _______________________________________________
>> >> >>>>    This is the private VTK discussion list.
>> >> >>>>    Please keep messages on-topic. Check the FAQ at:
>> >> >>>>    http://www.vtk.org/Wiki/VTK_FAQ
>> >> >>>>    Follow this link to subscribe/unsubscribe:
>> >> >>>>    http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>> ------------------------------------------------------------------------
>> >> >>>>
>> >> >>>> _______________________________________________
>> >> >>>> This is the private VTK discussion list.
>> >> >>>> Please keep messages on-topic. Check the FAQ at:
>> >> >>>> http://www.vtk.org/Wiki/VTK_FAQ
>> >> >>>> Follow this link to subscribe/unsubscribe:
>> >> >>>> http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >>>>
>> >> >>>
>> >> >>> --
>> >> >>> Amy Squillacote                    Phone: (256) 726-4839
>> >> >>> Computer Scientist                 Fax: (256) 726-4806
>> >> >>> CFD Research Corporation           Web: http://www.cfdrc.com
>> >> >>> 215 Wynn Drive, Suite 501
>> >> >>> Huntsville, AL  35805
>> >> >>>
>> >> >>>
>> >> >>
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > This is the private VTK discussion list.
>> >> > Please keep messages on-topic. Check the FAQ at:
>> >> > http://www.vtk.org/Wiki/VTK_FAQ
>> >> > Follow this link to subscribe/unsubscribe:
>> >> > http://www.vtk.org/mailman/listinfo/vtkusers
>> >> >
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> François Bertel, PhD | Kitware Inc. Suite 204
>> >> 1 (518) 371 3971 x113 | 28 Corporate Drive
>> >>  | Clifton Park NY 12065, USA
>> >> _______________________________________________
>> >> This is the private VTK discussion list.
>> >> Please keep messages on-topic. Check the FAQ at:
>> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >> Follow this link to subscribe/unsubscribe:
>> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >
>> >
>>
>>
>>
>> --
>> François Bertel, PhD | Kitware Inc. Suite 204
>> 1 (518) 371 3971 x113 | 28 Corporate Drive
>> | Clifton Park NY 12065, USA
>> _______________________________________________
>> This is the private VTK discussion list.
>> Please keep messages on-topic. Check the FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



-- 
François Bertel, PhD | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
 | Clifton Park NY 12065, USA



More information about the vtkusers mailing list