GraphingTexture.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "GraphingTexture.h"
  2. #include "../OpenGLWindow/OpenGLInclude.h"
  3. #include <assert.h>
  4. GraphingTexture::GraphingTexture()
  5. :m_textureId(0),
  6. m_width(0),
  7. m_height(0)
  8. {
  9. }
  10. GraphingTexture::~GraphingTexture()
  11. {
  12. destroy();
  13. }
  14. void GraphingTexture::destroy()
  15. {
  16. //TODO(erwincoumans) release memory etc...
  17. m_width = 0;
  18. m_height=0;
  19. glDeleteTextures(1,(GLuint*)&m_textureId);
  20. m_textureId=0;
  21. }
  22. bool GraphingTexture::create(int texWidth, int texHeight)
  23. {
  24. m_width = texWidth;
  25. m_height = texHeight;
  26. glActiveTexture(GL_TEXTURE0);
  27. m_imageData.resize(texWidth*texHeight*4);
  28. for(int y=0;y<texHeight;++y)
  29. {
  30. // const int t=y>>5;
  31. GLubyte* pi=&m_imageData[y*texWidth*4];
  32. for(int x=0;x<texWidth;++x)
  33. {
  34. if (x>=y)//x<2||y<2||x>253||y>253)
  35. {
  36. pi[0]=0;
  37. pi[1]=0;
  38. pi[2]=255;
  39. pi[3]=255;
  40. } else
  41. {
  42. pi[0]=255;
  43. pi[1]=0;
  44. pi[2]=0;
  45. pi[3]=255;
  46. }
  47. pi+=4;
  48. }
  49. }
  50. glGenTextures(1,(GLuint*)&m_textureId);
  51. uploadImageData();
  52. return true;
  53. }
  54. void GraphingTexture::uploadImageData()
  55. {
  56. glBindTexture(GL_TEXTURE_2D,m_textureId);
  57. assert(glGetError()==GL_NO_ERROR);
  58. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width,m_height,0,GL_RGBA,GL_UNSIGNED_BYTE,&m_imageData[0]);
  59. glGenerateMipmap(GL_TEXTURE_2D);
  60. assert(glGetError()==GL_NO_ERROR);
  61. }