Пример #1
0
int nu_vertex(int vi, int ti) {
  int plaa;
  
  plaa=hashcheck(vi, ti);
  if (plaa==-666) glueErrorf("\n\nERREUR: out of hash!\n\n"); 
      
  temp_vlist[plaa]=temp_vlist_x[vi];
  temp_tlist[plaa]=temp_tlist_x[ti];  
  
  if (vertexpos>MAX_VERTS-1) glueErrorf("\n\nERREUR: out of vertexbuffer\n\n");    
  
  return plaa;
}
Пример #2
0
char *glueLoadfile(char *filename) {
    FILE *f;
    int length;
    char *data;
    int x;

    for (x=0; x<datafile_filecount; x++) {
        if (strcmp(filename, datafile_datatab[x].filename)==0) {
            f=fopen("datafile.dat", "rb");
            if (!f) glueError("error opening datafile.dat");
            fseek(f, datafile_datatab[x].start, SEEK_SET);
            data=(char *)malloc(datafile_datatab[x].len);
            fread(data, datafile_datatab[x].len, 1, f);
            fclose(f);
            return data;
        }
    }

    f=fopen(filename, "rb");
    if (!f) glueErrorf("error opening file: %s", filename);
    fseek(f, 0, SEEK_END);
    length=ftell(f);
    fseek(f, 0, SEEK_SET);
    data=(char *)malloc(length);
    fread(data, length, 1, f);
    fclose(f);

#if GLUE_DEVEL_MODE==1
    glueNoticef("loaded from disk: %s", filename);
#endif

    return data;
}
Пример #3
0
FILE *glueDatafile_pointer(char *filename) {
    FILE *f;
    int x;

    f=fopen(filename, "rb");
    if (!f) glueErrorf("error opening file: %s", filename);

    return f;
}
Пример #4
0
int glueFilelength(char *filename) {
    FILE *f;
    int x;
    int length;

    f=fopen(filename, "rb");
    if (!f) glueErrorf("error opening file: %s", filename);
    fseek(f, 0, SEEK_END);
    length=ftell(f);
    fclose(f);

    return length;
}
Пример #5
0
char *glueLoadfile(char *filename) {
    FILE *f;
    int length;
    char *data;
    int x;

    f=fopen(filename, "rb");
    if (!f) glueErrorf("error opening file: %s", filename);
    fseek(f, 0, SEEK_END);
    length=ftell(f);
    fseek(f, 0, SEEK_SET);
    data=(char *)malloc(length);
    fread(data, length, 1, f);
    fclose(f);

    return data;
}
Пример #6
0
glue_static void gluePrinterrors(void) {
    GLenum erreur;
    char *err=0;

    erreur=glGetError();
    if (erreur==GL_NO_ERROR)          err="GL_NO_ERROR";
    else if (erreur==GL_INVALID_ENUM)      err="GL_INVALID_ENUM";
    else if (erreur==GL_INVALID_VALUE)     err="GL_INVALID_VALUE";
    else if (erreur==GL_INVALID_OPERATION) err="GL_INVALID_OPERATION";
    else if (erreur==GL_STACK_OVERFLOW)    err="GL_STACK_OVERFLOW";
    else if (erreur==GL_STACK_UNDERFLOW)   err="GL_STACK_UNDERFLOW";
    else if (erreur==GL_OUT_OF_MEMORY)     err="GL_OUT_OF_MEMORY";
    //else if (erreur==GL_TABLE_TOO_LARGE)    err="GL_TABLE_TOO_LARGE";
    //else if (erreur==GL_INVALID_FRAMEBUFFER_OPERATION) err="GL_INVALID_FRAMEBUFFER_OPERATION";
    else sprintf(err, "UNKNOWN GL_ERROR #%i", erreur);

    if (erreur!=GL_NO_ERROR) glueErrorf("OpenGL error: %s", err);
//  if (erreur!=GL_NO_ERROR) glueError(err);
}
Пример #7
0
int glueFilelength(char *filename) {
    FILE *f;
    int x;
    int length;

    for (x=0; x<datafile_filecount; x++) {
        if (strcmp(filename, datafile_datatab[x].filename)==0) {
            return datafile_datatab[x].len;
        }
    }

    f=fopen(filename, "rb");
    if (!f) glueErrorf("error opening file: %s", filename);
    fseek(f, 0, SEEK_END);
    length=ftell(f);
    fclose(f);

    return length;
}
Пример #8
0
FILE *glueDatafile_pointer(char *filename) {
    FILE *f;
    int x;

    for (x=0; x<datafile_filecount; x++) {
        if (strcmp(filename, datafile_datatab[x].filename)==0) {
            f=fopen("datafile.dat", "rb");
            if (!f) glueError("error opening datafile.dat");
            fseek(f, datafile_datatab[x].start, SEEK_SET);
            return f;
        }
    }

    f=fopen(filename, "rb");
    if (!f) glueErrorf("error opening file: %s", filename);

#if GLUE_DEVEL_MODE==1
    glueNoticef("loaded from disk: %s", filename);
#endif

    return f;
}
Пример #9
0
int mergevertices(Mvert *data, int vc, int *indices, int fc) {
  int killed=0;
  int x;
  float ea=0.0;
  int ec=0;
  
  //  calc edge average
  for (x=0; x<fc; x++) {
  	int v1, v2, v3;
  	int d;

  	v1=getroot(data, indices[x*3+0], &d);
  	v2=getroot(data, indices[x*3+1], &d);
  	v3=getroot(data, indices[x*3+2], &d);
  	
   	if (v1==v2 || v2==v3 || v3==v1) {
  	  // degenerate
  	} else {
    	ea+=v_len(data[v1].pos, data[v2].pos);
  	  ea+=v_len(data[v2].pos, data[v3].pos);
  	  ea+=v_len(data[v3].pos, data[v1].pos);  		
  		ec+=3;
  	} 	
  }
  ea/=(float)ec;
  ea*=0.75; // kludge
  
  // merge
  for (x=0; x<fc; x++) {
  	int v1, v2, v3;
    int d;
    
  	v1=getroot(data, indices[x*3+0], &d);
  	v2=getroot(data, indices[x*3+1], &d);
  	v3=getroot(data, indices[x*3+2], &d);
 
#ifdef DEBUG_LODDER
    if (v1<0 || v1>=vc) glueErrorf("getroot fail v1: %i", v1);
    if (v2<0 || v2>=vc) glueErrorf("getroot fail v2: %i", v2);
    if (v3<0 || v3>=vc) glueErrorf("getroot fail v3: %i", v3);
#endif
  	
  	if (v1==v2 || v2==v3 || v3==v1) {
  	  // degenerate
  	} else {
    	float e1=v_len(data[v1].pos, data[v2].pos);
  	  float e2=v_len(data[v2].pos, data[v3].pos);
  	  float e3=v_len(data[v3].pos, data[v1].pos);

      // if one of the edges is shorter than avg*kludge, kill the shortest
      if (e1<ea || e2<ea || e3<ea) {
    		if (e1<e2 && e1<e3) {
      		data[v2].parent = v1;			
      		killed++;
  		  } else if (e2<e1 && e2<e3) {
  		    data[v3].parent = v2;  			
    		  killed++;
		    } else { // if (e3<e1 && e3<e2) {
    		  data[v1].parent = v3;		
    		  killed++;
  	    }
  	  }
  	}		
  }
  return killed;
}
Пример #10
0
Object *glueLoadOBJ(char *filename, int flags) {
  FILE *in;
  char rivi[10000];
  char subrivi[10000];
  int maxface=0;
  int x;

  Vertex *vertices=0;
  Vertex *texcoords=0;
  int *indices=0;
  int *orig_indices=0;
  int *vertexlinks=0;
  Object *obj;
  
     
  
  in=fopen(filename, "rb");
  if (!in) glueErrorf("error opening file: %s", filename); 
  size=filelength(fileno(in));
  tempbuf=malloc(size);
  fread(tempbuf, size, 1, in);
  fclose(in);

  temp_vlist_x=malloc(sizeof(vertex)*MAX_VERTS);
  temp_vlist=malloc(sizeof(vertex)*MAX_VERTS);  
  temp_flist=malloc(sizeof(face)*MAX_FACES);
  temp_tlist=malloc(sizeof(vertex)*MAX_VERTS);
  temp_tlist_x=malloc(sizeof(vertex)*MAX_VERTS);
  orig_flist=malloc(sizeof(face)*MAX_FACES);
  muthas=malloc(sizeof(int)*MAX_FACES*2);
  
  for (x=0; x<MAX_VERTS*MAX_ATTACH; x++) hasataulu[x].vi=hasataulu[x].ti=-1;


  while (1) {
    
    if (!getline(rivi)) break;
    substr(rivi, subrivi, 2);
    

    if (strcmp(subrivi, "v ")==0) {     // vertex
      float xx=0, yy=0, zz=0;

      sscanf(rivi, "v %f %f %f", &xx, &yy, &zz);

      temp_vlist_x[vertexpos_x].x=xx;
      temp_vlist_x[vertexpos_x].y=yy;
      temp_vlist_x[vertexpos_x].z=zz;
      vertexpos_x++;
      
    } else if (strcmp(subrivi, "vt")==0) {     // texcoord
      float uu=0, vv=0;

      sscanf(rivi, "vt %f %f", &uu, &vv);
      
      temp_tlist_x[texturepos_x].x=uu;
      temp_tlist_x[texturepos_x].y=vv;
      temp_tlist_x[texturepos_x].z=0;      
      texturepos_x++;
      mapped=1;
      
    } else if (strcmp(subrivi, "f ")==0) {      // face
      static int v1, v2, v3;
      static int t1, t2, t3;
      static int vv1, vv2, vv3;

      if (mapped) sscanf(rivi, "f %i/%i %i/%i %i/%i", &v1, &t1, &v2, &t2, &v3, &t3);
      else {
        sscanf(rivi, "f %i %i %i", &v1, &v2, &v3);
        t1=t2=t3=1;
      }
      
      if (v1>maxface) maxface=v1;
      if (v2>maxface) maxface=v2;
      if (v3>maxface) maxface=v3;

      vv1=nu_vertex(v1-1, t1-1);
      vv2=nu_vertex(v2-1, t2-1);
      vv3=nu_vertex(v3-1, t3-1);
      
      orig_flist[orig_fpos].v[0]=hasataulu[(v1-1)*MAX_ATTACH].newind;
      orig_flist[orig_fpos].v[1]=hasataulu[(v2-1)*MAX_ATTACH].newind;
      orig_flist[orig_fpos].v[2]=hasataulu[(v3-1)*MAX_ATTACH].newind;
      orig_fpos++;

      temp_flist[facepos].v[0]=vv1;
      temp_flist[facepos].v[1]=vv2;
      temp_flist[facepos].v[2]=vv3;
      temp_flist[facepos].used=0;
      
      facepos++;      
    } 
  }
  
  //glueNoticef("scan ok, vpos:%i  fpos:%i   tpos:%i ", vertexpos_x, facepos, texturepos_x);
  //if (mapped) glueNoticef("mapped");
  //if (vertices_splitted) glueNoticef("vertices_splitted");

  vertices=malloc(sizeof(Vertex)*vertexpos);
  for (x=0; x<vertexpos; x++) {
    vertices[x].x=temp_vlist[x].x;
    vertices[x].y=temp_vlist[x].y;
    vertices[x].z=temp_vlist[x].z;
  }
   
  if (mapped) {
    texcoords=malloc(sizeof(Vertex)*vertexpos);
    for (x=0; x<vertexpos; x++) {
      texcoords[x].x=temp_tlist[x].x;
      texcoords[x].y=temp_tlist[x].y;
      texcoords[x].z=temp_tlist[x].z;
    }
  }
  
  indices=malloc(sizeof(int)*facepos*3);
  for (x=0; x<facepos; x++) {
    indices[x*3+0]=temp_flist[x].v[0];
    indices[x*3+1]=temp_flist[x].v[1];
    indices[x*3+2]=temp_flist[x].v[2];
  }
  
  
  if (vertices_splitted) {
  
    orig_indices=malloc(sizeof(int)*orig_fpos*3);
    for (x=0; x<orig_fpos; x++) {
      orig_indices[x*3+0]=orig_flist[x].v[0];
      orig_indices[x*3+1]=orig_flist[x].v[1];
      orig_indices[x*3+2]=orig_flist[x].v[2];
    }
    
    vertexlinks=malloc(sizeof(int)*muthapos);
    for (x=0; x<muthapos; x++) vertexlinks[x]=muthas[x];
    
  }
     
  obj = glueLoadobject(
    indices, //int *indices, 
    vertices, //Vertex *vertices, 
    mapped?texcoords:0, //Vertex *texcoords, 
    0, //int *neighbours, 
    0, //Vertex *colors, 
    0, //Edge *edges, 
    vertices_splitted?orig_indices:0, //int *orig_indices, 
    vertices_splitted?vertexlinks:0, //int *vertex_links, 
    vertexpos, //int vc, 
    facepos, //int fc, 
    0, //int ec, 
    vertices_splitted?muthapos/2:0, //int linkcnt, 
    vertices_splitted?vertexpos_x:0, //int orig_vc, 
    flags); //int flgs) {


  free(tempbuf);
  free(temp_vlist_x);
  free(temp_vlist);  
  free(temp_flist);
  free(temp_tlist);
  free(temp_tlist_x);
  free(orig_flist);
  free(muthas);
  
  return obj;
    
}
Пример #11
0
void glueMpeg2_get(Mpeg2 *mpg, Texture *dst, int sync_channel, float fps, int border, int skip_frames, int reset_on_error) {
  unsigned char *tmpbuf;
  int framecnt=0;
	float curtime;
	
#ifdef USE_FMODEX
	if(sync_channel==-1) // no audio sync
		curtime = timeGetTime();
	else // get time from audio channel
		curtime = fmod_gettick_channel(sync_channel)+(1000.0/fps);
#else
  curtime = timeGetTime();
#endif

  if (mpg->end==1) {
    glueMpeg2_reset(mpg);
  }
  
  if (mpg->prevtime==0) { 
    getframe(mpg, dst); 
    if (mpg->end==2) { glueMpeg2_reset(mpg); return; }
    if (mpg->end==3) { if (reset_on_error) glueMpeg2_reset(mpg); return; }    
  } 
  else if (curtime-mpg->prevtime < 1000.0/fps) return;
  else {
    int x;
    
    framecnt=(curtime-mpg->prevtime)/(1000.0/fps);
    if (skip_frames==0 && framecnt>1) framecnt=1;
    for (x=0; x<framecnt; x++) {
      getframe(mpg, dst);
      if (mpg->end==2) { glueMpeg2_reset(mpg); return; }
      if (mpg->end==3) { if (reset_on_error) glueMpeg2_reset(mpg); return; }
    }
  }
  
  if (mpg->prevtime==0) mpg->prevtime=curtime;
  else mpg->prevtime+=1000.0/fps*framecnt;
  //mpg->prevtime=timeGetTime();
  tmpbuf=tmpmalloc(dst->xres*dst->yres*4);
  
  if (mpg->info->display_fbuf) {
    int w, h;
      
    w=mpg->info->sequence->width;
    h=mpg->info->sequence->height;  
  
    if (dst->xres==w && dst->yres==h && (!border)) {
      glueReloadtexture(dst, mpg->info->display_fbuf->buf[0]);
    } else {
      int x;
      
      memset(tmpbuf, 0, dst->xres*dst->yres*4);
     
      if (dst->xres < w || dst->yres < h) 
        glueErrorf("erreur: ur texture too small for ur videoz (%ix%i vs %ix%i)", w, h, dst->xres, dst->yres);    

      for (x=0; x<h; x++) 
        memcpy(tmpbuf+x*dst->xres*4, mpg->info->display_fbuf->buf[0]+x*w*4, dst->xres*4);

      if (border) {
        for (x=0; x<w; x++) { blask(tmpbuf, x); blask(tmpbuf, x+(h-1)*dst->xres); }
        for (x=0; x<h; x++) { blask(tmpbuf, x*dst->xres); blask(tmpbuf, x*dst->xres+w-1); }
      }
 
      dst->scale.x=(float)w/dst->xres;
      dst->scale.y=(float)h/dst->yres;

      glueReloadtexture(dst, tmpbuf);
    }
  }
  
  tmpfree(tmpbuf);

}