GraphingTexture.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef GRAPHING_TEXTURE_H
  2. #define GRAPHING_TEXTURE_H
  3. #include "LinearMath/btAlignedObjectArray.h"
  4. struct GraphingTexture
  5. {
  6. int m_textureId;
  7. //assume rgba (8 bit per component, total of 32bit per pixel, for m_width*m_height pixels)
  8. btAlignedObjectArray<unsigned char> m_imageData;
  9. int m_width;
  10. int m_height;
  11. GraphingTexture();
  12. virtual ~GraphingTexture();
  13. bool create(int texWidth, int texHeight);
  14. void destroy();
  15. void setPixel(int x, int y, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
  16. {
  17. if (y>=0 && y<m_height && x>=0 && x<m_width)
  18. {
  19. m_imageData[x*4+y*4*m_width+0] = red;
  20. m_imageData[x*4+y*4*m_width+1] = green;
  21. m_imageData[x*4+y*4*m_width+2] = blue;
  22. m_imageData[x*4+y*4*m_width+3] = alpha;
  23. }
  24. }
  25. void getPixel(int x, int y, unsigned char& red, unsigned char& green, unsigned char& blue, unsigned char& alpha)
  26. {
  27. red = m_imageData[x*4+y*4*m_width+0];
  28. green = m_imageData[x*4+y*4*m_width+1];
  29. blue = m_imageData[x*4+y*4*m_width+2];
  30. alpha = m_imageData[x*4+y*4*m_width+3];
  31. }
  32. void uploadImageData();
  33. int getTextureId()
  34. {
  35. return m_textureId;
  36. }
  37. };
  38. #endif //GRAPHING_TEXTURE_H