spoutReceive.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ////////////////////////////////////////////////////////
  2. //
  3. // GEM - Graphics Environment for Multimedia
  4. //
  5. // Implementation file
  6. //
  7. // Copyright (c) 2002-2011 IOhannes m zmölnig. forum::für::umläute. IEM. zmoelnig@iem.at
  8. // zmoelnig@iem.kug.ac.at
  9. // For information on usage and redistribution, and for a DISCLAIMER
  10. // * OF ALL WARRANTIES, see the file, "GEM.LICENSE.TERMS"
  11. //
  12. // this file has been generated...
  13. ////////////////////////////////////////////////////////
  14. #include "spoutReceive.h"
  15. CPPEXTERN_NEW_WITH_ONE_ARG(spoutReceive, t_symbol*,A_DEFSYM);
  16. /////////////////////////////////////////////////////////
  17. //
  18. // GEMglViewport
  19. //
  20. /////////////////////////////////////////////////////////
  21. // Constructor
  22. //
  23. spoutReceive :: spoutReceive (t_symbol* s)
  24. {
  25. w=512;
  26. h=512;
  27. texture=false;
  28. bInitialized = false;
  29. spoutreceiver = GetSpout(); // Create a Spout receiver object
  30. bMemoryMode = false;
  31. if (strlen(s->s_name)!=0){s2=s;texture=true;}
  32. m_outTexInfo = outlet_new(this->x_obj, 0);
  33. }
  34. /////////////////////////////////////////////////////////
  35. // Destructor
  36. //
  37. spoutReceive :: ~spoutReceive () {
  38. if(num != 0) glDeleteTextures(1, &num);
  39. spoutreceiver->ReleaseReceiver();
  40. delete spoutreceiver;
  41. spoutreceiver = NULL;
  42. }
  43. /////////////////////////////////////////////////////////
  44. // Render
  45. //
  46. void spoutReceive :: render(GemState *state) {
  47. unsigned int width=500, height=500;
  48. if(!bInitialized) {
  49. sym[0]=NULL;
  50. if(spoutreceiver->CreateReceiver(sym, width, height, false)) {
  51. //bMemoryMode = spoutreceiver->GetMemoryShareMode();
  52. w=width;
  53. h=height;
  54. //initTexture();
  55. bInitialized = true;
  56. if (texture)setMess(s2);
  57. return;
  58. }
  59. else {
  60. }
  61. }
  62. if(bInitialized) {
  63. //initTexture();
  64. spoutreceiver->DrawSharedTexture();
  65. }
  66. }
  67. void spoutReceive::initTexture()
  68. {
  69. if(num != 0) {
  70. glDeleteTextures(1, &num);
  71. num = 0;
  72. }
  73. glGenTextures(1, &num);
  74. glBindTexture(GL_TEXTURE_RECTANGLE, num);
  75. glTexParameterf(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  76. glTexParameterf(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  77. glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  78. glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  79. if(bMemoryMode)
  80. glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
  81. else
  82. glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA,w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  83. glBindTexture(GL_TEXTURE_RECTANGLE, 0);
  84. }
  85. /////////////////////////////////////////////////////////
  86. // Variables
  87. //
  88. void spoutReceive :: setMess(t_symbol*indexed) {
  89. int index, nSenders;
  90. char* SenderName;
  91. int MaxSize = 64;
  92. unsigned int width, height;
  93. HANDLE hShareHandle;
  94. DWORD dwFormat;
  95. //nSenders = spoutreceiver->GetSenderCount();
  96. SenderName=indexed->s_name;
  97. spoutreceiver->GetSenderInfo(SenderName,
  98. width, height,
  99. hShareHandle, dwFormat);
  100. strcpy(sym,SenderName);
  101. //spoutreceiver->SetActiveSender(sym);
  102. spoutreceiver->ReleaseReceiver();
  103. spoutreceiver->CreateReceiver(sym, width, height, false);
  104. //bMemoryMode = spoutreceiver->GetMemoryShareMode();
  105. w=width;
  106. h=height;
  107. //initTexture();
  108. bInitialized = true;
  109. }
  110. void spoutReceive :: infoMess()
  111. {
  112. post("spoutReceive v.1 by ArNO Courcelle, 01/2015 \n enjoy!");
  113. }
  114. /////////////////////////////////////////////////////////
  115. // static member functions
  116. //
  117. void spoutReceive :: obj_setupCallback(t_class *classPtr) {
  118. class_addmethod(classPtr, reinterpret_cast<t_method>(&spoutReceive::setMessCallback),
  119. gensym("set"), A_SYMBOL, A_NULL);
  120. class_addmethod(classPtr, reinterpret_cast<t_method>(&spoutReceive::info),
  121. gensym("info"), A_NULL);
  122. }
  123. void spoutReceive :: setMessCallback(void *data, t_symbol*indexed)
  124. {
  125. GetMyClass(data)->setMess(indexed);
  126. }
  127. void spoutReceive :: info (void* data)
  128. {
  129. GetMyClass(data)->infoMess();//post("spoutReceive v.1 by ArNO Courcelle, 01/2014 n/");
  130. }