From 035e96ec3cf25dfa39dcdacb0f0c7b57d9d2b85a Mon Sep 17 00:00:00 2001 From: Jon Taylor Date: Sat, 21 Aug 1999 06:27:37 +0000 Subject: *** empty log message *** --- progs/ggi/asc-view.c | 353 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 progs/ggi/asc-view.c (limited to 'progs/ggi/asc-view.c') diff --git a/progs/ggi/asc-view.c b/progs/ggi/asc-view.c new file mode 100644 index 0000000000..16f53e5509 --- /dev/null +++ b/progs/ggi/asc-view.c @@ -0,0 +1,353 @@ +/* + test program for the ggi-mesa driver + + Copyright (C) 1997,1998 Uwe Maurer - uwe_maurer@t-online.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +ggi_visual_t vis,vis_mem; + +GGIMesaContext ctx; + +int screen_x=320,screen_y=200; +ggi_graphtype bpp=GT_16BIT; + +//#define ZBUFFER + +//#define SMOOTH_NORMALS + +void Init() +{ + GLfloat h=(GLfloat)3/4; + GLfloat pos[4]={5,5,-20,0}; + GLfloat specular[4]={.4,.4,.4,1}; + GLfloat diffuse[4]={.3,.3,.3,1}; + GLfloat ambient[4]={.2,.2,.2,1}; + + int err; + + if (ggiInit()<0) + { + printf("ggiInit() failed\n"); + exit(1); + } + ctx=GGIMesaCreateContext(); + if (ctx==NULL) + { + printf("Can't create Context!\n"); + exit(1); + } + + vis=ggiOpen(NULL); + vis_mem=ggiOpen("display-memory",NULL); + if (vis==NULL || vis_mem==NULL) + { + printf("Can't open ggi_visuals!\n"); + exit(1); + } + err=ggiSetGraphMode(vis,screen_x,screen_y,screen_x,screen_y,bpp); + err+=ggiSetGraphMode(vis_mem,screen_x,screen_y,screen_x,screen_y,bpp); + if (err) + { + printf("Can't set %ix%i\n",screen_x,screen_y); + exit(1); + } + + if (GGIMesaSetVisual(ctx,vis_mem,GL_TRUE,GL_FALSE)<0) + { + printf("GGIMesaSetVisual() failed!\n"); + exit(1); + } + + GGIMesaMakeCurrent(ctx); + + glViewport(0,0,screen_x,screen_y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1,1,-h,h,1,50); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0,0,-9); + glShadeModel(GL_FLAT); + + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glLightfv(GL_LIGHT0,GL_POSITION,pos); + + glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse); + glLightfv(GL_LIGHT0,GL_AMBIENT,ambient); + glLightfv(GL_LIGHT0,GL_SPECULAR,specular); + + #ifdef ZBUFFER + glEnable(GL_DEPTH_TEST); + #endif +} + + +#define MAX_VERTS 1000 +#define MAX_TRIS 2000 +#define MAX_LEN 1024 +#define MAX_F 100000000 + +void LoadAsc(GLuint *list,char *file) +{ + FILE *fp; + + GLfloat p[MAX_VERTS][3]; + GLfloat normal[MAX_VERTS][3]; + float ncount[MAX_VERTS]; + int v[MAX_TRIS][3]; + char line[MAX_LEN]; + char *s; + int i,j; + int verts,faces; + GLuint v0,v1,v2; + GLfloat n[3]; + GLfloat len,k; + GLfloat min[3]={MAX_F,MAX_F,MAX_F}; + GLfloat max[3]={-MAX_F,-MAX_F,-MAX_F}; + char *coord_str[]={"X","Z","Y"}; + + fp=fopen(file,"r"); + if (!fp) + { + printf("Can't open %s!\n",file); + exit(1); + } + + while (strncmp(fgets(line,MAX_LEN,fp),"Tri-mesh",8)) ; + + s=strstr(line,":")+1; + verts=atoi(s); + s=strstr(s,":")+1; + faces=atoi(s); + + if (verts>MAX_VERTS) + { + printf("Too many vertices..\n"); + exit(1); + } + + while (strncmp(fgets(line,MAX_LEN,fp),"Vertex list",11)) ; + + for (i=0;imax[j]) max[j]=k; + if (klen) {len=k;j=i;} + n[i]=(max[i]+min[i])/2; + } + + len/=2; + + for (i=0;iread); + rotate+=10; + frames++; + if (frames==(*maxframes)) break; + + if (ggiKbhit(vis)) + { + *maxframes=frames; + break; + } + } + + gettimeofday(&stop,NULL); + len=(double)(stop.tv_sec-start.tv_sec)+ + (double)(stop.tv_usec-start.tv_usec)/1e6; + return len; +} + + +int main(int argc,char **argv) +{ + GLuint l; + char *file; + int maxframes=0; + double len; + + Init(); + + file=(argc>1) ? argv[1] : "asc/box.asc"; + if (argc>2) maxframes=atoi(argv[2]); + + if (argc==1) + { + printf("usage: %s filename.asc\n",argv[0]); + } + + LoadAsc(&l,file); + + len=Display(l,&maxframes); + + printf("\ttime: %.3f sec\n",len); + printf("\tframes: %i\n",maxframes); + printf("\tfps: %.3f \n",(double)maxframes/len); + + GGIMesaDestroyContext(ctx); + ggiClose(vis); + ggiClose(vis_mem); + ggiExit(); + return 0; +} + -- cgit v1.2.3