2
test program for the ggi-mesa driver
4
Copyright (C) 1997,1998 Uwe Maurer - uwe_maurer@t-online.de
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
#include <GL/ggimesa.h>
30
ggi_visual_t vis,vis_mem;
34
int screen_x=GGI_AUTO,screen_y=GGI_AUTO;
35
ggi_graphtype bpp=GT_AUTO;
39
//#define SMOOTH_NORMALS
43
GLfloat h=(GLfloat)3/4;
44
GLfloat pos[4]={5,5,-20,0};
45
GLfloat specular[4]={.4,.4,.4,1};
46
GLfloat diffuse[4]={.3,.3,.3,1};
47
GLfloat ambient[4]={.2,.2,.2,1};
53
printf("ggiInit() failed\n");
56
ctx=GGIMesaCreateContext();
59
printf("Can't create Context!\n");
64
vis_mem=ggiOpen("display-memory",NULL);
65
if (vis==NULL || vis_mem==NULL)
67
printf("Can't open ggi_visuals!\n");
70
err=ggiSetGraphMode(vis,screen_x,screen_y,screen_x,screen_y,bpp);
71
err+=ggiSetGraphMode(vis_mem,screen_x,screen_y,screen_x,screen_y,bpp);
74
printf("Can't set %ix%i\n",screen_x,screen_y);
78
if (GGIMesaSetVisual(ctx,vis_mem,GL_TRUE,GL_FALSE)<0)
80
printf("GGIMesaSetVisual() failed!\n");
84
GGIMesaMakeCurrent(ctx);
86
glViewport(0,0,screen_x,screen_y);
87
glMatrixMode(GL_PROJECTION);
89
glFrustum(-1,1,-h,h,1,50);
90
glMatrixMode(GL_MODELVIEW);
93
glShadeModel(GL_FLAT);
96
glEnable(GL_CULL_FACE);
97
glEnable(GL_LIGHTING);
100
glLightfv(GL_LIGHT0,GL_POSITION,pos);
102
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
103
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
104
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
107
glEnable(GL_DEPTH_TEST);
112
#define MAX_VERTS 1000
113
#define MAX_TRIS 2000
115
#define MAX_F 100000000
117
void LoadAsc(GLuint *list,char *file)
121
GLfloat p[MAX_VERTS][3];
122
GLfloat normal[MAX_VERTS][3];
123
float ncount[MAX_VERTS];
132
GLfloat min[3]={MAX_F,MAX_F,MAX_F};
133
GLfloat max[3]={-MAX_F,-MAX_F,-MAX_F};
134
char *coord_str[]={"X","Z","Y"};
139
printf("Can't open %s!\n",file);
143
while (strncmp(fgets(line,MAX_LEN,fp),"Tri-mesh",8)) ;
145
s=strstr(line,":")+1;
152
printf("Too many vertices..\n");
156
while (strncmp(fgets(line,MAX_LEN,fp),"Vertex list",11)) ;
158
for (i=0;i<verts;i++)
160
while (strncmp(fgets(line,MAX_LEN,fp),"Vertex",6)) ;
163
s=strstr(line,coord_str[j])+2;
165
if (k>max[j]) max[j]=k;
166
if (k<min[j]) min[j]=k;
175
if (k>len) {len=k;j=i;}
176
n[i]=(max[i]+min[i])/2;
181
for (i=0;i<verts;i++)
191
glNewList(*list,GL_COMPILE);
192
glBegin(GL_TRIANGLES);
194
memset(ncount,0,sizeof(ncount));
195
memset(normal,0,sizeof(normal));
197
while (strncmp(fgets(line,MAX_LEN,fp),"Face list",9)) ;
198
for (i=0;i<faces;i++)
200
while (strncmp(fgets(line,MAX_LEN,fp),"Face",4)) ;
201
s=strstr(line,"A")+2;
203
s=strstr(line,"B")+2;
205
s=strstr(line,"C")+2;
207
n[0]=((p[v1][1]-p[v0][1])*(p[v2][2]-p[v0][2])
208
- (p[v1][2]-p[v0][2])*(p[v2][1]-p[v0][1]));
209
n[1]=((p[v1][2]-p[v0][2])*(p[v2][0]-p[v0][0])
210
- (p[v1][0]-p[v0][0])*(p[v2][2]-p[v0][2]));
211
n[2]=((p[v1][0]-p[v0][0])*(p[v2][1]-p[v0][1])
212
- (p[v1][1]-p[v0][1])*(p[v2][0]-p[v0][0]));
213
len=n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
218
#ifdef SMOOTH_NORMALS
220
normal[v[i][j]][0]+=n[0];
221
normal[v[i][j]][1]+=n[1];
222
normal[v[i][j]][2]+=n[2];
228
glVertex3fv(p[v[i][j]]);
232
#ifdef SMOOTH_NORMALS
233
for (i=0;i<verts;i++) {
235
normal[i][j]/=ncount[i];
238
for (i=0;i<faces;i++) {
240
glNormal3f(normal[v[i][j]][0],
243
glVertex3fv(p[v[i][j]]);
253
double Display(GLuint l,int *maxframes)
256
GLfloat col[]={.25,0,.25,1};
258
struct timeval start,stop;
262
gettimeofday(&start,NULL);
267
glClearColor(0,0,0,0);
271
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
273
glClear(GL_COLOR_BUFFER_BIT);
279
glRotatef(rotate/10,0,0,1);
280
glTranslatef(-6,-4,0);
287
glRotatef(rotate,y+1,-x-1,0);
289
col[0]=(GLfloat)(x+1)/4;
291
col[2]=(GLfloat)(y+1)/2;
292
glMaterialfv(GL_FRONT,GL_AMBIENT,col);
303
ggiPutBox(vis,0,0,screen_x,screen_y,ggiDBGetBuffer(vis,0)->read);
306
if (frames==(*maxframes)) break;
315
gettimeofday(&stop,NULL);
316
len=(double)(stop.tv_sec-start.tv_sec)+
317
(double)(stop.tv_usec-start.tv_usec)/1e6;
321
void visible(int vis)
323
if (vis == GLUT_VISIBLE)
329
int main(int argc, char *argv[])
331
glutInit(&argc, argv);
332
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
334
glutInitWindowPosition(0, 0);
335
glutInitWindowSize(300, 300);
336
glutCreateWindow("asc-view");
339
glutDisplayFunc(draw);
340
glutReshapeFunc(reshape);
341
glutKeyboardFunc(key);
342
glutSpecialFunc(special);
343
glutVisibilityFunc(visible);
354
file=(argc>1) ? argv[1] : "asc/box.asc";
355
if (argc>2) maxframes=atoi(argv[2]);
359
printf("usage: %s filename.asc\n",argv[0]);
364
len=Display(l,&maxframes);
366
printf("\ttime: %.3f sec\n",len);
367
printf("\tframes: %i\n",maxframes);
368
printf("\tfps: %.3f \n",(double)maxframes/len);
370
GGIMesaDestroyContext(ctx);