GLPrimitiveRenderer.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. #ifndef NO_OPENGL3
  2. #include "GLPrimitiveRenderer.h"
  3. #include "GLPrimInternalData.h"
  4. #include "Bullet3Common/b3Scalar.h"
  5. #include "LoadShader.h"
  6. static const char *vertexShader3D =
  7. "#version 150 \n"
  8. "\n"
  9. "uniform mat4 viewMatrix, projMatrix;\n"
  10. "in vec4 position;\n"
  11. "in vec4 colour;\n"
  12. "out vec4 colourV;\n"
  13. "\n"
  14. "in vec2 texuv;\n"
  15. "out vec2 texuvV;\n"
  16. "\n"
  17. "\n"
  18. "void main (void)\n"
  19. "{\n"
  20. " colourV = colour;\n"
  21. " gl_Position = projMatrix * viewMatrix * position ;\n"
  22. " texuvV=texuv;\n"
  23. "}\n";
  24. static const char *fragmentShader3D =
  25. "#version 150\n"
  26. "\n"
  27. "uniform vec2 p;\n"
  28. "in vec4 colourV;\n"
  29. "out vec4 fragColour;\n"
  30. "in vec2 texuvV;\n"
  31. "\n"
  32. "uniform sampler2D Diffuse;\n"
  33. "\n"
  34. "void main(void)\n"
  35. "{\n"
  36. " vec4 texcolor = texture(Diffuse,texuvV);\n"
  37. " if (p.x==0.f)\n"
  38. " {\n"
  39. " texcolor = vec4(1,1,1,texcolor.x);\n"
  40. " }\n"
  41. " fragColour = colourV*texcolor;\n"
  42. "}\n";
  43. static unsigned int s_indexData[6] = {0, 1, 2, 0, 2, 3};
  44. #define MAX_VERTICES2 8192
  45. struct PrimInternalData2
  46. {
  47. PrimInternalData2()
  48. : m_numVerticesText(0),
  49. m_numVerticesRect(0)
  50. {
  51. }
  52. int m_numVerticesText;
  53. int m_numVerticesRect;
  54. PrimVertex m_verticesText[MAX_VERTICES2];
  55. PrimVertex m_verticesRect[MAX_VERTICES2];
  56. };
  57. GLPrimitiveRenderer::GLPrimitiveRenderer(int screenWidth, int screenHeight)
  58. : m_screenWidth(screenWidth),
  59. m_screenHeight(screenHeight)
  60. {
  61. m_data = new PrimInternalData;
  62. m_data2 = new PrimInternalData2;
  63. m_data->m_shaderProg = gltLoadShaderPair(vertexShader3D, fragmentShader3D);
  64. m_data->m_viewmatUniform = glGetUniformLocation(m_data->m_shaderProg, "viewMatrix");
  65. if (m_data->m_viewmatUniform < 0)
  66. {
  67. b3Assert(0);
  68. }
  69. m_data->m_projMatUniform = glGetUniformLocation(m_data->m_shaderProg, "projMatrix");
  70. if (m_data->m_projMatUniform < 0)
  71. {
  72. b3Assert(0);
  73. }
  74. m_data->m_positionUniform = glGetUniformLocation(m_data->m_shaderProg, "p");
  75. if (m_data->m_positionUniform < 0)
  76. {
  77. b3Assert(0);
  78. }
  79. m_data->m_colourAttribute = glGetAttribLocation(m_data->m_shaderProg, "colour");
  80. if (m_data->m_colourAttribute < 0)
  81. {
  82. b3Assert(0);
  83. }
  84. m_data->m_positionAttribute = glGetAttribLocation(m_data->m_shaderProg, "position");
  85. if (m_data->m_positionAttribute < 0)
  86. {
  87. b3Assert(0);
  88. }
  89. m_data->m_textureAttribute = glGetAttribLocation(m_data->m_shaderProg, "texuv");
  90. if (m_data->m_textureAttribute < 0)
  91. {
  92. b3Assert(0);
  93. }
  94. loadBufferData();
  95. }
  96. void GLPrimitiveRenderer::loadBufferData()
  97. {
  98. PrimVertex vertexData[4] = {
  99. PrimVertex(PrimVec4(-1, -1, 0.0, 1.0), PrimVec4(1.0, 0.0, 0.0, 1.0), PrimVec2(0, 0)),
  100. PrimVertex(PrimVec4(-1, 1, 0.0, 1.0), PrimVec4(0.0, 1.0, 0.0, 1.0), PrimVec2(0, 1)),
  101. PrimVertex(PrimVec4(1, 1, 0.0, 1.0), PrimVec4(0.0, 0.0, 1.0, 1.0), PrimVec2(1, 1)),
  102. PrimVertex(PrimVec4(1, -1, 0.0, 1.0), PrimVec4(1.0, 1.0, 1.0, 1.0), PrimVec2(1, 0))};
  103. glGenVertexArrays(1, &m_data->m_vertexArrayObject);
  104. glBindVertexArray(m_data->m_vertexArrayObject);
  105. glGenBuffers(1, &m_data->m_vertexBuffer);
  106. glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
  107. glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(PrimVertex), vertexData, GL_DYNAMIC_DRAW);
  108. glGenVertexArrays(1, &m_data->m_vertexArrayObject2);
  109. glBindVertexArray(m_data->m_vertexArrayObject2);
  110. glGenBuffers(1, &m_data->m_vertexBuffer2);
  111. glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer2);
  112. glBufferData(GL_ARRAY_BUFFER, MAX_VERTICES2 * sizeof(PrimVertex), 0, GL_DYNAMIC_DRAW);
  113. b3Assert(glGetError() == GL_NO_ERROR);
  114. glGenBuffers(1, &m_data->m_indexBuffer);
  115. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer);
  116. glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(int), s_indexData, GL_STATIC_DRAW);
  117. unsigned int indexData[MAX_VERTICES2 * 2];
  118. int count = 0;
  119. for (int i = 0; i < MAX_VERTICES2; i += 4)
  120. {
  121. indexData[count++] = i;
  122. indexData[count++] = i + 1;
  123. indexData[count++] = i + 2;
  124. indexData[count++] = i;
  125. indexData[count++] = i + 2;
  126. indexData[count++] = i + 3;
  127. }
  128. glGenBuffers(1, &m_data->m_indexBuffer2);
  129. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer2);
  130. glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(int), indexData, GL_STATIC_DRAW);
  131. glEnableVertexAttribArray(m_data->m_positionAttribute);
  132. glEnableVertexAttribArray(m_data->m_colourAttribute);
  133. b3Assert(glGetError() == GL_NO_ERROR);
  134. glEnableVertexAttribArray(m_data->m_textureAttribute);
  135. glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0);
  136. glVertexAttribPointer(m_data->m_colourAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4));
  137. glVertexAttribPointer(m_data->m_textureAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4) + sizeof(PrimVec4)));
  138. b3Assert(glGetError() == GL_NO_ERROR);
  139. glActiveTexture(GL_TEXTURE0);
  140. GLubyte *image = new GLubyte[256 * 256 * 3];
  141. for (int y = 0; y < 256; ++y)
  142. {
  143. // const int t=y>>5;
  144. GLubyte *pi = image + y * 256 * 3;
  145. for (int x = 0; x < 256; ++x)
  146. {
  147. if (x < y) //x<2||y<2||x>253||y>253)
  148. {
  149. pi[0] = 255;
  150. pi[1] = 0;
  151. pi[2] = 0;
  152. }
  153. else
  154. {
  155. pi[0] = 255;
  156. pi[1] = 255;
  157. pi[2] = 255;
  158. }
  159. pi += 3;
  160. }
  161. }
  162. glGenTextures(1, (GLuint *)&m_data->m_texturehandle);
  163. glBindTexture(GL_TEXTURE_2D, m_data->m_texturehandle);
  164. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
  165. glGenerateMipmap(GL_TEXTURE_2D);
  166. b3Assert(glGetError() == GL_NO_ERROR);
  167. delete[] image;
  168. }
  169. GLPrimitiveRenderer::~GLPrimitiveRenderer()
  170. {
  171. glBindTexture(GL_TEXTURE_2D, 0);
  172. glUseProgram(0);
  173. glBindTexture(GL_TEXTURE_2D, 0);
  174. glDeleteProgram(m_data->m_shaderProg);
  175. delete m_data;
  176. delete m_data2;
  177. }
  178. void GLPrimitiveRenderer::drawLine()
  179. {
  180. }
  181. void GLPrimitiveRenderer::drawRect(float x0, float y0, float x1, float y1, float color[4])
  182. {
  183. b3Assert(glGetError() == GL_NO_ERROR);
  184. glActiveTexture(GL_TEXTURE0);
  185. b3Assert(glGetError() == GL_NO_ERROR);
  186. glBindTexture(GL_TEXTURE_2D, m_data->m_texturehandle);
  187. b3Assert(glGetError() == GL_NO_ERROR);
  188. drawTexturedRect(x0, y0, x1, y1, color, 0, 0, 1, 1);
  189. b3Assert(glGetError() == GL_NO_ERROR);
  190. }
  191. void GLPrimitiveRenderer::drawTexturedRect3D(const PrimVertex &v0, const PrimVertex &v1, const PrimVertex &v2, const PrimVertex &v3, float viewMat[16], float projMat[16], bool useRGBA)
  192. {
  193. //B3_PROFILE("GLPrimitiveRenderer::drawTexturedRect3D");
  194. b3Assert(glGetError() == GL_NO_ERROR);
  195. glUseProgram(m_data->m_shaderProg);
  196. glUniformMatrix4fv(m_data->m_viewmatUniform, 1, false, viewMat);
  197. glUniformMatrix4fv(m_data->m_projMatUniform, 1, false, projMat);
  198. b3Assert(glGetError() == GL_NO_ERROR);
  199. glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
  200. glBindVertexArray(m_data->m_vertexArrayObject);
  201. bool useFiltering = false;
  202. if (useFiltering)
  203. {
  204. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  205. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  206. }
  207. else
  208. {
  209. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  210. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  211. }
  212. PrimVertex vertexData[4] = {
  213. v0, v1, v2, v3};
  214. glBufferSubData(GL_ARRAY_BUFFER, 0, 4 * sizeof(PrimVertex), vertexData);
  215. b3Assert(glGetError() == GL_NO_ERROR);
  216. PrimVec2 p(0.f, 0.f); //?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) );
  217. if (useRGBA)
  218. {
  219. p.p[0] = 1.f;
  220. p.p[1] = 1.f;
  221. }
  222. glUniform2fv(m_data->m_positionUniform, 1, (const GLfloat *)&p);
  223. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  224. b3Assert(glGetError() == GL_NO_ERROR);
  225. glEnableVertexAttribArray(m_data->m_positionAttribute);
  226. b3Assert(glGetError() == GL_NO_ERROR);
  227. glEnableVertexAttribArray(m_data->m_colourAttribute);
  228. b3Assert(glGetError() == GL_NO_ERROR);
  229. glEnableVertexAttribArray(m_data->m_textureAttribute);
  230. glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0);
  231. glVertexAttribPointer(m_data->m_colourAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4));
  232. glVertexAttribPointer(m_data->m_textureAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4) + sizeof(PrimVec4)));
  233. b3Assert(glGetError() == GL_NO_ERROR);
  234. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer);
  235. //glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  236. int indexCount = 6;
  237. b3Assert(glGetError() == GL_NO_ERROR);
  238. glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
  239. b3Assert(glGetError() == GL_NO_ERROR);
  240. glBindVertexArray(0);
  241. b3Assert(glGetError() == GL_NO_ERROR);
  242. glBindBuffer(GL_ARRAY_BUFFER, 0);
  243. b3Assert(glGetError() == GL_NO_ERROR);
  244. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  245. b3Assert(glGetError() == GL_NO_ERROR);
  246. //glDisableVertexAttribArray(m_data->m_textureAttribute);
  247. b3Assert(glGetError() == GL_NO_ERROR);
  248. glUseProgram(0);
  249. b3Assert(glGetError() == GL_NO_ERROR);
  250. }
  251. void GLPrimitiveRenderer::drawTexturedRect3D2Text(bool useRGBA)
  252. {
  253. drawTexturedRect3D2(&m_data2->m_verticesText[0], m_data2->m_numVerticesText, useRGBA);
  254. m_data2->m_numVerticesText = 0;
  255. }
  256. void GLPrimitiveRenderer::drawTexturedRect3D2(PrimVertex *vertices, int numVertices, bool useRGBA)
  257. {
  258. //B3_PROFILE("drawTexturedRect3D2");
  259. if (numVertices == 0)
  260. {
  261. return;
  262. }
  263. //B3_PROFILE("GLPrimitiveRenderer::drawTexturedRect3D");
  264. b3Assert(glGetError() == GL_NO_ERROR);
  265. float identity[16] = {1, 0, 0, 0,
  266. 0, 1, 0, 0,
  267. 0, 0, 1, 0,
  268. 0, 0, 0, 1};
  269. glUseProgram(m_data->m_shaderProg);
  270. glUniformMatrix4fv(m_data->m_viewmatUniform, 1, false, identity);
  271. glUniformMatrix4fv(m_data->m_projMatUniform, 1, false, identity);
  272. b3Assert(glGetError() == GL_NO_ERROR);
  273. glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer2);
  274. glBindVertexArray(m_data->m_vertexArrayObject2);
  275. bool useFiltering = false;
  276. if (useFiltering)
  277. {
  278. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  279. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  280. }
  281. else
  282. {
  283. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  284. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  285. }
  286. /* PrimVertex vertexData[4] = {
  287. v0,v1,v2,v3
  288. };
  289. */
  290. glBufferSubData(GL_ARRAY_BUFFER, 0, numVertices * sizeof(PrimVertex), vertices);
  291. b3Assert(glGetError() == GL_NO_ERROR);
  292. PrimVec2 p(0.f, 0.f); //?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) );
  293. if (useRGBA)
  294. {
  295. p.p[0] = 1.f;
  296. p.p[1] = 1.f;
  297. }
  298. glUniform2fv(m_data->m_positionUniform, 1, (const GLfloat *)&p);
  299. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  300. b3Assert(glGetError() == GL_NO_ERROR);
  301. glEnableVertexAttribArray(m_data->m_positionAttribute);
  302. b3Assert(glGetError() == GL_NO_ERROR);
  303. glEnableVertexAttribArray(m_data->m_colourAttribute);
  304. b3Assert(glGetError() == GL_NO_ERROR);
  305. glEnableVertexAttribArray(m_data->m_textureAttribute);
  306. glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0);
  307. glVertexAttribPointer(m_data->m_colourAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4));
  308. glVertexAttribPointer(m_data->m_textureAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4) + sizeof(PrimVec4)));
  309. b3Assert(glGetError() == GL_NO_ERROR);
  310. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer2);
  311. //glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  312. int indexCount = (numVertices / 4) * 6;
  313. b3Assert(glGetError() == GL_NO_ERROR);
  314. glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
  315. b3Assert(glGetError() == GL_NO_ERROR);
  316. glBindVertexArray(0);
  317. b3Assert(glGetError() == GL_NO_ERROR);
  318. glBindBuffer(GL_ARRAY_BUFFER, 0);
  319. b3Assert(glGetError() == GL_NO_ERROR);
  320. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  321. b3Assert(glGetError() == GL_NO_ERROR);
  322. //glDisableVertexAttribArray(m_data->m_textureAttribute);
  323. b3Assert(glGetError() == GL_NO_ERROR);
  324. glUseProgram(0);
  325. b3Assert(glGetError() == GL_NO_ERROR);
  326. }
  327. void GLPrimitiveRenderer::drawTexturedRect2a(float x0, float y0, float x1, float y1, float color[4], float u0, float v0, float u1, float v1, int useRGBA)
  328. {
  329. PrimVertex vertexData[4] = {
  330. PrimVertex(PrimVec4(-1.f + 2.f * x0 / float(m_screenWidth), 1.f - 2.f * y0 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u0, v0)),
  331. PrimVertex(PrimVec4(-1.f + 2.f * x0 / float(m_screenWidth), 1.f - 2.f * y1 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u0, v1)),
  332. PrimVertex(PrimVec4(-1.f + 2.f * x1 / float(m_screenWidth), 1.f - 2.f * y1 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u1, v1)),
  333. PrimVertex(PrimVec4(-1.f + 2.f * x1 / float(m_screenWidth), 1.f - 2.f * y0 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u1, v0))};
  334. // int sz = m_data2->m_numVerticesText;
  335. m_data2->m_verticesRect[m_data2->m_numVerticesRect++] = vertexData[0];
  336. m_data2->m_verticesRect[m_data2->m_numVerticesRect++] = vertexData[1];
  337. m_data2->m_verticesRect[m_data2->m_numVerticesRect++] = vertexData[2];
  338. m_data2->m_verticesRect[m_data2->m_numVerticesRect++] = vertexData[3];
  339. if (m_data2->m_numVerticesRect >= MAX_VERTICES2)
  340. {
  341. flushBatchedRects();
  342. }
  343. }
  344. void GLPrimitiveRenderer::flushBatchedRects()
  345. {
  346. if (m_data2->m_numVerticesRect == 0)
  347. return;
  348. glActiveTexture(GL_TEXTURE0);
  349. b3Assert(glGetError() == GL_NO_ERROR);
  350. glBindTexture(GL_TEXTURE_2D, m_data->m_texturehandle);
  351. drawTexturedRect3D2(m_data2->m_verticesRect, m_data2->m_numVerticesRect, 0);
  352. m_data2->m_numVerticesRect = 0;
  353. }
  354. void GLPrimitiveRenderer::drawTexturedRect2(float x0, float y0, float x1, float y1, float color[4], float u0, float v0, float u1, float v1, int useRGBA)
  355. {
  356. PrimVertex vertexData[4] = {
  357. PrimVertex(PrimVec4(-1.f + 2.f * x0 / float(m_screenWidth), 1.f - 2.f * y0 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u0, v0)),
  358. PrimVertex(PrimVec4(-1.f + 2.f * x0 / float(m_screenWidth), 1.f - 2.f * y1 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u0, v1)),
  359. PrimVertex(PrimVec4(-1.f + 2.f * x1 / float(m_screenWidth), 1.f - 2.f * y1 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u1, v1)),
  360. PrimVertex(PrimVec4(-1.f + 2.f * x1 / float(m_screenWidth), 1.f - 2.f * y0 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u1, v0))};
  361. // int sz = m_data2->m_numVerticesText;
  362. m_data2->m_verticesText[m_data2->m_numVerticesText++] = vertexData[0];
  363. m_data2->m_verticesText[m_data2->m_numVerticesText++] = vertexData[1];
  364. m_data2->m_verticesText[m_data2->m_numVerticesText++] = vertexData[2];
  365. m_data2->m_verticesText[m_data2->m_numVerticesText++] = vertexData[3];
  366. if (m_data2->m_numVerticesText >= MAX_VERTICES2)
  367. {
  368. drawTexturedRect3D2(m_data2->m_verticesText, m_data2->m_numVerticesText, useRGBA);
  369. m_data2->m_numVerticesText = 0;
  370. }
  371. }
  372. void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0, float v0, float u1, float v1, int useRGBA)
  373. {
  374. float identity[16] = {1, 0, 0, 0,
  375. 0, 1, 0, 0,
  376. 0, 0, 1, 0,
  377. 0, 0, 0, 1};
  378. PrimVertex vertexData[4] = {
  379. PrimVertex(PrimVec4(-1.f + 2.f * x0 / float(m_screenWidth), 1.f - 2.f * y0 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u0, v0)),
  380. PrimVertex(PrimVec4(-1.f + 2.f * x0 / float(m_screenWidth), 1.f - 2.f * y1 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u0, v1)),
  381. PrimVertex(PrimVec4(-1.f + 2.f * x1 / float(m_screenWidth), 1.f - 2.f * y1 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u1, v1)),
  382. PrimVertex(PrimVec4(-1.f + 2.f * x1 / float(m_screenWidth), 1.f - 2.f * y0 / float(m_screenHeight), 0.f, 1.f), PrimVec4(color[0], color[1], color[2], color[3]), PrimVec2(u1, v0))};
  383. drawTexturedRect3D(vertexData[0], vertexData[1], vertexData[2], vertexData[3], identity, identity, useRGBA);
  384. }
  385. void GLPrimitiveRenderer::setScreenSize(int width, int height)
  386. {
  387. m_screenWidth = width;
  388. m_screenHeight = height;
  389. }
  390. #endif