TextureObj.h
上传用户:kellyonhid
上传日期:2013-10-12
资源大小:932k
文件大小:3k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. //############################################################
  2. // 
  3. // TextureObj.h
  4. //
  5. // Szymon Rusinkiewicz
  6. // Fri Mar 12 01:47:50 CET 1999
  7. //
  8. // Texture maps for scans.
  9. //
  10. //############################################################
  11. #ifndef _TEXTUREOBJ_H_
  12. #define _TEXTUREOBJ_H_
  13. #define DEFAULT_CAMERA_FILENAME "/usr/graphics/lib/plyshade/pastecolor/dmich.cameraparams"
  14. #define DEFAULT_CAMCALIBXF_FILENAME "/usr/graphics/lib/plyshade/pastecolor/dmich.cameracalib.xf"
  15. #ifdef sgi
  16. #define MAG_FILTER GL_LINEAR_SHARPEN_SGIS
  17. #else
  18. #define MAG_FILTER GL_LINEAR
  19. #endif
  20. #define MIN_FILTER GL_LINEAR_MIPMAP_LINEAR
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <GL/gl.h>
  24. #include "Xform.h"
  25. #include "RefCount.h"
  26. #include "cameraparams.h"
  27. class TextureObj : public RefCount {
  28. public:
  29. virtual void setupTexture() = 0;
  30. virtual ~TextureObj() {}
  31. };
  32. class GL_Bound_TextureObj : public TextureObj {
  33. private:
  34. GLuint textureobjnum;
  35. protected:
  36. void bind()
  37. {
  38. glBindTexture(GL_TEXTURE_2D, textureobjnum);
  39. }
  40. void unbind()
  41. {
  42. glBindTexture(GL_TEXTURE_2D, 0);
  43. }
  44. GL_Bound_TextureObj()
  45. {
  46. glGenTextures(1, &textureobjnum);
  47. bind();
  48. }
  49. public:
  50. virtual ~GL_Bound_TextureObj()
  51. {
  52. if (textureobjnum)
  53. glDeleteTextures(1, &textureobjnum);
  54. }
  55. };
  56. class ProjectiveTexture : public GL_Bound_TextureObj {
  57. private:
  58. Xform<float> *camcalibxf, *camxf, *alignxf; 
  59. float xscale, yscale;
  60. CameraParams *thecamera;
  61. protected:
  62. ProjectiveTexture(CameraParams *_cam,
  63.   Xform<float> *_camcalibxf = NULL,
  64.   Xform<float> *_camxf = NULL,
  65.   Xform<float> *_alignxf = NULL,
  66.   float _xscale = 1.0,
  67.   float _yscale = 1.0) :
  68. camcalibxf(_camcalibxf), camxf(_camxf), alignxf(_alignxf),
  69. thecamera(_cam), xscale(_xscale), yscale(_yscale)
  70. {}
  71. public:
  72. static Ref<ProjectiveTexture> loadImage(const char *filename,
  73. const char *camfilename = NULL,
  74. const char *camcalibxffilename = NULL,
  75. const char *camxffilename = NULL,
  76. const char *alignxffilename = NULL,
  77. const bool actuallyLoadImage = true,
  78. const bool use_mipmaps = true );
  79. virtual void setupTexture();
  80. virtual ~ProjectiveTexture()
  81. {
  82. delete thecamera;
  83. if (alignxf)  delete alignxf;
  84. if (camxf)  delete camxf;
  85. if (camcalibxf)  delete camcalibxf;
  86. }
  87. };
  88. class MeshAffixedProjectiveTexture : public TextureObj {
  89. private:
  90. Ref<ProjectiveTexture> theprojtexture;
  91. float meshtransform[16];
  92. MeshAffixedProjectiveTexture(Ref<ProjectiveTexture> _theprojtexture,
  93.      const float *_meshtransform) :
  94. theprojtexture(_theprojtexture)
  95. {
  96. memcpy(meshtransform, _meshtransform, 16*sizeof(float));
  97. }
  98. public:
  99. static Ref<TextureObj> AffixToMesh(Ref<ProjectiveTexture> projtex,
  100.    const float *transform)
  101. {
  102. return new MeshAffixedProjectiveTexture(projtex, transform);
  103. }
  104. virtual void setupTexture();
  105. };
  106. #endif