home *** CD-ROM | disk | FTP | other *** search
/ Launch & Play / spustahrej2.iso / Egoboo / code / graphicfan.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-03  |  12.2 KB  |  374 lines

  1. // Egoboo, Copyright (C) 2000 Aaron Bishop
  2.  
  3. #include "egoboo.h"
  4.  
  5. //--------------------------------------------------------------------------------------------
  6. void render_fan(unsigned int fan)
  7. {
  8.     // ZZ> This function draws a mesh fan
  9.     //D3DLVERTEX v[MAXMESHVERTICES];
  10.     //D3DTLVERTEX vt[MAXMESHVERTICES];
  11.     //D3DTLVERTEX vtlist[MAXMESHCOMMANDSIZE];
  12.     GLVERTEX v[MAXMESHVERTICES];    
  13.     Uint16 commands;
  14.     Uint16 vertices;
  15.     Uint16 basetile;
  16.     Uint16 texture;
  17.     Uint16 cnt, tnc, entry, vertex;
  18.     Uint32 badvertex;
  19. //    unsigned char red, grn, blu;
  20.     float offu, offv;
  21. //    float z;
  22.     //DWORD ambi;
  23. //    DWORD fogspec;
  24.  
  25.  
  26.     // vertex is a value from 0-15, for the meshcommandref/u/v variables
  27.     // badvertex is a value that references the actual vertex number
  28.  
  29.     Uint16 tile = meshtile[fan];               // Tile
  30.     Uint8 fx = meshfx[fan];                   // Fx bits
  31.     Uint16 type = meshtype[fan];               // Command type ( index to points in fan )
  32.  
  33.        if (tile == FANOFF)
  34.         return;
  35.  
  36.     // Animate the tiles
  37.     if (fx & MESHFXANIM)
  38.     {
  39.         if(type >= (MAXMESHTYPE>>1))
  40.         {
  41.             // Big tiles
  42.             basetile = tile & biganimtilebaseand;// Animation set
  43.             tile += animtileframeadd << 1;         // Animated tile
  44.             tile = (tile & biganimtileframeand) + basetile;
  45.         }
  46.         else
  47.         {
  48.             // Small tiles
  49.             basetile = tile & animtilebaseand;// Animation set
  50.             tile += animtileframeadd;         // Animated tile
  51.             tile = (tile & animtileframeand) + basetile;
  52.         }
  53.     }
  54.     offu = meshtileoffu[tile];          // Texture offsets
  55.     offv = meshtileoffv[tile];          //
  56.  
  57.     texture = (tile>>6)+1;                  // 64 tiles in each 256x256 texture
  58.     vertices = meshcommandnumvertices[type];// Number of vertices
  59.     commands = meshcommands[type];          // Number of commands
  60.  
  61.     // Original points
  62.     badvertex = meshvrtstart[fan];          // Get big reference value
  63.  
  64.                                             
  65.     //[claforte] Put this in an initialization function.
  66.     glEnableClientState(GL_VERTEX_ARRAY);
  67. //    glEnableClientState(GL_COLOR_ARRAY);
  68. //    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  69.  
  70.     glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*7 + 4, &v[0].x);
  71.     glTexCoordPointer(2, GL_FLOAT, sizeof(GLVERTEX)-2*sizeof(GLfloat), &v[0].s);
  72.     // glColorPointer... not needed?
  73.                                             
  74. /*  if(fogon)
  75.     {
  76.         // The full fog value
  77.         fogspec = 0xff000000 | (fogred<<16) | (foggrn<<8) | (fogblu);
  78.         for (cnt = 0; cnt < vertices; cnt++)
  79.         {
  80.             v[cnt].x = (D3DVALUE) meshvrtx[badvertex];
  81.             v[cnt].y = (D3DVALUE) meshvrty[badvertex];
  82.             v[cnt].z = (D3DVALUE) meshvrtz[badvertex];
  83.             z = v[cnt].z;
  84.  
  85.  
  86.             // Figure out the fog coloring
  87.             if(z < fogtop)
  88.             {
  89.                 if(z < fogbottom)
  90.                 {
  91.                     v[cnt].dcSpecular = fogspec;  // Full fog
  92.                 }
  93.                 else
  94.                 {
  95.                     z = 1.0 - ((z - fogbottom)/fogdistance);  // 0.0 to 1.0... Amount of fog to keep
  96.                     red = (fogred * z);
  97.                     grn = (foggrn * z);
  98.                     blu = (fogblu * z);
  99.                     ambi = 0xff000000 | (red<<16) | (grn<<8) | (blu);
  100.                     v[cnt].dcSpecular = ambi;
  101.                 }
  102.             }
  103.             else
  104.             {
  105.                 v[cnt].dcSpecular = 0;  // No fog
  106.             }
  107.  
  108.             ambi = (DWORD) meshvrtl[badvertex];
  109.             ambi = (ambi<<8)|ambi;
  110.             ambi = (ambi<<8)|ambi;
  111. //                v[cnt].dcColor = ambi;
  112. //                v[cnt].dwReserved = 0;
  113.             badvertex++;
  114.         }
  115.     }
  116.     else
  117. */
  118.     {
  119.         for (cnt = 0; cnt < vertices; cnt++)
  120.         {
  121. //                v[cnt].x = (D3DVALUE) meshvrtx[badvertex];
  122. //                v[cnt].y = (D3DVALUE) meshvrty[badvertex];
  123. //                v[cnt].z = (D3DVALUE) meshvrtz[badvertex];
  124.             v[cnt].x = (float) meshvrtx[badvertex];
  125.             v[cnt].y = (float) meshvrty[badvertex];
  126.             v[cnt].z = (float) meshvrtz[badvertex];
  127.             v[cnt].r = v[cnt].g = v[cnt].b = (float)meshvrtl[badvertex] / 255.0f;
  128.             v[cnt].s = meshcommandu[type][badvertex] + offu;
  129.             v[cnt].t = meshcommandv[type][badvertex] + offv;
  130.             //ambi = (DWORD) meshvrtl[badvertex];
  131.             //ambi = (ambi<<8)|ambi;
  132.             //ambi = (ambi<<8)|ambi;
  133.             //v[cnt].dcColor = ambi;
  134.             //v[cnt].dcSpecular = 0;  // No fog
  135.             //v[cnt].dwReserved = 0;
  136.             badvertex++;
  137.         }
  138.     }
  139.  
  140. // GS - Begin3DMode ();
  141.     // Change texture if need be
  142.     if(meshlasttexture != texture)
  143.     {
  144. //            lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE,
  145. //                      txTexture[texture].GetHandle());
  146.         glBindTexture ( GL_TEXTURE_2D, GLTexture_GetTextureID( &txTexture[texture] ));
  147.         meshlasttexture = texture;
  148.     }
  149.  
  150.     // Make new ones so we can index them and not transform 'em each time
  151.     //if(transform_vertices(vertices, v, vt))
  152.       //  return;
  153.  
  154.  
  155.     // Render each command
  156.     entry = 0;
  157.     for (cnt = 0; cnt < commands; cnt++)
  158.     {
  159.         glBegin (GL_TRIANGLE_FAN);
  160.         for (tnc = 0; tnc < meshcommandsize[type][cnt]; tnc++)
  161.         {
  162.             vertex = meshcommandvrt[type][entry];
  163.             glColor3fv( &v[vertex].r );
  164.             glTexCoord2f ( meshcommandu[type][vertex]+offu, meshcommandv[type][vertex]+offv);
  165.             glVertex3fv ( &v[vertex].x );
  166.             
  167. //            vtlist[tnc].dvSX = vt[vertex].dvSX;
  168. //            vtlist[tnc].dvSY = vt[vertex].dvSY;
  169. //            vtlist[tnc].dvSZ = vt[vertex].dvSZ;
  170. //            vtlist[tnc].dvRHW = vt[vertex].dvRHW;
  171. //            vtlist[tnc].dcColor = vt[vertex].dcColor;
  172. //            vtlist[tnc].dcSpecular = vt[vertex].dcSpecular;
  173. //            vtlist[tnc].dvTU = meshcommandu[type][vertex]+offu;
  174. //            vtlist[tnc].dvTV = meshcommandv[type][vertex]+offv;
  175.     
  176.             entry++;
  177.         }
  178.         glEnd();
  179. //            lpD3DDDevice->DrawPrimitive((D3DPRIMITIVETYPE) D3DPT_TRIANGLEFAN,
  180. //                                    D3DVT_TLVERTEX, (LPVOID)vtlist, tnc, NULL);
  181.     }
  182.  
  183.     // GS - End3DMode ();
  184. }
  185.  
  186. //--------------------------------------------------------------------------------------------
  187. void render_water_fan(unsigned int fan, unsigned char layer, unsigned char mode)
  188. {
  189.     // ZZ> This function draws a water fan
  190.     GLVERTEX v[MAXMESHVERTICES];    
  191.     Uint16 type;
  192.     Uint16 commands;
  193.     Uint16 vertices;
  194.     Uint16 texture, frame;
  195.     Uint16 cnt, tnc, entry, vertex;
  196.     Uint32 badvertex;
  197. //    unsigned char red, grn, blu;
  198.     float offu, offv;
  199. //    float z;
  200.     DWORD ambi;
  201. //    DWORD fogspec;
  202.  
  203.     // vertex is a value from 0-15, for the meshcommandref/u/v variables
  204.     // badvertex is a value that references the actual vertex number
  205.  
  206.  
  207.     // To make life easier
  208.     type = 0;                           // Command type ( index to points in fan )
  209.     offu = waterlayeru[layer];          // Texture offsets
  210.     offv = waterlayerv[layer];          //
  211.     frame = waterlayerframe[layer];     // Frame
  212.  
  213.     texture = layer+5;                      // Water starts at texture 5
  214.     vertices = meshcommandnumvertices[type];// Number of vertices
  215.     commands = meshcommands[type];          // Number of commands
  216.  
  217.  
  218.     // Original points
  219.     badvertex = meshvrtstart[fan];          // Get big reference value
  220.     // Corners
  221.     /*
  222.     if(fogon)
  223.     {
  224.         // The full fog value
  225.         fogspec = 0xff000000 | (fogred<<16) | (foggrn<<8) | (fogblu);
  226.         for (cnt = 0; cnt < vertices; cnt++)
  227.         {
  228.             v[cnt].x = (D3DVALUE) meshvrtx[badvertex];
  229.             v[cnt].y = (D3DVALUE) meshvrty[badvertex];
  230.             v[cnt].z = waterlayerzadd[layer][frame][mode][cnt]+waterlayerz[layer];
  231.             z = v[cnt].z;
  232.             ambi = (DWORD) meshvrtl[badvertex]>>1;
  233.             ambi+= waterlayercolor[layer][frame][mode][cnt];
  234.             ambi = (ambi<<8)|ambi;
  235.             ambi = (ambi<<8)|ambi;
  236.             ambi = (waterlayeralpha[layer]<<24)|ambi;
  237.             v[cnt].dcColor = ambi;
  238.  
  239.  
  240.             // Figure out the fog coloring
  241.             if(z < fogtop && fogaffectswater)
  242.             {
  243.                 if(z < fogbottom)
  244.                 {
  245.                     v[cnt].dcSpecular = fogspec;  // Full fog
  246.                 }
  247.                 else
  248.                 {
  249.                     spectokeep = ((z - fogbottom)/fogdistance);  // 0.0 to 1.0... Amount of old to keep
  250.                     z = 1.0 - spectokeep;  // 0.0 to 1.0... Amount of fog to keep
  251.                     spek = waterspek[ambi&255]&255;
  252.                     spek = spek * spectokeep;
  253.                     red = (fogred * z) + spek;
  254.                     grn = (foggrn * z) + spek;
  255.                     blu = (fogblu * z) + spek;
  256.                     ambi = 0xff000000 | (red<<16) | (grn<<8) | (blu);
  257.                     v[cnt].dcSpecular = ambi;
  258.                 }
  259.             }
  260.             else
  261.             {
  262.                 v[cnt].dcSpecular = waterspek[ambi&255];  // Old spec
  263.             }
  264.  
  265.             v[cnt].dwReserved = 0;
  266.             badvertex++;
  267.         }
  268.     }
  269.     else
  270.     */
  271.     {
  272.         for (cnt = 0; cnt < vertices; cnt++)
  273.         {
  274.             
  275.             //v[cnt].x = (D3DVALUE) meshvrtx[badvertex];
  276.             //v[cnt].y = (D3DVALUE) meshvrty[badvertex];
  277.             //v[cnt].z = waterlayerzadd[layer][frame][mode][cnt]+waterlayerz[layer];
  278.             v[cnt].x = meshvrtx[badvertex];
  279.             v[cnt].y = meshvrty[badvertex];
  280.             v[cnt].z = waterlayerzadd[layer][frame][mode][cnt]+waterlayerz[layer];
  281.             
  282.             ambi = (DWORD) meshvrtl[badvertex]>>1;
  283.             ambi+= waterlayercolor[layer][frame][mode][cnt];
  284.             v[cnt].r = v[cnt].g = v[cnt].b = (float)ambi / 255.0f;
  285.             /*
  286.             ambi = (ambi<<8)|ambi;
  287.             ambi = (ambi<<8)|ambi;
  288.             */
  289.             v[cnt].a = (float)waterlayeralpha[layer] / 255.0f;
  290.             
  291. // !!!BAD!!!  Debug code for show what mode means...
  292. //red = 50;
  293. //grn = 50;
  294. //blu = 50;
  295. //switch(mode)
  296. //{
  297. //    case 0:
  298. //      red = 255;
  299. //      break;
  300. //    case 1:
  301. //      grn = 255;
  302. //      break;
  303. //    case 2:
  304. //      blu = 255;
  305. //      break;
  306. //    case 3:
  307. //      red = 255;
  308. //      grn = 255;
  309. //      blu = 255;
  310. //      break;
  311. //}
  312. //ambi = 0xbf000000 | (red<<16) | (grn<<8) | (blu);
  313. // !!!BAD!!!
  314.  
  315.             //v[cnt].dcColor = ambi;
  316.             //v[cnt].dcSpecular = waterspek[ambi&255];
  317.             //v[cnt].dwReserved = 0;
  318.             badvertex++;
  319.         }
  320.     }
  321.  
  322.  
  323.     // Change texture if need be
  324.     if(meshlasttexture != texture)
  325.     {
  326.         //lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE,
  327.         //          txTexture[texture].GetHandle());
  328.         glBindTexture ( GL_TEXTURE_2D, GLTexture_GetTextureID( &txTexture[texture] ));
  329.         meshlasttexture = texture;
  330.     }
  331.  
  332.  
  333.  
  334.     // Make new ones so we can index them and not transform 'em each time
  335.     //if(transform_vertices(vertices, v, vt))
  336.     //    return;
  337.  
  338.  
  339.     // Render each command
  340.     entry = 0;
  341.     v[0].s = 1+offu;
  342.     v[0].t = 0+offv;
  343.     v[1].s = 1+offu;
  344.     v[1].t = 1+offv;
  345.     v[2].s = 0+offu;
  346.     v[2].t = 1+offv;
  347.     v[3].s = 0+offu;
  348.     v[3].t = 0+offv;
  349.     for (cnt = 0; cnt < commands; cnt++)
  350.     {
  351.         glBegin (GL_TRIANGLE_FAN);
  352.             for (tnc = 0; tnc < meshcommandsize[type][cnt]; tnc++)
  353.             {
  354.                 vertex = meshcommandvrt[type][entry];
  355.                 glColor4fv( &v[vertex].r );
  356.                 glTexCoord2fv ( &v[vertex].s );
  357.                 glVertex3fv ( &v[vertex].x );
  358.         /*
  359.                 vtlist[tnc].dvSX = vt[vertex].dvSX;
  360.                 vtlist[tnc].dvSY = vt[vertex].dvSY;
  361.                 vtlist[tnc].dvSZ = vt[vertex].dvSZ;
  362.                 vtlist[tnc].dvRHW = vt[vertex].dvRHW;
  363.                 vtlist[tnc].dcColor = vt[vertex].dcColor;
  364.                 vtlist[tnc].dcSpecular = vt[vertex].dcSpecular;
  365.                 vtlist[tnc].dvTU = meshcommandu[type][vertex]+offu;
  366.                 vtlist[tnc].dvTV = meshcommandv[type][vertex]+offv;
  367.         */
  368.                 entry++;
  369.             }
  370.         glEnd ();
  371. //            lpD3DDDevice->DrawPrimitive((D3DPRIMITIVETYPE) D3DPT_TRIANGLEFAN,
  372. //                                    D3DVT_TLVERTEX, (LPVOID)vtlist, tnc, NULL);
  373.     }
  374. }