PVRTPrint3DAPI.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /******************************************************************************
  2. @File PVRTPrint3DAPI.cpp
  3. @Title OGLES2/PVRTPrint3DAPI
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Displays a text string using 3D polygons. Can be done in two ways:
  8. using a window defined by the user or writing straight on the
  9. screen.
  10. ******************************************************************************/
  11. /****************************************************************************
  12. ** Includes
  13. ****************************************************************************/
  14. #include <stdarg.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "PVRTContext.h"
  19. #include "PVRTFixedPoint.h"
  20. #include "PVRTMatrix.h"
  21. #include "PVRTTexture.h"
  22. #include "PVRTTextureAPI.h"
  23. #include "PVRTPrint3D.h"
  24. #include "PVRTString.h"
  25. #include "PVRTShader.h"
  26. #include "PVRTgles2Ext.h"
  27. #include "PVRTPrint3DShaders.h"
  28. /****************************************************************************
  29. ** Defines
  30. ****************************************************************************/
  31. #define VERTEX_ARRAY 0
  32. #define UV_ARRAY 1
  33. #define COLOR_ARRAY 2
  34. /****************************************************************************
  35. ** Structures
  36. ****************************************************************************/
  37. struct SPVRTPrint3DAPI
  38. {
  39. GLuint uTexture[5];
  40. GLuint uTexturePVRLogo;
  41. GLuint uTextureIMGLogo;
  42. GLuint m_VertexShaderObject, m_FragmentShaderObject;
  43. GLuint m_ProgramObject;
  44. /* Used to save the OpenGL state to restore them after drawing */
  45. GLboolean isCullFaceEnabled;
  46. GLboolean isBlendEnabled;
  47. GLboolean isDepthTestEnabled;
  48. GLint nArrayBufferBinding;
  49. };
  50. /****************************************************************************
  51. ** Class: CPVRTPrint3D
  52. ****************************************************************************/
  53. /*!***************************************************************************
  54. @Function ReleaseTextures
  55. @Description Deallocate the memory allocated in SetTextures(...)
  56. *****************************************************************************/
  57. void CPVRTPrint3D::ReleaseTextures()
  58. {
  59. #if !defined (DISABLE_PRINT3D)
  60. if(m_pAPI)
  61. {
  62. /* Release the shaders */
  63. glDeleteProgram(m_pAPI->m_ProgramObject);
  64. glDeleteShader(m_pAPI->m_VertexShaderObject);
  65. glDeleteShader(m_pAPI->m_FragmentShaderObject);
  66. }
  67. /* Only release textures if they've been allocated */
  68. if (!m_bTexturesSet) return;
  69. /* Release IndexBuffer */
  70. FREE(m_pwFacesFont);
  71. FREE(m_pPrint3dVtx);
  72. /* Delete textures */
  73. glDeleteTextures(5, m_pAPI->uTexture);
  74. glDeleteTextures(1, &m_pAPI->uTexturePVRLogo);
  75. glDeleteTextures(1, &m_pAPI->uTextureIMGLogo);
  76. m_bTexturesSet = false;
  77. FREE(m_pVtxCache);
  78. APIRelease();
  79. #endif
  80. }
  81. /*!***************************************************************************
  82. @Function Flush
  83. @Description Flushes all the print text commands
  84. *****************************************************************************/
  85. int CPVRTPrint3D::Flush()
  86. {
  87. #if !defined (DISABLE_PRINT3D)
  88. int nTris, nVtx, nVtxBase, nTrisTot;
  89. _ASSERT((m_nVtxCache % 4) == 0);
  90. _ASSERT(m_nVtxCache <= m_nVtxCacheMax);
  91. /* Save render states */
  92. APIRenderStates(0);
  93. /* Set font texture */
  94. glBindTexture(GL_TEXTURE_2D, m_pAPI->uTexture[0]);
  95. nTrisTot = m_nVtxCache >> 1;
  96. /*
  97. Render the text then. Might need several submissions.
  98. */
  99. nVtxBase = 0;
  100. while(m_nVtxCache)
  101. {
  102. nVtx = PVRT_MIN(m_nVtxCache, 0xFFFC);
  103. nTris = nVtx >> 1;
  104. _ASSERT(nTris <= (PVRTPRINT3D_MAX_RENDERABLE_LETTERS*2));
  105. _ASSERT((nVtx % 4) == 0);
  106. /* Draw triangles */
  107. glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(SPVRTPrint3DAPIVertex), (const void*)&m_pVtxCache[nVtxBase].sx);
  108. glVertexAttribPointer(COLOR_ARRAY, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(SPVRTPrint3DAPIVertex), (const void*)&m_pVtxCache[nVtxBase].color);
  109. glVertexAttribPointer(UV_ARRAY, 2, GL_FLOAT, GL_FALSE, sizeof(SPVRTPrint3DAPIVertex), (const void*)&m_pVtxCache[nVtxBase].tu);
  110. glDrawElements(GL_TRIANGLES, nTris * 3, GL_UNSIGNED_SHORT, m_pwFacesFont);
  111. if (glGetError())
  112. {
  113. _RPT0(_CRT_WARN,"glDrawElements(GL_TRIANGLES, (VertexCount/2)*3, GL_UNSIGNED_SHORT, m_pFacesFont); failed\n");
  114. }
  115. nVtxBase += nVtx;
  116. m_nVtxCache -= nVtx;
  117. }
  118. /* Draw a logo if requested */
  119. #if defined(FORCE_NO_LOGO)
  120. /* Do nothing */
  121. #elif defined(FORCE_PVR_LOGO)
  122. APIDrawLogo(ePVRTPrint3DLogoPVR, 1); /* PVR to the right */
  123. #elif defined(FORCE_IMG_LOGO)
  124. APIDrawLogo(ePVRTPrint3DLogoIMG, 1); /* IMG to the right */
  125. #elif defined(FORCE_ALL_LOGOS)
  126. APIDrawLogo(ePVRTPrint3DLogoIMG, -1); /* IMG to the left */
  127. APIDrawLogo(ePVRTPrint3DLogoPVR, 1); /* PVR to the right */
  128. #else
  129. /* User selected logos */
  130. switch (m_uLogoToDisplay)
  131. {
  132. case ePVRTPrint3DLogoNone:
  133. break;
  134. default:
  135. case ePVRTPrint3DLogoPVR:
  136. APIDrawLogo(ePVRTPrint3DLogoPVR, 1); /* PVR to the right */
  137. break;
  138. case ePVRTPrint3DLogoIMG:
  139. APIDrawLogo(ePVRTPrint3DLogoIMG, 1); /* IMG to the right */
  140. break;
  141. case (ePVRTPrint3DLogoPVR | ePVRTPrint3DLogoIMG):
  142. APIDrawLogo(ePVRTPrint3DLogoIMG, -1); /* IMG to the left */
  143. APIDrawLogo(ePVRTPrint3DLogoPVR, 1); /* PVR to the right */
  144. break;
  145. }
  146. #endif
  147. /* Restore render states */
  148. APIRenderStates(1);
  149. return nTrisTot;
  150. #else
  151. return 0;
  152. #endif
  153. }
  154. /*************************************************************
  155. * PRIVATE FUNCTIONS *
  156. **************************************************************/
  157. /*!***************************************************************************
  158. @Function APIInit
  159. @Description Initialisation and texture upload. Should be called only once
  160. for a given context.
  161. *****************************************************************************/
  162. bool CPVRTPrint3D::APIInit(const SPVRTContext * const pContext)
  163. {
  164. PVRT_UNREFERENCED_PARAMETER(pContext);
  165. m_pAPI = new SPVRTPrint3DAPI;
  166. if(!m_pAPI)
  167. return false;
  168. /* Compiles the shaders. For a more detailed explanation, see IntroducingPVRTools */
  169. CPVRTString error;
  170. bool bRes;
  171. // Try binary shaders first
  172. bRes = (PVRTShaderLoadBinaryFromMemory(_Print3DFragShader_fsc, _Print3DFragShader_fsc_size,
  173. GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_FragmentShaderObject, &error) == PVR_SUCCESS)
  174. && (PVRTShaderLoadBinaryFromMemory(_Print3DVertShader_vsc, _Print3DVertShader_vsc_size,
  175. GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_VertexShaderObject, &error) == PVR_SUCCESS);
  176. if (!bRes)
  177. {
  178. // if binary shaders don't work, try source shaders
  179. bRes = (PVRTShaderLoadSourceFromMemory(_Print3DFragShader_fsh, GL_FRAGMENT_SHADER, &m_pAPI->m_FragmentShaderObject, &error) == PVR_SUCCESS) &&
  180. (PVRTShaderLoadSourceFromMemory(_Print3DVertShader_vsh, GL_VERTEX_SHADER, &m_pAPI->m_VertexShaderObject, &error) == PVR_SUCCESS);
  181. }
  182. _ASSERT(bRes);
  183. m_pAPI->m_ProgramObject = glCreateProgram();
  184. glAttachShader(m_pAPI->m_ProgramObject, m_pAPI->m_VertexShaderObject);
  185. glAttachShader(m_pAPI->m_ProgramObject, m_pAPI->m_FragmentShaderObject);
  186. glBindAttribLocation(m_pAPI->m_ProgramObject, VERTEX_ARRAY, "myVertex");
  187. glBindAttribLocation(m_pAPI->m_ProgramObject, UV_ARRAY, "myUV");
  188. glBindAttribLocation(m_pAPI->m_ProgramObject, COLOR_ARRAY, "myColour");
  189. glLinkProgram(m_pAPI->m_ProgramObject);
  190. GLint Linked;
  191. glGetProgramiv(m_pAPI->m_ProgramObject, GL_LINK_STATUS, &Linked);
  192. if (!Linked)
  193. bRes = false;
  194. _ASSERT(bRes);
  195. return true;
  196. }
  197. /*!***************************************************************************
  198. @Function APIRelease
  199. @Description Deinitialization.
  200. *****************************************************************************/
  201. void CPVRTPrint3D::APIRelease()
  202. {
  203. delete m_pAPI;
  204. m_pAPI = 0;
  205. }
  206. /*!***************************************************************************
  207. @Function APIUpLoadIcons
  208. @Description Initialisation and texture upload. Should be called only once
  209. for a given context.
  210. *****************************************************************************/
  211. bool CPVRTPrint3D::APIUpLoadIcons(
  212. const PVRTuint32 * const pPVR,
  213. const PVRTuint32 * const pIMG)
  214. {
  215. /* Load Icon textures */
  216. if(PVRTTextureLoadFromPointer((unsigned char*)pPVR, &m_pAPI->uTexturePVRLogo) != PVR_SUCCESS)
  217. return false;
  218. if(PVRTTextureLoadFromPointer((unsigned char*)pIMG, &m_pAPI->uTextureIMGLogo) != PVR_SUCCESS)
  219. return false;
  220. return true;
  221. }
  222. /*!***************************************************************************
  223. @Function APIUpLoad4444
  224. @Return true if succesful, false otherwise.
  225. @Description Reads texture data from *.dat and loads it in
  226. video memory.
  227. *****************************************************************************/
  228. bool CPVRTPrint3D::APIUpLoad4444(unsigned int dwTexID, unsigned char *pSource, unsigned int nSize, unsigned int nMode)
  229. {
  230. int i, j;
  231. int x=256, y=256;
  232. unsigned short R, G, B, A;
  233. unsigned short *p8888, *pDestByte;
  234. unsigned char *pSrcByte;
  235. /* Only square textures */
  236. x = nSize;
  237. y = nSize;
  238. glGenTextures(1, &m_pAPI->uTexture[dwTexID]);
  239. /* Load texture from data */
  240. /* Format is 4444-packed, expand it into 8888 */
  241. if (nMode==0)
  242. {
  243. /* Allocate temporary memory */
  244. p8888 = (unsigned short *)malloc(nSize*nSize*sizeof(unsigned short));
  245. if(!p8888)
  246. {
  247. PVRTErrorOutputDebug("Not enough memory!\n");
  248. return false;
  249. }
  250. pDestByte = p8888;
  251. /* Set source pointer (after offset of 16) */
  252. pSrcByte = &pSource[16];
  253. /* Transfer data */
  254. for (i=0; i<y; i++)
  255. {
  256. for (j=0; j<x; j++)
  257. {
  258. /* Get all 4 colour channels (invert A) */
  259. G = (*pSrcByte) & 0xF0;
  260. R = ( (*pSrcByte++) & 0x0F ) << 4;
  261. A = (*pSrcByte) ^ 0xF0;
  262. B = ( (*pSrcByte++) & 0x0F ) << 4;
  263. /* Set them in 8888 data */
  264. *pDestByte++ = ((R&0xF0)<<8) | ((G&0xF0)<<4) | (B&0xF0) | (A&0xF0)>>4;
  265. }
  266. }
  267. }
  268. else
  269. {
  270. /* Set source pointer */
  271. pSrcByte = pSource;
  272. /* Allocate temporary memory */
  273. p8888 = (unsigned short *)malloc(nSize*nSize*sizeof(unsigned short));
  274. if(!p8888)
  275. {
  276. PVRTErrorOutputDebug("Not enough memory!\n");
  277. return false;
  278. }
  279. /* Set destination pointer */
  280. pDestByte = p8888;
  281. /* Transfer data */
  282. for (i=0; i<y; i++)
  283. {
  284. for (j=0; j<x; j++)
  285. {
  286. /* Get alpha channel */
  287. A = *pSrcByte++;
  288. /* Set them in 8888 data */
  289. R = 255;
  290. G = 255;
  291. B = 255;
  292. /* Set them in 8888 data */
  293. *pDestByte++ = ((R&0xF0)<<8) | ((G&0xF0)<<4) | (B&0xF0) | (A&0xF0)>>4;
  294. }
  295. }
  296. }
  297. /* Bind texture */
  298. glBindTexture(GL_TEXTURE_2D, m_pAPI->uTexture[dwTexID]);
  299. /* Default settings: bilinear */
  300. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  301. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  302. /* Now load texture */
  303. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, p8888);
  304. if (glGetError())
  305. {
  306. _RPT0(_CRT_WARN,"glTexImage2D() failed\n");
  307. free(p8888);
  308. return false;
  309. }
  310. /* Destroy temporary data */
  311. free(p8888);
  312. /* Return status : OK */
  313. return true;
  314. }
  315. /*!***************************************************************************
  316. @Function DrawBackgroundWindowUP
  317. @Description
  318. *****************************************************************************/
  319. void CPVRTPrint3D::DrawBackgroundWindowUP(SPVRTPrint3DAPIVertex *pVtx, const bool bIsOp, const bool bBorder)
  320. {
  321. const unsigned short c_pwFacesWindow[] =
  322. {
  323. 0,1,2, 2,1,3, 2,3,4, 4,3,5, 4,5,6, 6,5,7, 5,8,7, 7,8,9, 8,10,9, 9,10,11, 8,12,10, 8,13,12,
  324. 13,14,12, 13,15,14, 13,3,15, 1,15,3, 3,13,5, 5,13,8
  325. };
  326. /* Set the texture (with or without border) */
  327. if(!bBorder)
  328. glBindTexture(GL_TEXTURE_2D, m_pAPI->uTexture[2 + (bIsOp*2)]);
  329. else
  330. glBindTexture(GL_TEXTURE_2D, m_pAPI->uTexture[1 + (bIsOp*2)]);
  331. /* Is window opaque ? */
  332. if(bIsOp)
  333. {
  334. glDisable(GL_BLEND);
  335. }
  336. else
  337. {
  338. /* Set blending properties */
  339. glEnable(GL_BLEND);
  340. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  341. }
  342. /* Set pointers */
  343. glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(SPVRTPrint3DAPIVertex), (const void*)&pVtx[0].sx);
  344. glVertexAttribPointer(COLOR_ARRAY, 3, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(SPVRTPrint3DAPIVertex), (const void*)&pVtx[0].color);
  345. glVertexAttribPointer(UV_ARRAY, 2, GL_FLOAT, GL_FALSE, sizeof(SPVRTPrint3DAPIVertex), (const void*)&pVtx[0].tu);
  346. /* Draw triangles */
  347. glDrawElements(GL_TRIANGLES, 18*3, GL_UNSIGNED_SHORT, c_pwFacesWindow);
  348. if (glGetError())
  349. {
  350. PVRTErrorOutputDebug("glDrawElements(GL_TRIANGLES, 18*3, GL_UNSIGNED_SHORT, pFaces); failed\n");
  351. }
  352. /* Restore render states (need to be translucent to draw the text) */
  353. }
  354. /*!***************************************************************************
  355. @Function APIRenderStates
  356. @Description Stores, writes and restores Render States
  357. *****************************************************************************/
  358. void CPVRTPrint3D::APIRenderStates(int nAction)
  359. {
  360. // static GLboolean bVertexPointerEnabled, bColorPointerEnabled, bTexCoorPointerEnabled;
  361. PVRTMATRIX Matrix;
  362. int i;
  363. /* Saving or restoring states ? */
  364. switch (nAction)
  365. {
  366. case 0:
  367. {
  368. /* Get previous render states */
  369. m_pAPI->isCullFaceEnabled = glIsEnabled(GL_CULL_FACE);
  370. m_pAPI->isBlendEnabled = glIsEnabled(GL_BLEND);
  371. m_pAPI->isDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
  372. glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&m_pAPI->nArrayBufferBinding);
  373. /******************************
  374. ** SET PRINT3D RENDER STATES **
  375. ******************************/
  376. /* Set the default GL_ARRAY_BUFFER */
  377. glBindBuffer(GL_ARRAY_BUFFER, 0);
  378. /* Get viewport dimensions */
  379. /*glGetFloatv(GL_VIEWPORT, fViewport);*/
  380. /* Set matrix with viewport dimensions */
  381. for(i=0; i<16; i++)
  382. {
  383. Matrix.f[i]=0;
  384. }
  385. Matrix.f[0] = (2.0f/(m_fScreenScale[0]*640.0f));
  386. Matrix.f[5] = (-2.0f/(m_fScreenScale[1]*480.0f));
  387. Matrix.f[10] = (1.0f);
  388. Matrix.f[12] = (-1.0f);
  389. Matrix.f[13] = (1.0f);
  390. Matrix.f[15] = (1.0f);
  391. /* Use the shader */
  392. glUseProgram(m_pAPI->m_ProgramObject);
  393. /* Bind the projection and modelview matrices to the shader */
  394. int location = glGetUniformLocation(m_pAPI->m_ProgramObject, "myMVPMatrix");
  395. glUniformMatrix4fv( location, 1, GL_FALSE, Matrix.f);
  396. /* Culling */
  397. glEnable(GL_CULL_FACE);
  398. glFrontFace(GL_CW);
  399. glCullFace(GL_FRONT);
  400. /* Set blending mode */
  401. glEnable(GL_BLEND);
  402. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  403. /* Set Z compare properties */
  404. glDisable(GL_DEPTH_TEST);
  405. /* Set client states */
  406. glEnableVertexAttribArray(VERTEX_ARRAY);
  407. glEnableVertexAttribArray(COLOR_ARRAY);
  408. glEnableVertexAttribArray(UV_ARRAY);
  409. /* texture */
  410. glActiveTexture(GL_TEXTURE1);
  411. glActiveTexture(GL_TEXTURE0);
  412. break;
  413. }
  414. case 1:
  415. /* Restore render states */
  416. glDisableVertexAttribArray(VERTEX_ARRAY);
  417. glDisableVertexAttribArray(COLOR_ARRAY);
  418. glDisableVertexAttribArray(UV_ARRAY);
  419. /* Restore some values */
  420. if (!m_pAPI->isCullFaceEnabled) glDisable(GL_CULL_FACE);
  421. if (!m_pAPI->isBlendEnabled) glDisable(GL_BLEND);
  422. if (m_pAPI->isDepthTestEnabled) glEnable(GL_DEPTH_TEST);
  423. glBindBuffer(GL_ARRAY_BUFFER,m_pAPI->nArrayBufferBinding);
  424. break;
  425. }
  426. }
  427. /****************************************************************************
  428. ** Local code
  429. ****************************************************************************/
  430. /*!***************************************************************************
  431. @Function APIDrawLogo
  432. @Description nPos = -1 to the left
  433. nPos = +1 to the right
  434. *****************************************************************************/
  435. #define LOGO_SIZE 0.3f
  436. #define LOGO_SHIFT 0.05f
  437. void CPVRTPrint3D::APIDrawLogo(unsigned int uLogoToDisplay, int nPos)
  438. {
  439. const float fLogoSizeHalf = 0.15f;
  440. const float fLogoShift = 0.05f;
  441. const float fLogoSizeHalfShifted = fLogoSizeHalf + fLogoShift;
  442. const float fLogoYScale = 50.0f / 64.0f;
  443. static VERTTYPE Vertices[] =
  444. {
  445. -fLogoSizeHalf, fLogoSizeHalf , 0.5f,
  446. -fLogoSizeHalf, -fLogoSizeHalf, 0.5f,
  447. fLogoSizeHalf , fLogoSizeHalf , 0.5f,
  448. fLogoSizeHalf , -fLogoSizeHalf, 0.5f
  449. };
  450. static float Colours[] = {
  451. (1.0f), (1.0f), (1.0f), (0.75f),
  452. (1.0f), (1.0f), (1.0f), (0.75f),
  453. (1.0f), (1.0f), (1.0f), (0.75f),
  454. (1.0f), (1.0f), (1.0f), (0.75f)
  455. };
  456. static float UVs[] = {
  457. (0.0f), (0.0f),
  458. (0.0f), (1.0f),
  459. (1.0f), (0.0f),
  460. (1.0f), (1.0f)
  461. };
  462. float *pVertices = ( (float*)&Vertices );
  463. float *pColours = ( (float*)&Colours );
  464. float *pUV = ( (float*)&UVs );
  465. GLuint tex;
  466. switch(uLogoToDisplay)
  467. {
  468. case ePVRTPrint3DLogoIMG:
  469. tex = m_pAPI->uTextureIMGLogo;
  470. break;
  471. default:
  472. tex = m_pAPI->uTexturePVRLogo;
  473. break;
  474. }
  475. // Matrices
  476. PVRTMATRIX matModelView;
  477. PVRTMATRIX matTransform;
  478. PVRTMatrixIdentity(matModelView);
  479. float fScreenScale = PVRT_MIN(m_ui32ScreenDim[0], m_ui32ScreenDim[1]) / 480.0f;
  480. float fScaleX = (640.0f / m_ui32ScreenDim[0]) * fScreenScale;
  481. float fScaleY = (480.0f / m_ui32ScreenDim[1]) * fScreenScale * fLogoYScale;
  482. PVRTMatrixScaling(matTransform, f2vt(fScaleX), f2vt(fScaleY), f2vt(1.0f));
  483. PVRTMatrixMultiply(matModelView, matModelView, matTransform);
  484. PVRTMatrixTranslation(matTransform, nPos - (fLogoSizeHalfShifted * fScaleX * nPos), -1.0f + (fLogoSizeHalfShifted * fScaleY), 0.0f);
  485. PVRTMatrixMultiply(matModelView, matModelView, matTransform);
  486. if(m_bRotate)
  487. {
  488. PVRTMatrixRotationZ(matTransform, -90.0f*PVRT_PI/180.0f);
  489. PVRTMatrixMultiply(matModelView, matModelView, matTransform);
  490. }
  491. // Bind the projection and modelview matrices to the shader
  492. int location = glGetUniformLocation(m_pAPI->m_ProgramObject, "myMVPMatrix");
  493. glUniformMatrix4fv( location, 1, GL_FALSE, matModelView.f);
  494. // Render states
  495. glActiveTexture(GL_TEXTURE0);
  496. glBindTexture(GL_TEXTURE_2D, tex);
  497. glDisable(GL_DEPTH_TEST);
  498. glEnable (GL_BLEND);
  499. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  500. // Vertices
  501. glEnableVertexAttribArray(VERTEX_ARRAY);
  502. glEnableVertexAttribArray(UV_ARRAY);
  503. glEnableVertexAttribArray(COLOR_ARRAY);
  504. glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, (const void*)pVertices);
  505. glVertexAttribPointer(UV_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, (const void*)pUV);
  506. glVertexAttribPointer(COLOR_ARRAY, 4, GL_FLOAT, GL_FALSE, 0, (const void*)pColours);
  507. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  508. glDisableVertexAttribArray(VERTEX_ARRAY);
  509. glDisableVertexAttribArray(UV_ARRAY);
  510. glDisableVertexAttribArray(COLOR_ARRAY);
  511. // Restore render states
  512. glDisable (GL_BLEND);
  513. glEnable(GL_DEPTH_TEST);
  514. }
  515. /*****************************************************************************
  516. End of file (PVRTPrint3DAPI.cpp)
  517. *****************************************************************************/