Difference for arch/ogl/ogl.c from version 1.8 to 1.9


version 1.8 version 1.9
Line 23
 
Line 23
 #include "polyobj.h"  #include "polyobj.h"
   
   
   int GL_texmagfilt=GL_NEAREST;
   int GL_texminfilt=GL_NEAREST;
   int GL_needmipmaps=0;
   
 int last_width=-1,last_height=-1;  int last_width=-1,last_height=-1;
 int GL_TEXTURE_2D_enabled=-1;  int GL_TEXTURE_2D_enabled=-1;
 int GL_texclamp_enabled=-1;  int GL_texclamp_enabled=-1;
   int GL_TEXTURE_ENV_MODE_state=-1,GL_TEXTURE_MAG_FILTER_state=-1,GL_TEXTURE_MIN_FILTER_state=-1;
   
 //crude texture precaching  //crude texture precaching
 //handles: powerups, walls, weapons, polymodels, etc.  //handles: powerups, walls, weapons, polymodels, etc.
Line 305
 
Line 310
   
  return 0;   return 0;
 }  }
 bool ogl_ubitmapm(int x, int y,grs_bitmap *bm)  bool ogl_ubitmapm_c(int x, int y,grs_bitmap *bm,int c)
 {  {
  GLfloat xo,yo,xs,ys;   GLfloat xo,yo,xs,ys;
  r_ubitmapc++;   r_ubitmapc++;
Line 331
 
Line 336
  OGL_TEXCLAMP();   OGL_TEXCLAMP();
   
  glBegin(GL_QUADS);   glBegin(GL_QUADS);
  glColor3f(1.5,1.5,1.5);   if (c<0)
    glColor3f(1.0,1.0,1.0);
    else
    glColor3f(PAL2Tr(c),PAL2Tg(c),PAL2Tb(c));
  glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo);   glTexCoord2f(0.0, 0.0); glVertex2f(xo, yo);
  glTexCoord2f(bm->glu, 0.0); glVertex2f(xo+xs, yo);   glTexCoord2f(bm->glu, 0.0); glVertex2f(xo+xs, yo);
  glTexCoord2f(bm->glu, bm->glv); glVertex2f(xo+xs, yo-ys);   glTexCoord2f(bm->glu, bm->glv); glVertex2f(xo+xs, yo-ys);
Line 342
 
Line 350
    
  return 0;   return 0;
 }  }
   bool ogl_ubitmapm(int x, int y,grs_bitmap *bm){
    return ogl_ubitmapm_c(x,y,bm,-1);
   }
   
 void ogl_start_frame(void){  void ogl_start_frame(void){
  r_polyc=0;r_tpolyc=0;r_bitmapc=0;r_ubitmapc=0;   r_polyc=0;r_tpolyc=0;r_bitmapc=0;r_ubitmapc=0;
Line 361
 
Line 372
  glLoadIdentity();//clear matrix   glLoadIdentity();//clear matrix
  glEnable(GL_BLEND);   glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glDisable(GL_DITHER);  // glDisable(GL_DITHER);
 // glScalef(1.0,1.0,-1.0);  // glScalef(1.0,1.0,-1.0);
 // glScalef(1.0,1.0,-1.0);  // glScalef(1.0,1.0,-1.0);
 // glPushMatrix();  // glPushMatrix();
   
   // glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    OGL_TEXENV(GL_TEXTURE_ENV_MODE,GL_MODULATE);
    //TODO: make texturing mode an (ingame?) option
   // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_texmagfilt);
   // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_texminfilt);
    OGL_TEXPARAM(GL_TEXTURE_MAG_FILTER,GL_texmagfilt);
    OGL_TEXPARAM(GL_TEXTURE_MIN_FILTER,GL_texminfilt);
 }  }
 void ogl_end_frame(void){  void ogl_end_frame(void){
   
Line 396
 
Line 415
 //In theory this could be a problem for repeating textures, but all real  //In theory this could be a problem for repeating textures, but all real
 //textures (not sprites, etc) in descent are 64x64, so we are ok.  //textures (not sprites, etc) in descent are 64x64, so we are ok.
 //stores OpenGL textured id in *texid and u/v values required to get only the real data in *u/*v  //stores OpenGL textured id in *texid and u/v values required to get only the real data in *u/*v
 void ogl_loadtexture(unsigned char * data, int width, int height, int *texid,float *u,float *v){  void ogl_loadtexture(unsigned char * data, int width, int height, int *texid,float *u,float *v,int domipmap){
  int x,y,c,i;   int x,y,c,i;
  GLubyte *texp=texbuf;   GLubyte *texp=texbuf;
  int twidth=pow2ize(width),theight=pow2ize(height);//calculate smallest texture size that can accomodate us (must be multiples of 2)   int twidth=pow2ize(width),theight=pow2ize(height);//calculate smallest texture size that can accomodate us (must be multiples of 2)
Line 431
 
Line 450
  }   }
  }   }
    
 // glEnable(GL_TEXTURE_2D);  
 // glPixelStorei(GL_UNPACK_ALIGNMENT, 1);  
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);  
  //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  
   
  // Generate OpenGL texture IDs.   // Generate OpenGL texture IDs.
  glGenTextures(1, texid);   glGenTextures(1, texid);
   
Line 443
 
Line 457
   
  glBindTexture(GL_TEXTURE_2D, *texid);   glBindTexture(GL_TEXTURE_2D, *texid);
   
 //TODO: make texturing mode an option  // domipmap=0;//mipmaps aren't used in GL_NEAREST anyway, and making the mipmaps is pretty slow
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);   //however, if texturing mode becomes an ingame option, they would need to be made regardless, so it could switch to them later.  OTOH, texturing mode could just be made a command line arg.
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);  
 //    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  
 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  
 //  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);  
 //  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);  
 //  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);  
 //  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);  
   
 /* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, // RGBA textures.   if (domipmap && GL_needmipmaps)
  width, height, 0, GL_RGBA,  
  GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer.  
  texbuf);*/  
  gluBuild2DMipmaps( GL_TEXTURE_2D, 4, twidth,   gluBuild2DMipmaps( GL_TEXTURE_2D, 4, twidth,
  theight, GL_RGBA, GL_UNSIGNED_BYTE, texbuf);   theight, GL_RGBA, GL_UNSIGNED_BYTE, texbuf);
    else
    glTexImage2D(GL_TEXTURE_2D, 0, 4,
    twidth, theight, 0, GL_RGBA, // RGBA textures.
    GL_UNSIGNED_BYTE, // imageData is a GLubyte pointer.
    texbuf);
  r_texcount++;   r_texcount++;
  mprintf((0,"ogl_loadtexture(%p,%i,%i,%p):%i u=%f v=%f (%i)\n",data,twidth,theight,texid,*texid,*u,*v,r_texcount));   mprintf((0,"ogl_loadtexture(%p,%i,%i,%p):%i u=%f v=%f (%i)\n",data,twidth,theight,texid,*texid,*u,*v,r_texcount));
   
 }  }
 unsigned char decodebuf[512*512];  unsigned char decodebuf[512*512];
 void ogl_loadbmtexture(grs_bitmap *bm){  void ogl_loadbmtexture_m(grs_bitmap *bm,int domipmap){
  unsigned char *buf=bm->bm_data;   unsigned char *buf=bm->bm_data;
  if (bm->gltexture>=0)   if (bm->gltexture>=0)
  return;   return;
Line 482
 
Line 491
  }   }
  buf=decodebuf;   buf=decodebuf;
  }   }
  ogl_loadtexture(buf,bm->bm_w,bm->bm_h,&bm->gltexture,&bm->glu,&bm->glv);   ogl_loadtexture(buf,bm->bm_w,bm->bm_h,&bm->gltexture,&bm->glu,&bm->glv,domipmap);
   }
   void ogl_loadbmtexture(grs_bitmap *bm){
    ogl_loadbmtexture_m(bm,1);
 }  }
 void ogl_freebmtexture(grs_bitmap *bm){  void ogl_freebmtexture(grs_bitmap *bm){
  if (bm->gltexture>=0){   if (bm->gltexture>=0){

Legend:
line(s) removed in v.1.8 
line(s) changed
 line(s) added in v.1.9