render.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. /*
  2. Copyright (C) 2005, 2010 - Cryptic Sea
  3. This file is part of Gish.
  4. Gish 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.
  11. See the 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. void renderlevelback(void)
  17. {
  18. int count,count2;
  19. int lightcount;
  20. int blocknum;
  21. int lightrange;
  22. float vec[3];
  23. float texcoord[2];
  24. updateogg();
  25. for (count=view.position[1]-view.zoomy;count<=view.position[1]+view.zoomy;count++)
  26. if (count>=0 && count<256)
  27. for (count2=view.position[0]-view.zoomx;count2<=view.position[0]+view.zoomx;count2++)
  28. if (count2>=0 && count2<256)
  29. {
  30. blocknum=level.backgrid[count][count2];
  31. if (block[blocknum].animation!=0)
  32. if (block[blocknum].animationspeed!=0)
  33. blocknum+=(game.framenum/block[blocknum].animationspeed)%block[blocknum].animation;
  34. if (!game.godmode)
  35. if (!editor.active || !editor.showgrid)
  36. if (level.grid[count][count2]!=0 && level.gridmod[count][count2]==0)
  37. if (!texture[level.grid[count][count2]].isalpha)
  38. blocknum=0;
  39. if (!game.godmode)
  40. if (!editor.active || !editor.showgrid)
  41. if (level.foregrid[count][count2]!=0)
  42. if (!texture[level.foregrid[count][count2]].isalpha)
  43. blocknum=0;
  44. if (blocknum!=0)
  45. {
  46. glBindTexture(GL_TEXTURE_2D,texture[blocknum].glname);
  47. glBegin(GL_QUADS);
  48. glColor3fv(level.ambient[0]);
  49. vec[0]=(float)count2;
  50. vec[1]=(float)count+1.0f;
  51. glTexCoord2f(0.0f,0.0f);
  52. glVertex3f(vec[0],vec[1],0.0f);
  53. vec[0]=(float)count2+1.0f;
  54. vec[1]=(float)count+1.0f;
  55. glTexCoord2f(1.0f,0.0f);
  56. glVertex3f(vec[0],vec[1],0.0f);
  57. vec[0]=(float)count2+1.0f;
  58. vec[1]=(float)count;
  59. glTexCoord2f(1.0f,1.0f);
  60. glVertex3f(vec[0],vec[1],0.0f);
  61. vec[0]=(float)count2;
  62. vec[1]=(float)count;
  63. glTexCoord2f(0.0f,1.0f);
  64. glVertex3f(vec[0],vec[1],0.0f);
  65. glEnd();
  66. }
  67. }
  68. glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  69. glEnable(GL_STENCIL_TEST);
  70. glActiveTextureARB(GL_TEXTURE1_ARB);
  71. glEnable(GL_TEXTURE_2D);
  72. glBindTexture(GL_TEXTURE_2D,texture[332].glname);
  73. glDisable(GL_TEXTURE_2D);
  74. glActiveTextureARB(GL_TEXTURE0_ARB);
  75. for (lightcount=0;lightcount<frame.numoflights;lightcount++)
  76. {
  77. glStencilMask((1<<lightcount));
  78. glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
  79. glStencilFunc(GL_NOTEQUAL,(1<<lightcount),(1<<lightcount));
  80. for (count=view.position[1]-view.zoomy;count<=view.position[1]+view.zoomy;count++)
  81. if (count>=0 && count<256)
  82. for (count2=view.position[0]-view.zoomx;count2<=view.position[0]+view.zoomx;count2++)
  83. if (count2>=0 && count2<256)
  84. {
  85. blocknum=level.backgrid[count][count2];
  86. if (block[blocknum].animation!=0)
  87. if (block[blocknum].animationspeed!=0)
  88. blocknum+=(game.framenum/block[blocknum].animationspeed)%block[blocknum].animation;
  89. if (!editor.active || !editor.showgrid)
  90. if (level.grid[count][count2]!=0 && level.gridmod[count][count2]==0)
  91. if (!texture[level.grid[count][count2]].isalpha)
  92. blocknum=0;
  93. if (!editor.active || !editor.showgrid)
  94. if (level.foregrid[count][count2]!=0)
  95. if (!texture[level.foregrid[count][count2]].isalpha)
  96. blocknum=0;
  97. lightrange=frame.light[lightcount].intensity*0.5f;
  98. if ((count2-frame.light[lightcount].position[0])>lightrange+1)
  99. blocknum=0;
  100. if ((count-frame.light[lightcount].position[1])>lightrange+1)
  101. blocknum=0;
  102. if (blocknum!=0)
  103. {
  104. glBindTexture(GL_TEXTURE_2D,texture[blocknum].glname);
  105. glActiveTextureARB(GL_TEXTURE1_ARB);
  106. glEnable(GL_TEXTURE_2D);
  107. glBegin(GL_QUADS);
  108. glColor3fv(frame.light[lightcount].color);
  109. vec[0]=(float)count2;
  110. vec[1]=(float)count+1.0f;
  111. glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0f,0.0f);
  112. setuplighttexcoord(lightcount,vec);
  113. glVertex3f(vec[0],vec[1],0.0f);
  114. vec[0]=(float)count2+1.0f;
  115. vec[1]=(float)count+1.0f;
  116. glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1.0f,0.0f);
  117. setuplighttexcoord(lightcount,vec);
  118. glVertex3f(vec[0],vec[1],0.0f);
  119. vec[0]=(float)count2+1.0f;
  120. vec[1]=(float)count;
  121. glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1.0f,1.0f);
  122. setuplighttexcoord(lightcount,vec);
  123. glVertex3f(vec[0],vec[1],0.0f);
  124. vec[0]=(float)count2;
  125. vec[1]=(float)count;
  126. glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0f,1.0f);
  127. setuplighttexcoord(lightcount,vec);
  128. glVertex3f(vec[0],vec[1],0.0f);
  129. glEnd();
  130. glDisable(GL_TEXTURE_2D);
  131. glActiveTextureARB(GL_TEXTURE0_ARB);
  132. }
  133. }
  134. }
  135. glDisable(GL_STENCIL_TEST);
  136. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  137. }
  138. void renderlevel(void)
  139. {
  140. int count,count2,count3;
  141. int lightcount;
  142. int blocknum;
  143. int lightrange;
  144. float vec[3],vec2[3],vec3[3];
  145. float normal[3];
  146. float scale;
  147. updateogg();
  148. for (count=view.position[1]-view.zoomy;count<=view.position[1]+view.zoomy;count++)
  149. if (count>=0 && count<256)
  150. for (count2=view.position[0]-view.zoomx;count2<=view.position[0]+view.zoomx;count2++)
  151. if (count2>=0 && count2<256)
  152. {
  153. blocknum=level.grid[count][count2];
  154. if (block[blocknum].animation!=0)
  155. if (block[blocknum].animationspeed!=0)
  156. blocknum+=(game.framenum/block[blocknum].animationspeed)%block[blocknum].animation;
  157. if (level.gridmod[count][count2]==1)
  158. blocknum=0;
  159. if (blocknum>=240 && blocknum<248)
  160. if (level.gridmod[count][count2]==2)
  161. blocknum+=8;
  162. if (!editor.active || !editor.showgrid)
  163. if (level.foregrid[count][count2]!=0)
  164. if (!texture[level.foregrid[count][count2]].isalpha)
  165. blocknum=0;
  166. if (blocknum!=0)
  167. {
  168. glBindTexture(GL_TEXTURE_2D,texture[blocknum].glname);
  169. glBegin(GL_QUADS);
  170. glColor3fv(level.ambient[1]);
  171. vec[0]=(float)count2;
  172. vec[1]=(float)count+1.0f;
  173. glTexCoord2f(0.0f,0.0f);
  174. glVertex3f(vec[0],vec[1],0.0f);
  175. vec[0]=(float)count2+1.0f;
  176. vec[1]=(float)count+1.0f;
  177. glTexCoord2f(1.0f,0.0f);
  178. glVertex3f(vec[0],vec[1],0.0f);
  179. vec[0]=(float)count2+1.0f;
  180. vec[1]=(float)count;
  181. glTexCoord2f(1.0f,1.0f);
  182. glVertex3f(vec[0],vec[1],0.0f);
  183. vec[0]=(float)count2;
  184. vec[1]=(float)count;
  185. glTexCoord2f(0.0f,1.0f);
  186. glVertex3f(vec[0],vec[1],0.0f);
  187. glEnd();
  188. /*
  189. if (block[blocknum].friction<0.1f)
  190. {
  191. glDisable(GL_TEXTURE_2D);
  192. for (count3=0;count3<block[blocknum].numoflines;count3++)
  193. if (((level.gridflags[count][count2]>>count3)&1)==0)
  194. {
  195. normal[0]=-(block[blocknum].line[count3][3]-block[blocknum].line[count3][1]);
  196. normal[1]=(block[blocknum].line[count3][2]-block[blocknum].line[count3][0]);
  197. normal[2]=0.0f;
  198. normalizevector(normal,normal);
  199. glBegin(GL_QUADS);
  200. glColor4f(0.25f,0.25f,0.25f,1.0f);
  201. vec[0]=(float)count2+block[blocknum].line[count3][0];
  202. vec[1]=(float)count+block[blocknum].line[count3][1];
  203. vec[2]=0.0f;
  204. glVertex3fv(vec);
  205. vec[0]=(float)count2+block[blocknum].line[count3][2];
  206. vec[1]=(float)count+block[blocknum].line[count3][3];
  207. vec[2]=0.0f;
  208. glVertex3fv(vec);
  209. glColor4f(0.25f,0.25f,0.25f,0.0f);
  210. vec[0]=(float)count2+block[blocknum].line[count3][2]-normal[0]*0.125f*0.5f;
  211. vec[1]=(float)count+block[blocknum].line[count3][3]-normal[1]*0.125f*0.5f;
  212. vec[2]=0.0f;
  213. glVertex3fv(vec);
  214. vec[0]=(float)count2+block[blocknum].line[count3][0]-normal[0]*0.125f*0.5f;
  215. vec[1]=(float)count+block[blocknum].line[count3][1]-normal[1]*0.125f*0.5f;
  216. vec[2]=0.0f;
  217. glVertex3fv(vec);
  218. glEnd();
  219. }
  220. glEnable(GL_TEXTURE_2D);
  221. }
  222. */
  223. }
  224. }
  225. glBlendFunc(GL_ONE,GL_ONE);
  226. glEnable(GL_STENCIL_TEST);
  227. for (lightcount=0;lightcount<frame.numoflights;lightcount++)
  228. {
  229. glStencilMask((1<<lightcount));
  230. glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
  231. glStencilFunc(GL_NOTEQUAL,(1<<lightcount),(1<<lightcount));
  232. for (count=view.position[1]-view.zoomy;count<=view.position[1]+view.zoomy;count++)
  233. if (count>=0 && count<256)
  234. for (count2=view.position[0]-view.zoomx;count2<=view.position[0]+view.zoomx;count2++)
  235. if (count2>=0 && count2<256)
  236. {
  237. blocknum=level.grid[count][count2];
  238. if (block[blocknum].animation!=0)
  239. if (block[blocknum].animationspeed!=0)
  240. blocknum+=(game.framenum/block[blocknum].animationspeed)%block[blocknum].animation;
  241. if (level.gridmod[count][count2]==1)
  242. blocknum=0;
  243. if (blocknum>=240 && blocknum<248)
  244. if (level.gridmod[count][count2]==2)
  245. blocknum+=8;
  246. if (!editor.active || !editor.showgrid)
  247. if (level.foregrid[count][count2]!=0)
  248. if (!texture[level.foregrid[count][count2]].isalpha)
  249. blocknum=0;
  250. lightrange=frame.light[lightcount].intensity*0.5f;
  251. if ((count2-frame.light[lightcount].position[0])>lightrange+1)
  252. blocknum=0;
  253. if ((count-frame.light[lightcount].position[1])>lightrange+1)
  254. blocknum=0;
  255. if (blocknum!=0)
  256. {
  257. glBindTexture(GL_TEXTURE_2D,texture[blocknum].glname);
  258. for (count3=0;count3<block[blocknum].numoflines;count3++)
  259. if (((level.gridflags[count][count2]>>count3)&1)==0)
  260. {
  261. normal[0]=-(block[blocknum].line[count3][3]-block[blocknum].line[count3][1]);
  262. normal[1]=(block[blocknum].line[count3][2]-block[blocknum].line[count3][0]);
  263. normal[2]=0.0f;
  264. normalizevector(normal,normal);
  265. glBegin(GL_QUADS);
  266. vec[0]=(float)count2+block[blocknum].line[count3][0];
  267. vec[1]=(float)count+block[blocknum].line[count3][1];
  268. vec[2]=0.0f;
  269. subtractvectors(vec2,frame.light[lightcount].position,vec);
  270. normalizevector(vec3,vec2);
  271. scale=frame.light[lightcount].intensity*dotproduct(vec3,normal)/(vec2[0]*vec2[0]+vec2[1]*vec2[1]);
  272. scalevector(vec2,frame.light[lightcount].color,scale);
  273. glColor3fv(vec2);
  274. glTexCoord2f(block[blocknum].line[count3][0],1.0f-block[blocknum].line[count3][1]);
  275. glVertex3f(vec[0],vec[1],0.0f);
  276. vec[0]=(float)count2+block[blocknum].line[count3][2];
  277. vec[1]=(float)count+block[blocknum].line[count3][3];
  278. vec[2]=0.0f;
  279. subtractvectors(vec2,frame.light[lightcount].position,vec);
  280. normalizevector(vec3,vec2);
  281. scale=frame.light[lightcount].intensity*dotproduct(vec3,normal)/(vec2[0]*vec2[0]+vec2[1]*vec2[1]);
  282. scalevector(vec2,frame.light[lightcount].color,scale);
  283. glColor3fv(vec2);
  284. glTexCoord2f(block[blocknum].line[count3][2],1.0f-block[blocknum].line[count3][3]);
  285. glVertex3f(vec[0],vec[1],0.0f);
  286. vec[0]=(float)count2+block[blocknum].line[count3][2]-normal[0]*0.125f;
  287. vec[1]=(float)count+block[blocknum].line[count3][3]-normal[1]*0.125f;
  288. glColor3f(0.0f,0.0f,0.0f);
  289. glTexCoord2f((block[blocknum].line[count3][2]-normal[0]*0.125f),1.0f-(block[blocknum].line[count3][3]-normal[1]*0.125f));
  290. glVertex3f(vec[0],vec[1],0.0f);
  291. vec[0]=(float)count2+block[blocknum].line[count3][0]-normal[0]*0.125f;
  292. vec[1]=(float)count+block[blocknum].line[count3][1]-normal[1]*0.125f;
  293. glColor3f(0.0f,0.0f,0.0f);
  294. glTexCoord2f((block[blocknum].line[count3][0]-normal[0]*0.125f),1.0f-(block[blocknum].line[count3][1]-normal[1]*0.125f));
  295. glVertex3f(vec[0],vec[1],0.0f);
  296. glEnd();
  297. }
  298. }
  299. }
  300. }
  301. glDisable(GL_STENCIL_TEST);
  302. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  303. }
  304. void renderlevelfore(void)
  305. {
  306. int count,count2;
  307. int blocknum;
  308. float vec[3];
  309. updateogg();
  310. for (count=view.position[1]-view.zoomy;count<=view.position[1]+view.zoomy;count++)
  311. if (count>=0 && count<256)
  312. for (count2=view.position[0]-view.zoomx;count2<=view.position[0]+view.zoomx;count2++)
  313. if (count2>=0 && count2<256)
  314. {
  315. blocknum=level.foregrid[count][count2];
  316. if (block[blocknum].animation!=0)
  317. if (block[blocknum].animationspeed!=0)
  318. blocknum+=(game.framenum/block[blocknum].animationspeed)%block[blocknum].animation;
  319. if (blocknum!=0)
  320. {
  321. glBindTexture(GL_TEXTURE_2D,texture[blocknum].glname);
  322. glBegin(GL_QUADS);
  323. glColor3fv(level.ambient[2]);
  324. vec[0]=(float)count2;
  325. vec[1]=(float)count+1.0f;
  326. glTexCoord2f(0.0f,0.0f);
  327. glVertex3f(vec[0],vec[1],0.0f);
  328. vec[0]=(float)count2+1.0f;
  329. vec[1]=(float)count+1.0f;
  330. glTexCoord2f(1.0f,0.0f);
  331. glVertex3f(vec[0],vec[1],0.0f);
  332. vec[0]=(float)count2+1.0f;
  333. vec[1]=(float)count;
  334. glTexCoord2f(1.0f,1.0f);
  335. glVertex3f(vec[0],vec[1],0.0f);
  336. vec[0]=(float)count2;
  337. vec[1]=(float)count;
  338. glTexCoord2f(0.0f,1.0f);
  339. glVertex3f(vec[0],vec[1],0.0f);
  340. glEnd();
  341. }
  342. }
  343. }
  344. void renderbonds(void)
  345. {
  346. int count;
  347. float vec[3];
  348. glDisable(GL_TEXTURE_2D);
  349. glBegin(GL_LINES);
  350. glColor4f(0.0f,1.0f,0.0f,1.0f);
  351. for (count=0;count<numofbonds;count++)
  352. {
  353. vec[0]=particle[bond[count].part1].position[0];
  354. vec[1]=particle[bond[count].part1].position[1];
  355. vec[2]=particle[bond[count].part1].position[2];
  356. glVertex3fv(vec);
  357. vec[0]=particle[bond[count].part2].position[0];
  358. vec[1]=particle[bond[count].part2].position[1];
  359. vec[2]=particle[bond[count].part2].position[2];
  360. glVertex3fv(vec);
  361. }
  362. glColor4f(1.0f,1.0f,0.0f,1.0f);
  363. for (count=0;count<physicstemp.numofbonds;count++)
  364. {
  365. if (physicstemp.bond[count].type==0)
  366. {
  367. glVertex3fv(particle[physicstemp.bond[count].part1].position);
  368. glVertex3fv(physicstemp.bond[count].point);
  369. }
  370. if (physicstemp.bond[count].type==1)
  371. {
  372. glVertex3fv(particle[physicstemp.bond[count].part1].position);
  373. glVertex3fv(physicstemp.bond[count].point);
  374. }
  375. if (physicstemp.bond[count].type==5)
  376. {
  377. scalevector(vec,particle[physicstemp.bond[count].part1].position,physicstemp.bond[count].force[0]);
  378. scaleaddvectors(vec,vec,particle[physicstemp.bond[count].part2].position,physicstemp.bond[count].force[1]);
  379. glVertex3fv(vec);
  380. glVertex3fv(particle[physicstemp.bond[count].part3].position);
  381. }
  382. }
  383. glEnd();
  384. glEnable(GL_TEXTURE_2D);
  385. }
  386. void renderobjectinvisible(int objectnum)
  387. {
  388. int count,count2;
  389. float vec[3],vec2[3];
  390. float windowsize;
  391. windowsize=2.0f*640.0f/800.0f;
  392. vec[0]=object[objectrender[objectnum].objectnum].position[0]-view.position[0];
  393. vec[1]=object[objectrender[objectnum].objectnum].position[1]-view.position[1];
  394. vec[0]/=10.0f;
  395. vec[1]/=10.0f;
  396. count2=(windowinfo.resolutionx>>1)+vec[0]*(windowinfo.resolutionx>>1);
  397. count=(windowinfo.resolutiony>>1)+vec[1]*(windowinfo.resolutionx>>1);
  398. count2-=64;
  399. count-=64;
  400. if (count2<0)
  401. count2=0;
  402. if (count<0)
  403. count=0;
  404. if (count2>windowinfo.resolutionx-128)
  405. count2=windowinfo.resolutionx-128;
  406. if (count>windowinfo.resolutiony-128)
  407. count=windowinfo.resolutiony-128;
  408. glBindTexture(GL_TEXTURE_2D,texture[331].glname);
  409. glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,count2,count,128,128,0);
  410. glBlendFunc(GL_ONE,GL_ZERO);
  411. //glDisable(GL_ALPHA_TEST);
  412. glBindTexture(GL_TEXTURE_2D,texture[331].glname);
  413. glBegin(GL_TRIANGLES);
  414. glColor3f(0.75f,0.75f,0.75f);
  415. for (count2=0;count2<32;count2++)
  416. {
  417. subtractvectors(vec2,objectrender[objectnum].vertex[count2],object[objectrender[objectnum].objectnum].position);
  418. normalizevector(vec2,vec2);
  419. glTexCoord2f(0.5f+vec2[0]*0.3f,0.5f+vec2[1]*0.3f);
  420. glVertex3fv(objectrender[objectnum].vertex[count2]);
  421. subtractvectors(vec2,objectrender[objectnum].vertex[((count2+1)&31)],object[objectrender[objectnum].objectnum].position);
  422. normalizevector(vec2,vec2);
  423. glTexCoord2f(0.5f+vec2[0]*0.3f,0.5f+vec2[1]*0.3f);
  424. glVertex3fv(objectrender[objectnum].vertex[((count2+1)&31)]);
  425. glTexCoord2f(0.5f,0.5f);
  426. glVertex3fv(objectrender[objectnum].vertex[32]);
  427. }
  428. glEnd();
  429. /*
  430. for (count=0;count<16;count++)
  431. {
  432. glBegin(GL_TRIANGLES);
  433. glColor3f(0.5f,0.5f,0.5f);
  434. subtractvectors(vec2,particle[object[objectnum].particle[count]].position,object[objectnum].position);
  435. normalizevector(vec2,vec2);
  436. glTexCoord2f(0.5f+vec2[0]*0.3f,0.5f+vec2[1]*0.3f);
  437. glVertex3fv(particle[object[objectnum].particle[count]].position);
  438. subtractvectors(vec2,particle[object[objectnum].particle[((count+1)&15)]].position,object[objectnum].position);
  439. normalizevector(vec2,vec2);
  440. glTexCoord2f(0.5f+vec2[0]*0.3f,0.5f+vec2[1]*0.3f);
  441. glVertex3fv(particle[object[objectnum].particle[((count+1)&15)]].position);
  442. glTexCoord2f(0.5f,0.5f);
  443. glVertex3fv(object[objectnum].position);
  444. glEnd();
  445. }
  446. */
  447. //glEnable(GL_ALPHA_TEST);
  448. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  449. }
  450. void setuplighttexcoord(int lightcount,float position[3])
  451. {
  452. float texcoord[2];
  453. texcoord[0]=(position[0]-frame.light[lightcount].position[0])/frame.light[lightcount].intensity+0.5f;
  454. texcoord[1]=(position[1]-frame.light[lightcount].position[1])/frame.light[lightcount].intensity+0.5f;
  455. glMultiTexCoord2fARB(GL_TEXTURE1_ARB,texcoord[0],texcoord[1]);
  456. }
  457. float calclight(int lightcount,float position[3],float normal[3])
  458. {
  459. float vec[3],vec2[3];
  460. float scale;
  461. subtractvectors(vec,frame.light[lightcount].position,position);
  462. normalizevector(vec2,vec);
  463. scale=frame.light[lightcount].intensity*dotproduct(vec2,normal)/(vec[0]*vec[0]+vec[1]*vec[1]);
  464. return(scale);
  465. }
  466. void renderparticles(void)
  467. {
  468. int count;
  469. float vec[3];
  470. float alpha;
  471. for (count=0;count<numofparticles;count++)
  472. if (particle[count].type==5)
  473. if (particle[count].texturenum!=366)
  474. {
  475. alpha=1.0f;
  476. if (particle[count].timetolive<50)
  477. alpha=(float)particle[count].timetolive/50.0f;
  478. glBindTexture(GL_TEXTURE_2D,texture[particle[count].texturenum].glname);
  479. glBegin(GL_QUADS);
  480. glColor4f(1.0f,1.0f,1.0f,alpha);
  481. glTexCoord2f(0.0f,0.0f);
  482. vec[0]=particle[count].position[0]-particle[count].rendersize*0.5f;
  483. vec[1]=particle[count].position[1]+particle[count].rendersize*0.5f;
  484. glVertex3f(vec[0],vec[1],0.0f);
  485. glTexCoord2f(1.0f,0.0f);
  486. vec[0]=particle[count].position[0]+particle[count].rendersize*0.5f;
  487. vec[1]=particle[count].position[1]+particle[count].rendersize*0.5f;
  488. glVertex3f(vec[0],vec[1],0.0f);
  489. glTexCoord2f(1.0f,1.0f);
  490. vec[0]=particle[count].position[0]+particle[count].rendersize*0.5f;
  491. vec[1]=particle[count].position[1]-particle[count].rendersize*0.5f;
  492. glVertex3f(vec[0],vec[1],0.0f);
  493. glTexCoord2f(0.0f,1.0f);
  494. vec[0]=particle[count].position[0]-particle[count].rendersize*0.5f;
  495. vec[1]=particle[count].position[1]-particle[count].rendersize*0.5f;
  496. glVertex3f(vec[0],vec[1],0.0f);
  497. glEnd();
  498. }
  499. }
  500. void renderparticles2(void)
  501. {
  502. int count;
  503. float vec[3];
  504. float alpha;
  505. for (count=0;count<numofparticles;count++)
  506. if (particle[count].type==5)
  507. if (particle[count].texturenum==366)
  508. {
  509. alpha=1.0f;
  510. if (particle[count].timetolive<50)
  511. alpha=(float)particle[count].timetolive/50.0f;
  512. glBindTexture(GL_TEXTURE_2D,texture[particle[count].texturenum].glname);
  513. glBegin(GL_QUADS);
  514. glColor4f(1.0f,1.0f,1.0f,alpha);
  515. glTexCoord2f(0.0f,0.0f);
  516. vec[0]=particle[count].position[0]-particle[count].rendersize*0.5f;
  517. vec[1]=particle[count].position[1]+particle[count].rendersize*0.5f;
  518. glVertex3f(vec[0],vec[1],0.0f);
  519. glTexCoord2f(1.0f,0.0f);
  520. vec[0]=particle[count].position[0]+particle[count].rendersize*0.5f;
  521. vec[1]=particle[count].position[1]+particle[count].rendersize*0.5f;
  522. glVertex3f(vec[0],vec[1],0.0f);
  523. glTexCoord2f(1.0f,1.0f);
  524. vec[0]=particle[count].position[0]+particle[count].rendersize*0.5f;
  525. vec[1]=particle[count].position[1]-particle[count].rendersize*0.5f;
  526. glVertex3f(vec[0],vec[1],0.0f);
  527. glTexCoord2f(0.0f,1.0f);
  528. vec[0]=particle[count].position[0]-particle[count].rendersize*0.5f;
  529. vec[1]=particle[count].position[1]-particle[count].rendersize*0.5f;
  530. glVertex3f(vec[0],vec[1],0.0f);
  531. glEnd();
  532. }
  533. }
  534. void renderobjects(void)
  535. {
  536. int count,count2;
  537. int lightcount;
  538. float vec[3],vec2[3];
  539. float normal[3];
  540. float color[4];
  541. float size;
  542. updateogg();
  543. for (count=0;count<numofobjectrenders;count++)
  544. {
  545. if (objectrender[count].type==1)
  546. {
  547. if (game.godmode && game.oldschool==0)
  548. renderobjectinvisible(count);
  549. else
  550. {
  551. glDisable(GL_TEXTURE_2D);
  552. glBegin(GL_TRIANGLES);
  553. glColor4f(0.0f,0.0f,0.0f,1.0f);
  554. if (objectrender[count].objectnum==1)
  555. glColor4f(0.5f,0.5f,0.5f,1.0f);
  556. if (objectrender[count].objectnum==2)
  557. glColor4f(0.355f,0.31f,0.15f,1.0f);
  558. if (objectrender[count].objectnum==3)
  559. glColor4f(0.453f,0.3f,0.28f,1.0f);
  560. if (object[objectrender[count].objectnum].hitpoints<object[objectrender[count].objectnum].prevhitpoints)
  561. glColor4f(0.25f,0.0f,0.0f,1.0f);
  562. for (count2=0;count2<32;count2++)
  563. {
  564. glVertex3fv(objectrender[count].vertex[count2]);
  565. glVertex3fv(objectrender[count].vertex[((count2+1)&31)]);
  566. glVertex3fv(objectrender[count].vertex[32]);
  567. }
  568. glEnd();
  569. glEnable(GL_TEXTURE_2D);
  570. }
  571. renderobjectspecular(count);
  572. size=0.75f;
  573. glBindTexture(GL_TEXTURE_2D,texture[objectrender[count].texturenum].glname);
  574. glBegin(GL_QUADS);
  575. glColor4f(1.0f,1.0f,1.0f,1.0f);
  576. vec[0]=objectrender[count].vertex[32][0]+size*cos(objectrender[count].angle+pi/4.0f);
  577. vec[1]=objectrender[count].vertex[32][1]+size*sin(objectrender[count].angle+pi/4.0f);
  578. vec[2]=0.0f;
  579. if (object[objectrender[count].objectnum].direction==0)
  580. glTexCoord2f(0.0f,0.0f);
  581. else
  582. glTexCoord2f(1.0f,0.0f);
  583. glVertex3fv(vec);
  584. vec[0]=objectrender[count].vertex[32][0]+size*cos(objectrender[count].angle+3.0f*pi/4.0f);
  585. vec[1]=objectrender[count].vertex[32][1]+size*sin(objectrender[count].angle+3.0f*pi/4.0f);
  586. vec[2]=0.0f;
  587. if (object[objectrender[count].objectnum].direction==0)
  588. glTexCoord2f(1.0f,0.0f);
  589. else
  590. glTexCoord2f(0.0f,0.0f);
  591. glVertex3fv(vec);
  592. vec[0]=objectrender[count].vertex[32][0]+size*cos(objectrender[count].angle+5.0f*pi/4.0f);
  593. vec[1]=objectrender[count].vertex[32][1]+size*sin(objectrender[count].angle+5.0f*pi/4.0f);
  594. vec[2]=0.0f;
  595. if (object[objectrender[count].objectnum].direction==0)
  596. glTexCoord2f(1.0f,1.0f);
  597. else
  598. glTexCoord2f(0.0f,1.0f);
  599. glVertex3fv(vec);
  600. vec[0]=objectrender[count].vertex[32][0]+size*cos(objectrender[count].angle+7.0f*pi/4.0f);
  601. vec[1]=objectrender[count].vertex[32][1]+size*sin(objectrender[count].angle+7.0f*pi/4.0f);
  602. vec[2]=0.0f;
  603. if (object[objectrender[count].objectnum].direction==0)
  604. glTexCoord2f(0.0f,1.0f);
  605. else
  606. glTexCoord2f(1.0f,1.0f);
  607. glVertex3fv(vec);
  608. glEnd();
  609. if (!object[objectrender[count].objectnum].idata[0])
  610. {
  611. if (game.oldschool==0)
  612. glEnable(GL_LINE_SMOOTH);
  613. glDisable(GL_TEXTURE_2D);
  614. for (count2=0;count2<32;count2++)
  615. {
  616. glBegin(GL_LINES);
  617. if (objectrender[count].objectnum==0)
  618. glColor4f(0.5f,0.5f,0.5f,0.5f);
  619. else
  620. glColor4f(0.25f,0.25f,0.25f,0.5f);
  621. glVertex3fv(objectrender[count].vertex[count2]);
  622. glVertex3fv(objectrender[count].vertex[((count2+1)&31)]);
  623. glEnd();
  624. }
  625. if ((object[objectrender[count].objectnum].button&4)==4)
  626. for (count2=0;count2<32;count2++)
  627. {
  628. glBegin(GL_LINES);
  629. if (objectrender[count].objectnum==0)
  630. glColor4f(0.5f,0.5f,0.5f,0.5f);
  631. else
  632. glColor4f(0.25f,0.25f,0.25f,0.5f);
  633. normal[0]=objectrender[count].vertex[count2][1]-objectrender[count].vertex[((count2+1)&31)][1];
  634. normal[1]=objectrender[count].vertex[((count2+1)&31)][0]-objectrender[count].vertex[count2][0];
  635. normal[2]=0.0f;
  636. copyvector(vec,objectrender[count].vertex[count2]);
  637. scaleaddvectors(vec,vec,normal,0.1f);
  638. glVertex3fv(vec);
  639. normal[0]=objectrender[count].vertex[((count2+1)&31)][1]-objectrender[count].vertex[((count2+2)&31)][1];
  640. normal[1]=objectrender[count].vertex[((count2+2)&31)][0]-objectrender[count].vertex[((count2+1)&31)][0];
  641. normal[2]=0.0f;
  642. copyvector(vec,objectrender[count].vertex[((count2+1)&31)]);
  643. scaleaddvectors(vec,vec,normal,0.1f);
  644. glVertex3fv(vec);
  645. glEnd();
  646. }
  647. if ((object[objectrender[count].objectnum].button&1)==1)
  648. for (count2=0;count2<32;count2++)
  649. {
  650. glBegin(GL_LINES);
  651. if (objectrender[count].objectnum==0)
  652. {
  653. color[0]=0.5f;
  654. color[1]=0.5f;
  655. color[2]=0.5f;
  656. }
  657. else
  658. {
  659. color[0]=0.25f;
  660. color[1]=0.25f;
  661. color[2]=0.25f;
  662. }
  663. normal[0]=objectrender[count].vertex[count2][1]-objectrender[count].vertex[((count2+1)&31)][1];
  664. normal[1]=objectrender[count].vertex[((count2+1)&31)][0]-objectrender[count].vertex[count2][0];
  665. normal[2]=0.0f;
  666. scalevector(normal,normal,0.8f);
  667. copyvector(vec,objectrender[count].vertex[count2]);
  668. color[3]=1.0f;
  669. glColor4fv(color);
  670. glVertex3fv(vec);
  671. addvectors(vec,vec,normal);
  672. color[3]=0.0f;
  673. glColor4fv(color);
  674. glVertex3fv(vec);
  675. scalevector(vec,objectrender[count].vertex[count2],0.5f);
  676. scaleaddvectors(vec,vec,objectrender[count].vertex[((count2+1)&31)],0.5f);
  677. color[3]=1.0f;
  678. glColor4fv(color);
  679. glVertex3fv(vec);
  680. addvectors(vec,vec,normal);
  681. color[3]=0.0f;
  682. glColor4fv(color);
  683. glVertex3fv(vec);
  684. glEnd();
  685. }
  686. glEnable(GL_TEXTURE_2D);
  687. glDisable(GL_LINE_SMOOTH);
  688. }
  689. }
  690. else
  691. {
  692. glBindTexture(GL_TEXTURE_2D,texture[objectrender[count].texturenum].glname);
  693. glBegin(GL_TRIANGLES);
  694. glColor4f(level.ambient[1][0],level.ambient[1][1],level.ambient[1][2],objectrender[count].alpha);
  695. if (objectrender[count].type==8)
  696. if (object[objectrender[count].objectnum].lighttype==1)
  697. glColor3fv(object[objectrender[count].objectnum].lightcolor);
  698. for (count2=0;count2<objectrender[count].numoftris;count2++)
  699. {
  700. glTexCoord2fv(objectrender[count].texcoord[objectrender[count].tri[count2][0]]);
  701. glVertex3fv(objectrender[count].vertex[objectrender[count].tri[count2][0]]);
  702. glTexCoord2fv(objectrender[count].texcoord[objectrender[count].tri[count2][1]]);
  703. glVertex3fv(objectrender[count].vertex[objectrender[count].tri[count2][1]]);
  704. glTexCoord2fv(objectrender[count].texcoord[objectrender[count].tri[count2][2]]);
  705. glVertex3fv(objectrender[count].vertex[objectrender[count].tri[count2][2]]);
  706. }
  707. glEnd();
  708. glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  709. glEnable(GL_STENCIL_TEST);
  710. for (lightcount=0;lightcount<frame.numoflights;lightcount++)
  711. if (((objectrender[count].lightflags>>lightcount)&1)==1)
  712. {
  713. glStencilMask((1<<lightcount));
  714. glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
  715. glStencilFunc(GL_NOTEQUAL,(1<<lightcount),(1<<lightcount));
  716. glActiveTextureARB(GL_TEXTURE1_ARB);
  717. glEnable(GL_TEXTURE_2D);
  718. glBindTexture(GL_TEXTURE_2D,texture[332].glname);
  719. if (objectrender[count].type!=2 && objectrender[count].type!=10)
  720. {
  721. glBegin(GL_TRIANGLES);
  722. glColor4f(level.ambient[1][0],level.ambient[1][1],level.ambient[1][2],objectrender[count].alpha);
  723. for (count2=0;count2<objectrender[count].numoftris;count2++)
  724. {
  725. glTexCoord2fv(objectrender[count].texcoord[objectrender[count].tri[count2][0]]);
  726. setuplighttexcoord(lightcount,objectrender[count].vertex[objectrender[count].tri[count2][0]]);
  727. glVertex3fv(objectrender[count].vertex[objectrender[count].tri[count2][0]]);
  728. glTexCoord2fv(objectrender[count].texcoord[objectrender[count].tri[count2][1]]);
  729. setuplighttexcoord(lightcount,objectrender[count].vertex[objectrender[count].tri[count2][1]]);
  730. glVertex3fv(objectrender[count].vertex[objectrender[count].tri[count2][1]]);
  731. glTexCoord2fv(objectrender[count].texcoord[objectrender[count].tri[count2][2]]);
  732. setuplighttexcoord(lightcount,objectrender[count].vertex[objectrender[count].tri[count2][2]]);
  733. glVertex3fv(objectrender[count].vertex[objectrender[count].tri[count2][2]]);
  734. }
  735. glEnd();
  736. }
  737. else
  738. {
  739. glBegin(GL_QUADS);
  740. for (count2=0;count2<objectrender[count].numofedges;count2++)
  741. {
  742. subtractvectors(vec2,frame.light[lightcount].position,objectrender[count].edgevertex[count2][0]);
  743. scalevector(vec,frame.light[lightcount].color,dotproduct(vec2,objectrender[count].edgenormal[count2]));
  744. glColor4f(vec[0],vec[1],vec[2],objectrender[count].alpha);
  745. glTexCoord2fv(objectrender[count].edgetexcoord[count2][0]);
  746. setuplighttexcoord(lightcount,objectrender[count].edgevertex[count2][0]);
  747. glVertex3fv(objectrender[count].edgevertex[count2][0]);
  748. subtractvectors(vec2,frame.light[lightcount].position,objectrender[count].edgevertex[count2][1]);
  749. scalevector(vec,frame.light[lightcount].color,dotproduct(vec2,objectrender[count].edgenormal[count2]));
  750. glColor4f(vec[0],vec[1],vec[2],objectrender[count].alpha);
  751. glTexCoord2fv(objectrender[count].edgetexcoord[count2][1]);
  752. setuplighttexcoord(lightcount,objectrender[count].edgevertex[count2][1]);
  753. glVertex3fv(objectrender[count].edgevertex[count2][1]);
  754. zerovector(vec);
  755. glColor4f(vec[0],vec[1],vec[2],objectrender[count].alpha);
  756. glTexCoord2fv(objectrender[count].edgetexcoord[count2][2]);
  757. setuplighttexcoord(lightcount,objectrender[count].edgevertex[count2][2]);
  758. glVertex3fv(objectrender[count].edgevertex[count2][2]);
  759. zerovector(vec);
  760. glColor4f(vec[0],vec[1],vec[2],objectrender[count].alpha);
  761. glTexCoord2fv(objectrender[count].edgetexcoord[count2][3]);
  762. setuplighttexcoord(lightcount,objectrender[count].edgevertex[count2][3]);
  763. glVertex3fv(objectrender[count].edgevertex[count2][3]);
  764. }
  765. glEnd();
  766. }
  767. glDisable(GL_TEXTURE_2D);
  768. glActiveTextureARB(GL_TEXTURE0_ARB);
  769. }
  770. glDisable(GL_STENCIL_TEST);
  771. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  772. if (game.oldschool==2)
  773. if (objectrender[count].type==32)
  774. {
  775. glDisable(GL_TEXTURE_2D);
  776. glBegin(GL_LINES);
  777. glColor4f(0.0f,0.0f,0.0f,1.0f);
  778. glVertex3fv(particle[rope[objectrender[count].objectnum].part1].position);
  779. glVertex3fv(particle[rope[objectrender[count].objectnum].part2].position);
  780. glEnd();
  781. glEnable(GL_TEXTURE_2D);
  782. }
  783. }
  784. }
  785. }
  786. void rendersprites(void)
  787. {
  788. int count;
  789. int x,y;
  790. float vec[3];
  791. for (count=0;count<numofsprites;count++)
  792. {
  793. subtractvectors(vec,sprite[count].position,view.position);
  794. vec[0]/=view.zoom;
  795. vec[1]/=view.zoom;
  796. vec[0]*=(float)(640>>1);
  797. vec[0]+=(float)(640>>1);
  798. vec[1]*=(float)(640>>1);
  799. vec[1]=(float)(480>>1)-vec[1];
  800. x=vec[0];
  801. y=vec[1];
  802. drawtext(sprite[count].text,(x|TEXT_CENTER),(y|TEXT_CENTER),sprite[count].size,sprite[count].red,sprite[count].green,sprite[count].blue,sprite[count].alpha);
  803. }
  804. }