opengl_draw.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * opengl_draw.c: OpenGL drawing routines.
  18. *
  19. * Author: Michael Liebscher
  20. *
  21. * Acknowledgement:
  22. * This code was derived from Quake II, and was originally
  23. * written by Id Software, Inc.
  24. *
  25. */
  26. #include "../wolfiphone.h"
  27. texture_t *draw_chars;
  28. //extern _boolean scrap_dirty;
  29. //void Scrap_Upload (void);
  30. /*
  31. -----------------------------------------------------------------------------
  32. Function: R_Draw_Char -Draw ASCII character to the screen.
  33. Parameters: x -[in] x-coordinate.
  34. y -[in] y-coordinate.
  35. num -[in] ASCII character value.
  36. myfont -[in] Valid pointer to font_t structure.
  37. Returns: Nothing.
  38. Notes:
  39. It can be clipped to the top of the screen to allow the console to be
  40. smoothly scrolled off.
  41. -----------------------------------------------------------------------------
  42. */
  43. PUBLIC void R_Draw_Character( int x, int y, int num, font_t *myfont )
  44. {
  45. int row, col;
  46. int scale, sh; // scaled width, height
  47. float frow, fcol;
  48. num &= 255;
  49. if( (num & 127) == 32 )
  50. {
  51. return; // space
  52. }
  53. if( y <= -myfont->nMaxHeight )
  54. {
  55. return; // totally off screen
  56. }
  57. scale = myfont->nSize;
  58. sh = myfont->nMaxHeight;
  59. row = (num >> 4) - 2;
  60. col = num & 15;
  61. frow = row * myfont->hFrac;
  62. fcol = col * myfont->wFrac;
  63. pfglColor4ubv( myfont->colour );
  64. pfglEnable( GL_BLEND );
  65. R_Bind( myfont->texfont->texnum );
  66. pfglBegin( GL_QUADS );
  67. pfglTexCoord2f( fcol, frow );
  68. pfglVertex2i( x, y );
  69. pfglTexCoord2f( fcol+myfont->wFrac, frow );
  70. pfglVertex2i( x+myfont->nMaxWidth*scale, y );
  71. pfglTexCoord2f( fcol+myfont->wFrac, frow+myfont->hFrac );
  72. pfglVertex2i( x+myfont->nMaxWidth*scale, (y+sh*scale) );
  73. pfglTexCoord2f( fcol, frow+myfont->hFrac );
  74. pfglVertex2i( x, (y+sh*scale) );
  75. pfglEnd();
  76. pfglDisable( GL_BLEND );
  77. pfglColor3f( 1, 1, 1 );
  78. }
  79. /*
  80. -----------------------------------------------------------------------------
  81. Function: R_Draw_StretchPic -Draw stretched image to the screen.
  82. Parameters: x -[in] x-coordinate.
  83. y -[in] y-coordinate.
  84. w -[in] width of region.
  85. h -[in] height of region.
  86. pic -[in] Image filename to stretch.
  87. Returns: Nothing.
  88. Notes:
  89. -----------------------------------------------------------------------------
  90. */
  91. PUBLIC void R_Draw_StretchPic( int x, int y, int w, int h, const char *pic )
  92. {
  93. texture_t *gl;
  94. gl = TM_FindTexture( pic, TT_Pic );
  95. if( ! gl )
  96. {
  97. Com_Printf( "Can't find pic: %s\n", pic );
  98. return;
  99. }
  100. // if( scrap_dirty )
  101. // Scrap_Upload();
  102. R_Bind( gl->texnum );
  103. pfglBegin( GL_QUADS );
  104. pfglTexCoord2f( 0.0f, 0.0f ); pfglVertex2i( x, y );
  105. pfglTexCoord2f( 1.0f, 0.0f ); pfglVertex2i( x+w, y );
  106. pfglTexCoord2f( 1.0f, 1.0f ); pfglVertex2i( x+w, y+h );
  107. pfglTexCoord2f( 0.0f, 1.0f ); pfglVertex2i( x, y+h );
  108. pfglEnd();
  109. }
  110. /*
  111. -----------------------------------------------------------------------------
  112. Function: R_Draw_Pic -Draw image to the screen.
  113. Parameters: x -[in] x-coordinate.
  114. y -[in] y-coordinate.
  115. pic -[in] Image filename to draw.
  116. Returns: Nothing.
  117. Notes:
  118. -----------------------------------------------------------------------------
  119. */
  120. PUBLIC void R_Draw_Pic( int x, int y, const char *pic )
  121. {
  122. texture_t *tex;
  123. tex = TM_FindTexture( pic, TT_Pic );
  124. if( ! tex )
  125. {
  126. Com_Printf( "Can't find pic: %s\n", pic );
  127. return;
  128. }
  129. // if( scrap_dirty )
  130. // Scrap_Upload();
  131. R_Bind( tex->texnum );
  132. pfglBegin( GL_QUADS );
  133. pfglTexCoord2f( 0.0, 0.0 ); pfglVertex2i( x, y );
  134. pfglTexCoord2f( 1.0, 0.0 ); pfglVertex2i( x + tex->width, y );
  135. pfglTexCoord2f( 1.0, 1.0 ); pfglVertex2i( x + tex->width, y + tex->height );
  136. pfglTexCoord2f( 0.0, 1.0 ); pfglVertex2i( x, y + tex->height );
  137. pfglEnd();
  138. }
  139. /*
  140. -----------------------------------------------------------------------------
  141. Function: R_Draw_Tile -Tile image on the screen.
  142. Parameters: x -[in] x-coordinate.
  143. y -[in] y-coordinate.
  144. w -[in] width of region.
  145. h -[in] height of region.
  146. pic -[in] Image filename to draw.
  147. Returns: Nothing.
  148. Notes:
  149. This repeats a tile graphic to fill a region on the screen.
  150. -----------------------------------------------------------------------------
  151. */
  152. PUBLIC void R_Draw_Tile( int x, int y, int w, int h, const char *pic )
  153. {
  154. texture_t *image;
  155. image = TM_FindTexture( pic, TT_Wall );
  156. if( ! image )
  157. {
  158. Com_Printf( "Can't find pic: %s\n", pic );
  159. return;
  160. }
  161. R_Bind( image->texnum );
  162. pfglBegin( GL_QUADS );
  163. pfglTexCoord2i( x/image->upload_width, y/image->upload_height);
  164. pfglVertex2i( x, y );
  165. pfglTexCoord2i( (x + w)/image->upload_width, y/image->upload_height);
  166. pfglVertex2i( x + w, y );
  167. pfglTexCoord2i( (x+w)/image->upload_width, (y+h)/image->upload_height);
  168. pfglVertex2i( x + w, y + h );
  169. pfglTexCoord2i( x/image->upload_width, (y+h)/image->upload_height );
  170. pfglVertex2i( x, y + h );
  171. pfglEnd ();
  172. }
  173. /*
  174. -----------------------------------------------------------------------------
  175. Function: R_Draw_Fill -Fills a box of pixels with a single color.
  176. Parameters: x -[in] x-coordinate.
  177. y -[in] y-coordinate.
  178. w -[in] width of region.
  179. h -[in] height of region.
  180. c -[in] Colour to fill region.
  181. Returns: Nothing.
  182. Notes:
  183. -----------------------------------------------------------------------------
  184. */
  185. PUBLIC void R_Draw_Fill( int x, int y, int w, int h, colour3_t c )
  186. {
  187. qglScissor( x, 320-(y+h), w, h );
  188. qglEnable( GL_SCISSOR_TEST );
  189. qglClearColor( c[0] / 255.0f, c[1] / 255.0f, c[2] / 255.0f, 1.0f );
  190. qglClear( GL_COLOR_BUFFER_BIT );
  191. qglDisable( GL_SCISSOR_TEST );
  192. }
  193. PUBLIC void R_Draw_Blend( int x, int y, int w, int h, colour4_t c )
  194. {
  195. pfglDisable( GL_TEXTURE_2D );
  196. pfglColor4ubv( c );
  197. pfglBegin( GL_QUADS );
  198. pfglVertex2i( x, y );
  199. pfglVertex2i( x+w, y );
  200. pfglVertex2i( x+w, y+h );
  201. pfglVertex2i( x, y+h );
  202. pfglEnd();
  203. pfglColor3f( 1, 1, 1 );
  204. pfglEnable( GL_TEXTURE_2D );
  205. }
  206. /*
  207. -----------------------------------------------------------------------------
  208. Function: R_Draw_Line -Draw a line on the screen.
  209. Parameters: nXStart -[in] x-coordinate of starting point.
  210. nYStart -[in] y-coordinate of starting point.
  211. nXEnd -[in] x-coordinate of ending point.
  212. nYEnd -[in] y-coordinate of ending point.
  213. c -[in] Colour value.
  214. Returns: Nothing.
  215. Notes:
  216. -----------------------------------------------------------------------------
  217. */
  218. PUBLIC void R_Draw_Line( int nXStart, int nYStart, int nXEnd, int nYEnd, int width, colour3_t c )
  219. {
  220. pfglDisable( GL_TEXTURE_2D );
  221. pfglColor3ubv( c );
  222. pfglLineWidth( (float)width );
  223. pfglBegin( GL_LINES );
  224. pfglVertex2i( nXStart, nYStart );
  225. pfglVertex2i( nXEnd, nYEnd );
  226. pfglEnd();
  227. pfglColor3f( 1, 1, 1 );
  228. pfglEnable( GL_TEXTURE_2D );
  229. }