Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

texturegl.H

Go to the documentation of this file.
00001 /**********************************************************************
00002  * texturegl.H
00003  **********************************************************************/
00004 #ifndef __TEXTUREGL_H
00005 #define __TEXTUREGL_H
00006 
00007 #include "std/support.H"
00008 #include "glew/glew.H" // must come first
00009 
00010 #include "texture.H"
00011 #include "disp/view.H"
00012 
00013 /**********************************************************************
00014  * TEXTUREgl:
00015  **********************************************************************/
00016 MAKE_PTR_SUBC(TEXTUREgl, TEXTURE);
00017 typedef const TEXTUREglptr CTEXTUREglptr;
00018 class TEXTUREgl : public TEXTURE {
00019  public:
00020    TEXTUREgl(Cstr_ptr& file="", GLenum target=GL_TEXTURE_2D);
00021    TEXTUREgl(CBBOX2D& bb, CVIEWptr &v);
00022    TEXTUREgl(GLenum target, GLenum unit = GL_TEXTURE0);
00023 
00024 
00025    virtual ~TEXTUREgl() { free_dl(); }
00026 
00027    mlib::Point2i  get_size()        const { return _img.dims(); }
00028 
00029    virtual int  load_image();
00030    virtual int  set_image(unsigned char *data, int w, int h, uint bpp=3);
00031 
00032    // delete current texture (if any) and store the given filename
00033    // as the texture file to load next time we need the data:
00034    void set_texture(Cstr_ptr& filename);
00035 
00036    GLuint     get_tex_id()      const   { return _dl; }   
00037    bool       is_valid()        const   { return _dl_valid; }
00038 
00039    virtual bool load_texture(unsigned char **copy = 0);
00040 
00041    // Activates the texture and calls glEnable() to enable texturing.
00042    // NOTE: this should be called between glPushAttrib(GL_ENABLE_BIT)
00043    // and glPopAttrib()
00044    virtual void apply_texture(const mlib::Wtransf *xf = 0);
00045         
00046    void copy_texture(CBBOX2D &bb, CVIEWptr &v);
00047 
00048    void   set_format(GLenum format) { _format = format; }
00049    GLenum format    () const        { return _format; }
00050 
00051    void   set_tex_unit(GLenum unit)             { _tex_unit = unit; }
00052    GLenum get_tex_unit()                const   { return _tex_unit; }
00053 
00054    void    set_tex_fn(GLint   fn)    { _tex_fn = fn; }
00055    GLint   tex_fn    () const        { return _tex_fn; }
00056    
00057    void    set_wrap_r(GLint wrapr)   { _wrap_s = wrapr;}
00058    GLint   wrap_r    () const        { return _wrap_r;}
00059    void    set_wrap_s(GLint wraps)   { _wrap_s = wraps;}
00060    GLint   wrap_s    () const        { return _wrap_s;}
00061    void    set_wrap_t(GLint wrapt)   { _wrap_t = wrapt;}
00062    GLint   wrap_t    () const        { return _wrap_t;}
00063 
00064    void    set_min_filter(GLint minfilt) { _min_filter = minfilt;}
00065    void    set_max_filter(GLint maxfilt) { _max_filter = maxfilt;}
00066 
00067    bool    mipmap    () const        { return _mipmap;}
00068    void    set_mipmap(bool mipmap);
00069 
00070    void    set_save_img(bool b = 1) { _save_img = b; }
00071    const   GLenum  target() const {return _target; }
00072    
00073    void declare_texture();
00074  
00075 protected:
00076    GLuint       _dl;        // texture object (was display list in OGL 1.1)
00077    bool         _dl_valid;  // _dl is valid
00078    GLenum       _format;    // GL_RGB, GL_RGBA, etc.
00079    GLenum       _tex_unit;  // GL_TEXTURE0 by default
00080    bool         _save_img;  // whether to free image data after loading
00081    bool         _mipmap;    // Mipmap or not
00082    GLint        _min_filter;
00083    GLint        _max_filter;
00084    GLint        _wrap_r;
00085    GLint        _wrap_s;
00086    GLint        _wrap_t;
00087    GLint        _tex_fn;    // texture function (GL_DECAL etc.)
00088    const GLenum _target;    // GL_TEXTURE_2D or GL_TEXTURE_3D
00089 
00090    GLenum bpp_to_format() const {
00091       return ((_img.bpp()==4) ? GL_RGBA :
00092               (_img.bpp()==3) ? GL_RGB  :
00093               (_img.bpp()==2) ? GL_LUMINANCE_ALPHA :
00094               GL_LUMINANCE
00095          );
00096    }
00097 
00098    void free_dl();
00099 
00100    // allocate texture object:
00101 
00102 
00103    void init_settings();
00104 };
00105 
00106 #endif // __TEXTUREGL_H
00107 
00108 // end of file texturegl.H

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4