.[ ČeskéHry.cz ].

Laboratoř ČeskýchHer.cz - PasteBin

Vložit nový kód

ČeskéHry.cz - KOMUNITA HERNÍCH VÝVOJÁŘŮ

  1. dfh dcvn cvndhjdfj dfsdfh
    2 hod
  2. djdh dfhdf
    2 hod
  3. dfh dfjhdfhdfh d
    2 hod
  4. FREE Ç.P LINK
    2 hod
  5. FREE Ç.P LINK
    2 hod
  6. FREE Ç.P LINK
    2 hod
  7. FREE Ç.P LINK
    2 hod
  8. FREE Ç.P LINK
    2 hod
  9. FREE Ç.P LINK
    2 hod
  10. FREE Ç.P LINK
    2 hod
Link: http://nopaste.ceske-hry.cz/subdom/nopaste863
Zaslal: Weny Sky
Jazyk: C++
Vloženo: 2.2.2008, 11:07
Stáhnout jako soubor
  1. #include "BAMWE.h"
  2. #include "BAMWE_log.h"
  3.  
  4. //-----------------------------------------------------------------------------
  5. // Name: BAMWE_sprite::BAMWE_sprite()
  6. // Desc: implicitni konstruktor
  7. //-----------------------------------------------------------------------------
  8. BAMWE_sprite::BAMWE_sprite()
  9. {
  10. texture = 0;
  11.  
  12. size_x = 0;
  13. size_y = 0;
  14. tile_x = 0;
  15. tile_y = 0;
  16.  
  17. is_color_scheme = false;
  18. num_of_color_scheme = 0;
  19. color_scheme = NULL;
  20. }
  21.  
  22. //-----------------------------------------------------------------------------
  23. // Name: BAMWE_sprite::~BAMWE_sprite()
  24. // Desc: implicitni destruktor
  25. //-----------------------------------------------------------------------------
  26. BAMWE_sprite::~BAMWE_sprite()
  27. {
  28. if(color_scheme != NULL)
  29. delete [] color_scheme;
  30. }
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Name: BAMWE_sprite::create(unsigned int tex, unsigned int x, unsigned short y, unsigned short tx, unsigned short ty, unsigned short colors, const BAMWE* engine)
  34. // Desc: vytvori a nastavi zakladni parametry spritu
  35. //-----------------------------------------------------------------------------
  36. bool BAMWE_sprite::create(unsigned int tex, unsigned int x, unsigned short y, unsigned short tx, unsigned short ty, unsigned short colors, const BAMWE* engine)
  37. {
  38. texture = tex;
  39.  
  40. size_x = x;
  41. size_y = y;
  42. tile_x = tx == 0 ? 1 : tx;
  43. tile_y = ty == 0 ? 1 : ty;
  44.  
  45. num_of_color_scheme = colors;
  46. is_color_scheme = colors > 0;
  47.  
  48. try
  49. {
  50. if(colors > 0)
  51. color_scheme = new unsigned int[colors];
  52. else
  53. color_scheme = NULL;
  54. }
  55. catch(...)
  56. {
  57. return false;
  58. }
  59.  
  60. if(!vertices.create(tile_x*tile_y*4, colors == 0))
  61. return false;
  62.  
  63. for(int u = 0; u < tile_x; u++)
  64. {
  65. for(int v = 0; v < tile_y; v++)
  66. {
  67. vertices.getVertices()[(v*tile_x + u)*4] = BAMWE_vertex(.0f, .0f, 0.0f);
  68. vertices.getVertices()[(v*tile_x + u)*4+1] = BAMWE_vertex((float)x, .0f, 0.0f);
  69. vertices.getVertices()[(v*tile_x + u)*4+2] = BAMWE_vertex((float)x, (float)y, 0.0f);
  70. vertices.getVertices()[(v*tile_x + u)*4+3] = BAMWE_vertex(.0f, (float)y, 0.0f);
  71.  
  72. vertices.getTextureCords()[(v*tile_x + u)*4] = BAMWE_texture_cord((u*x) / (float)engine->getTextureWidth(texture), (v*y) / (float)engine->getTextureHeight(texture));
  73. vertices.getTextureCords()[(v*tile_x + u)*4+1] = BAMWE_texture_cord(((u+1)*x) / (float)engine->getTextureWidth(texture), (v*y) / (float)engine->getTextureHeight(texture));
  74. vertices.getTextureCords()[(v*tile_x + u)*4+2] = BAMWE_texture_cord(((u+1)*x) / (float)engine->getTextureWidth(texture), ((v+1)*y) / (float)engine->getTextureHeight(texture));
  75. vertices.getTextureCords()[(v*tile_x + u)*4+3] = BAMWE_texture_cord((u*x) / (float)engine->getTextureWidth(texture), ((v+1)*y) / (float)engine->getTextureHeight(texture));
  76. }
  77. }
  78.  
  79. return true;
  80. }
  81.  
  82. //-----------------------------------------------------------------------------
  83. // Name: BAMWE_sprite::setColorScheme(unsigned int scheme, unsigned int color)
  84. // Desc: nastavi barvu urcite skupine vertexu
  85. //-----------------------------------------------------------------------------
  86. void BAMWE_sprite::setColorScheme(unsigned int scheme, unsigned int color)
  87. {
  88. for(int u = 0; u < tile_x; u++)
  89. {
  90. for(int v = 0; v < tile_y; v++)
  91. {
  92. // prekopirovani vrcholou
  93. vertices.getVertices()[(tile_x*tile_y*scheme + v*tile_x + u)*4] = vertices.getVertices()[(v*tile_x + u)*4];
  94. vertices.getVertices()[(tile_x*tile_y*scheme + v*tile_x + u)*4+1] = vertices.getVertices()[(v*tile_x + u)*4+1];
  95. vertices.getVertices()[(tile_x*tile_y*scheme + v*tile_x + u)*4+2] = vertices.getVertices()[(v*tile_x + u)*4+2];
  96. vertices.getVertices()[(tile_x*tile_y*scheme + v*tile_x + u)*4+3] = vertices.getVertices()[(v*tile_x + u)*4+3];
  97.  
  98. // prekopirovani mapovacich souradnic
  99. vertices.getTextureCords()[(tile_x*tile_y*scheme + v*tile_x + u)*4] = vertices.getTextureCords()[(v*tile_x + u)*4];
  100. vertices.getTextureCords()[(tile_x*tile_y*scheme + v*tile_x + u)*4+1] = vertices.getTextureCords()[(v*tile_x + u)*4+1];
  101. vertices.getTextureCords()[(tile_x*tile_y*scheme + v*tile_x + u)*4+2] = vertices.getTextureCords()[(v*tile_x + u)*4+2];
  102. vertices.getTextureCords()[(tile_x*tile_y*scheme + v*tile_x + u)*4+3] = vertices.getTextureCords()[(v*tile_x + u)*4+3];
  103.  
  104. // namapovani barev na vrcholy
  105. vertices.getColors()[(tile_x*tile_y*scheme + v*tile_x + u)*4] =
  106. vertices.getColors()[(tile_x*tile_y*scheme + v*tile_x + u)*4+1] =
  107. vertices.getColors()[(tile_x*tile_y*scheme + v*tile_x + u)*4+2] =
  108. vertices.getColors()[(tile_x*tile_y*scheme + v*tile_x + u)*4+3] = BAMWE_texture_color(((color >> 8) & 0xFF) / 256.0f , ((color >> 16) & 0xFF) / 256.0f, (color & 0xFF) / 256.0f, ((color >> 24) & 0xFF) / 256.0f);
  109. }
  110. }
  111. }
  112.  
  113. //-----------------------------------------------------------------------------
  114. // Name: BAMWE_sprite::createVBO()
  115. // Desc: prekopiruje vertexy primo do pameti graficke karty
  116. //-----------------------------------------------------------------------------
  117. void BAMWE_sprite::createVBO()
  118. {
  119. vertices.createVBO();
  120. }
  121.  
  122. //-----------------------------------------------------------------------------
  123. // Name: BAMWE_sprite::render(float x, float y, float z, unsigned short tx, unsigned short ty, unsigned short scheme, const BAMWE* engine)
  124. // Desc: vykresli sprite
  125. //-----------------------------------------------------------------------------
  126. void BAMWE_sprite::render(float x, float y, float z, unsigned short tx, unsigned short ty, unsigned short scheme, const BAMWE* engine)
  127. {
  128. if(scheme > num_of_color_scheme || tx > tile_x || ty > tile_y)
  129. {
  130. #ifdef _DEBUG
  131. log(__FILE__, __LINE__, "Bad render parameters: color_scheme(%d)[max:%d] tile_x(%d)[max:%d] tile_y(%d)[max:%d]", scheme, num_of_color_scheme, tx, tile_x, ty, tile_y);
  132. #endif
  133. return;
  134. }
  135.  
  136. glPushMatrix(); log_error();
  137.  
  138. glLoadIdentity(); log_error();
  139. glTranslatef((float)x, (float)y, (float)z); log_error();
  140.  
  141. glEnable(GL_TEXTURE_2D); log_error();
  142. glBindTexture( GL_TEXTURE_2D, engine->getTexture(texture) ); log_error();
  143. vertices.bindBuffer(); log_error();
  144.  
  145. if(num_of_color_scheme > 0)
  146. glEnableClientState(GL_COLOR_ARRAY); log_error();
  147. glDrawArrays(GL_QUADS, (tile_x*tile_y*scheme + tile_x*ty + tx)*4, 4); log_error();
  148. if(num_of_color_scheme > 0)
  149. glDisableClientState(GL_COLOR_ARRAY); log_error();
  150.  
  151. glPopMatrix(); log_error();
  152. }
  153.