/* 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=GGI_AUTO,screen_y=GGI_AUTO; ggi_graphtype bpp=GT_AUTO; //#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; } void visible(int vis) { if (vis == GLUT_VISIBLE) glutIdleFunc(idle); else glutIdleFunc(NULL); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowPosition(0, 0); glutInitWindowSize(300, 300); glutCreateWindow("asc-view"); init(); glutDisplayFunc(draw); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutSpecialFunc(special); glutVisibilityFunc(visible); glutMainLoop(); #if 0 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(); #endif return 0; }