Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

r_draw.cpp

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/07 19:02:04 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: r_draw.cpp,v 1.1.1.1 2002/12/07 19:02:04 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: r_draw.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:04  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00040 #include            "omicron/internal.h"
00041 #include            "omicron/render.h"
00042 #include            "omicron/texture.h"
00043 
00044 /****************************************************************************
00045  ****************************************************************************
00046  * 2D & 3D RENDERING FUNCTIONS **********************************************
00047  ****************************************************************************
00048  ****************************************************************************/
00049 
00050 /****************************************************************************
00051  ****************************************************************************
00052  * 2D FUNCTIONS *************************************************************
00053  ****************************************************************************
00054  ****************************************************************************/
00055 
00056 /****************************************************************************
00057  * renderer_c::draw_pic                                  draws a 2d picture *
00058  ****************************************************************************/
00059 void renderer_c::draw_pic
00060 ( 
00061     float           x1,                 // screen coordinates 
00062     float           y1,
00063     float           x2,
00064     float           y2,
00065     float           u1,                 // texture coordinates 
00066     float           v1,
00067     float           u2,
00068     float           v2,
00069     sshort          texture,
00070     ushort          blendtype
00071 )
00072 {
00073     AssertThis;
00074 
00075     vertex_t   verts[]=
00076     {
00077         {{  0,  0, 0 }, {{u1, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00078         {{  1,  0, 0 }, {{u2, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00079         {{  1,  1, 0 }, {{u2, v1}, {0,0}}, {0,0,-1}, state.currentcolor},
00080         {{  0,  1, 0 }, {{u1, v1}, {0,0}}, {0,0,-1}, state.currentcolor}
00081     };           // the vertex buffer 
00082  
00083     glMatrixMode(GL_MODELVIEW);
00084     glPushMatrix();
00085     glLoadIdentity();
00086 
00087     glTranslatef(x1,y1,0);
00088     glScalef((x2-x1),(y2-y1),1);
00089 
00090     // draw! 
00091     glMatrixMode(GL_TEXTURE);
00092     glLoadIdentity();
00093 
00094     set_spheremapping(false);
00095     set_blending(blendtype);
00096     set_texture_params(TF_LINEAR,TF_LINEAR,0,0);
00097     gv.texman->set(texture);
00098 
00099     use_vertices(verts, 4);
00100     push_vertices(PT_QUADS, 4);
00101 
00102     glPopMatrix();
00103 }
00104  
00105  
00106  
00107 /****************************************************************************
00108  * renderer_c::draw_pic_shader                           draws a 2d picture *
00109  ****************************************************************************/
00110 void renderer_c::draw_pic_shader 
00111 ( 
00112     float           x1,                 // screen coordinates
00113     float           y1,
00114     float           x2,
00115     float           y2,
00116     float           u1,                 // texture coordinates
00117     float           v1,
00118     float           u2,
00119     float           v2,
00120     const shader_t  *shader
00121 )
00122 {
00123     AssertThis;
00124 
00125     vertex_t   verts[]=
00126     {
00127         {{  0,  0, 0 }, {{u1, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00128         {{  1,  0, 0 }, {{u2, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00129         {{  1,  1, 0 }, {{u2, v1}, {0,0}}, {0,0,-1}, state.currentcolor},
00130         {{  0,  1, 0 }, {{u1, v1}, {0,0}}, {0,0,-1}, state.currentcolor}
00131     };           // the vertex buffer 
00132  
00133     glMatrixMode(GL_MODELVIEW);
00134     glPushMatrix();
00135     glLoadIdentity();
00136 
00137     glTranslatef(x1,y1,0);
00138     glScalef((x2-x1),(y2-y1),1);
00139 
00140     // draw! 
00141     use_shader(shader); 
00142     render_verts(verts,4,PT_QUADS); 
00143 
00144     glPopMatrix();
00145 } // _r_draw_pic_shader 
00146 
00147 
00148 
00149 /****************************************************************************
00150  * render_c::draw_rotated_pic                            draws a 2d picture *
00151  ****************************************************************************/
00152 void renderer_c::draw_rotated_pic 
00153 ( 
00154     float           angle,
00155     float           x1,                 // screen coordinates (center) 
00156     float           y1,
00157     float           w,                  // width and height 
00158     float           h,
00159     float           u1,                 // texture coordinates 
00160     float           v1,
00161     float           u2,
00162     float           v2,
00163     sshort          texture,
00164     ushort          blendtype
00165 ) 
00166 { 
00167     AssertThis;
00168 
00169     vertex_t   verts[]=
00170     {
00171         {{ -1, -1, 0 }, {{u1, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00172         {{  1, -1, 0 }, {{u2, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00173         {{  1,  1, 0 }, {{u2, v1}, {0,0}}, {0,0,-1}, state.currentcolor},
00174         {{ -1,  1, 0 }, {{u1, v1}, {0,0}}, {0,0,-1}, state.currentcolor}
00175     };           // the vertex buffer 
00176  
00177     glMatrixMode(GL_MODELVIEW);
00178     glPushMatrix();
00179     glLoadIdentity();
00180 
00181     glTranslatef(x1,y1,0);
00182     glRotatef(angle, 0, 0, 1);
00183     glScalef(w/2,h/2,1);
00184 
00185     // draw! 
00186     glMatrixMode(GL_TEXTURE);
00187     glLoadIdentity();
00188 
00189     set_spheremapping(false);
00190     set_blending(blendtype);
00191     gv.texman->set(texture);
00192 
00193     use_vertices(verts, 4);
00194     push_vertices(PT_QUADS, 4);
00195 
00196     glPopMatrix();
00197 } // _r_draw_rotated_pic 
00198 
00199 
00200 
00201 /****************************************************************************
00202  * renderer_c::draw_rotated_pic_shader                   draws a 2d picture *
00203  ****************************************************************************/
00204 void renderer_c::draw_rotated_pic_shader
00205 (
00206     float           angle,
00207     float           x1,                 // screen coordinates (center)
00208     float           y1,
00209     float           w,                  // width and height
00210     float           h,
00211     float           u1,                 // texture coordinates
00212     float           v1,
00213     float           u2,
00214     float           v2,
00215     const shader_t  *shader
00216 ) 
00217 { 
00218     AssertThis;
00219 
00220     vertex_t   verts[]=
00221     {
00222         {{ -1, -1, 0 }, {{u1, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00223         {{  1, -1, 0 }, {{u2, v2}, {0,0}}, {0,0,-1}, state.currentcolor},
00224         {{  1,  1, 0 }, {{u2, v1}, {0,0}}, {0,0,-1}, state.currentcolor},
00225         {{ -1,  1, 0 }, {{u1, v1}, {0,0}}, {0,0,-1}, state.currentcolor}
00226     };           // the vertex buffer 
00227  
00228     glMatrixMode(GL_MODELVIEW);
00229     glPushMatrix();
00230     glLoadIdentity();
00231 
00232     glTranslatef(x1,y1,0);
00233     glRotatef(angle, 0, 0, 1);
00234     glScalef(w/2,h/2,1);
00235 
00236     // draw! 
00237     use_shader(shader); 
00238     render_quad(verts); 
00239 
00240     glPopMatrix();
00241 } // _r_draw_rotated_pic_shader 
00242  
00243  
00244 /**************************************************************************** 
00245  * render_c::draw_lensflares                               draws lensflares * 
00246  ****************************************************************************/ 
00247 void renderer_c::draw_lensflares
00248 ( 
00249     const lensflare_t     *flare,         // array of flares
00250     const vec2_t    pos,
00251     ulong           count,
00252     float           intensity
00253 ) 
00254 { 
00255     AssertThis;
00256 
00257     AssertReturn3(flare, pos, count);
00258 
00259     vec3_c         p, sp; 
00260  
00261     p.set(pos[VECT_X]-gv.renderer->get_viewwidth()/2, pos[VECT_Y]-gv.renderer->get_viewheight()/2, 0 );
00262 
00263     gv.renderer->set_texture_params(TF_LINEAR_MIPMAP_LINEAR, TF_LINEAR_MIPMAP_LINEAR, TW_REPEAT, TW_REPEAT);
00264  
00265     for (ulong i=0; i<count; i++) 
00266     { 
00267         sp = p * flare[i].position; 
00268         set_blending(flare[i].blendttype); 
00269 
00270         gv.renderer->set_color(color_interpolate(0, flare[i].color, intensity));
00271 
00272         draw_rotated_pic( flare[i].angle, sp[VECT_X]+gv.renderer->get_viewwidth()/2, 
00273             sp[VECT_Y]+gv.renderer->get_viewheight()/2,  flare[i].size*intensity, flare[i].size*intensity, 
00274             0,0, 1,1, flare[i].texture, flare[i].blendttype); 
00275     } 
00276 } // _r_draw_lensflare 
00277 
00278 
00279 
00280 /****************************************************************************
00281  ****************************************************************************
00282  * 3D FUNCTIONS *************************************************************
00283  ****************************************************************************
00284  ****************************************************************************/
00285 
00286 /****************************************************************************
00287  * renderer_c::draw_billboard                             draws a billboard *
00288  ****************************************************************************/
00289 void renderer_c::draw_billboard
00290 ( 
00291     const vec3_t    pos,                // position of billboard
00292     const vec2_t    size,               // size
00293     sshort          texture,
00294     ushort          blendtype
00295 )
00296 {
00297     AssertThis;
00298     AssertReturn2(pos, size);
00299 
00300     vertex_t    verts[4];          // the vertex buffer 
00301  
00302     vec3_c      vup,vright; 
00303     float       sizeu, sizev;
00304  
00305     vup     = gv.renderer->get_viewup2()    * size[1];
00306     vright  = gv.renderer->get_viewright()  * size[0];
00307 
00308     sizeu = size[0]/2;
00309     sizev = size[1]/2;
00310 
00311     for ( ulong i=0; i<4; i++ ) 
00312     { 
00313         vec3_c tmp;
00314 
00315         tmp = pos + vright *    (QUADVERTX(i)*sizeu);
00316                 tmp = tmp + vup    *    (QUADVERTY(i)*sizev);
00317 
00318         tmp.copy(verts[i].xyz);
00319 
00320         vec2_c(NQUADVERTX(i), NQUADVERTY(i)).copy(verts[i].uv[0]);
00321         verts[i].diffuse = state.currentcolor;
00322     } 
00323  
00324     // draw! 
00325     glMatrixMode(GL_TEXTURE);
00326     glLoadIdentity();
00327 
00328     set_spheremapping(false);
00329     set_blending(blendtype);
00330     gv.texman->set(texture);
00331 
00332     use_vertices(verts, 4);
00333     push_vertices(PT_QUADS, 4);
00334 } // _r_draw_billboard 
00335  
00336  
00337  
00338  
00339 /****************************************************************************
00340  * renderer_c::draw_billboard_shader                      draws a billboard *
00341  ****************************************************************************/
00342 void renderer_c::draw_billboard_shader
00343 ( 
00344     const vec3_t    pos,                // position of billboard
00345     const vec2_t    size,               // size
00346     const shader_t  *shader 
00347 ) 
00348 {
00349     AssertThis;
00350     AssertReturn3(pos, size, shader);
00351 
00352     vertex_t   verts[4];          // the vertex buffer 
00353  
00354     vec3_c     vup,vright; 
00355     float       sizeu, sizev;
00356  
00357     vup     = gv.renderer->get_viewup2()    * size[1];
00358     vright  = gv.renderer->get_viewright()  * size[0];
00359 
00360     sizeu = size[0]/2;
00361     sizev = size[1]/2;
00362 
00363     for ( ulong i=0; i<4; i++ ) 
00364     { 
00365         vec3_c tmp;
00366 
00367         tmp = pos + vright *    (QUADVERTX(i)*sizeu);
00368                 tmp = tmp + vup    *    (QUADVERTY(i)*sizev);
00369         tmp.copy(verts[i].xyz);
00370 
00371         vec2_c(NQUADVERTX(i), NQUADVERTY(i)).copy(verts[i].uv[0]);
00372         verts[i].diffuse = state.currentcolor;
00373     } 
00374  
00375     // draw! 
00376     use_shader(shader); 
00377     render_quad(verts); 
00378 } // _r_draw_billboard 
00379  
00380    
00381    
00382 /****************************************************************************
00383  * _r_draw_rotated_billboard                              draws a billboard *
00384  ****************************************************************************/
00385 void renderer_c::draw_rotated_billboard
00386 ( 
00387     const vec3_t    pos,                // position of particle
00388     const vec2_t    size,               // size of the particle
00389     float           angle,
00390     sshort          texture,
00391     ushort          blendtype
00392 )
00393 {
00394     AssertThis;
00395     AssertReturn2(pos, size);
00396 
00397     vertex_t   verts[4];          // the vertex buffer
00398 
00399     vec3_c     vup,vright; 
00400  
00401     vup     = gv.renderer->get_viewup2();
00402     vright  = gv.renderer->get_viewright(); 
00403     
00404     vec3_t     upright[4]; 
00405  
00406     // rotated vup and vright vectors 
00407     float       rad       = (float)(-angle / 180.0f*PI); 
00408     float       radsin    = (float)(sin(rad)); 
00409     float       radcos    = (float)(cos(rad)); 
00410     vec3_c      tmp,tmp2; 
00411 
00412     for (ulong i=0; i<4; i++) 
00413     { 
00414         upright[i][0] = QUADVERTX(i)*size[0];     
00415         upright[i][1] = QUADVERTY(i)*size[1]; 
00416 
00417         tmp = upright[i];
00418  
00419         upright[i][0] = tmp[0]*radcos-tmp[1]*radsin; 
00420         upright[i][1] = tmp[0]*radsin+tmp[1]*radcos; 
00421  
00422         tmp     = vright * upright[i][0];
00423         tmp2    = vup * upright[i][1];
00424  
00425         tmp     = tmp + tmp2 + pos;
00426         tmp.copy(verts[i].xyz);
00427 
00428         // set texture coordinates 
00429         vec2_c(NQUADVERTX(i), NQUADVERTY(i)).copy(verts[i].uv[0]);
00430 
00431         verts[i].diffuse = state.currentcolor;
00432     } 
00433 
00434     // draw! 
00435     glMatrixMode(GL_TEXTURE);
00436     glLoadIdentity();
00437 
00438     set_spheremapping(false);
00439     set_blending(blendtype);
00440     gv.texman->set(texture);
00441 
00442     use_vertices(verts, 4);
00443     push_vertices(PT_QUADS, 4);
00444 } // _r_draw_rotated_billboard 
00445  
00446  
00447  
00448 /**************************************************************************** 
00449  * _r_draw_rotated_billboard_shader                       draws a billboard * 
00450  ****************************************************************************/ 
00451 void renderer_c::draw_rotated_billboard_shader 
00452 ( 
00453     const vec3_t    pos,                // position of particle
00454     const vec2_t    size,               // size of the particle
00455     float           angle,
00456     const shader_t  *shader
00457 )
00458 {
00459     AssertThis;
00460     AssertReturn3(pos, size, shader);
00461 
00462     vertex_t   verts[4];          // the vertex buffer 
00463  
00464     vec3_c     vup,vright; 
00465  
00466     vup     = gv.renderer->get_viewup2();
00467     vright  = gv.renderer->get_viewright();
00468  
00469     vec3_t     upright[4]; 
00470  
00471     // rotated vup and vright vectors 
00472     float       rad       = (float)(-angle / 180.0f*PI); 
00473     float       radsin    = (float)(sin(rad)); 
00474     float       radcos    = (float)(cos(rad)); 
00475     vec3_c     tmp,tmp2; 
00476 
00477     for (ulong i=0; i<4; i++) 
00478     { 
00479         upright[i][0] = QUADVERTX(i)*size[0];     
00480         upright[i][1] = QUADVERTY(i)*size[1]; 
00481 
00482         tmp = upright[i];
00483  
00484         upright[i][0] = tmp[0]*radcos-tmp[1]*radsin; 
00485         upright[i][1] = tmp[0]*radsin+tmp[1]*radcos; 
00486  
00487         tmp     = vright * upright[i][0];
00488         tmp2    = vup    * upright[i][1];
00489  
00490         tmp     = tmp + tmp2 + pos;
00491         tmp.copy(verts[i].xyz);
00492 
00493         // set texture coordinates 
00494         vec2_c(NQUADVERTX(i), NQUADVERTY(i)).copy(verts[i].uv[0]);
00495 
00496         verts[i].diffuse = state.currentcolor;
00497     } 
00498  
00499     // draw! 
00500     use_shader(shader);
00501     render_quad(verts);
00502 } // _r_draw_rotated_billboard_shader 
00503  
00504    
00505 /****************************************************************************
00506  * render_c::draw_particle                                 draws a particle *
00507  ****************************************************************************/
00508 /*
00509 void renderer_c::draw_particle
00510 (
00511     particle_t      *part
00512 )
00513 {
00514     AssertThis;
00515     AssertReturn1(part);
00516 
00517     vec2_t s;
00518  
00519     if (!(part->flags&PF_ACTIVE)) 
00520         return; 
00521  
00522     if (part->birthtime>gv.time) 
00523         return; 
00524  
00525     set_color_from_vec(part->color); 
00526     vector2_copy(part->size, s);
00527  
00528     float angle = 0; 
00529  
00530     if (part->flags & PF_ALIGNEDTOMOTION) 
00531     { 
00532         float x,y; 
00533  
00534         x = gv.renderer->get_viewright().dot(part->dir); 
00535         y = gv.renderer->get_viewup2().dot(part->dir); 
00536  
00537         angle = (float)(atan(x/y)/PI*180.0f); 
00538     } 
00539  
00540     draw_rotated_billboard(part->pos, s, angle+part->angle, 
00541         part->texture, part->blendtype); 
00542 } // _r_draw_particle 
00543  
00544  */
00545  
00546 /****************************************************************************
00547  * renderer_c::draw_particles                               draws particles *
00548  ****************************************************************************/
00549 /*
00550 void renderer_c::draw_particles
00551 ( 
00552     particle_t      *parts,
00553     ulong           count
00554 )
00555 {
00556     AssertThis;
00557     AssertReturn2(parts, count);
00558 
00559     for (ulong i=0; i<count; ++i)
00560         draw_particle(&parts[i]);
00561 } // _r_draw_particles 
00562 */

Generated on Wed Dec 18 15:48:47 2002 for omicron engine by doxygen1.2.18