static void w32_drawpattern(int x, int y, int w, unsigned char patt, GrxColor fg, GrxColor bg) { RECT Rect; GRX_ENTER(); drawpattern(x, y, w, patt, fg, bg); Rect.left = x; Rect.top = y; Rect.right = x + w; Rect.bottom = y + 1; InvalidateRect(hGRXWnd, &Rect, FALSE); GRX_LEAVE(); }
/* * main rendering loop */ static void draw(ModeInfo * mi) { boxedstruct *gp = &boxed[MI_SCREEN(mi)]; int wire = MI_IS_WIREFRAME (mi); vectorf v1,v2; GLfloat r; int dx, dz; int i; GLfloat dgray[4] = {0.3f, 0.3f, 0.3f, 1.0f}; GLfloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat lblue[4] = {0.4f,0.6f,1.0f }; GLfloat l0_ambient[] = {0.0, 0.0, 0.0, 1.0}; GLfloat l0_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat l0_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat l0_position[] = {0.0, 0.0, 0.0, 1.0}; /* w != 0 -> positional light */ GLfloat l1_ambient[] = {0.0, 0.0, 0.0, 1.0}; GLfloat l1_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat l1_diffuse[] = {0.5, 0.5, 0.5, 1.0}; GLfloat l1_position[] = {0.0, 1.0, 0.0, 0.0}; /* w = 0 -> directional light */ mi->polygon_count = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ { GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); int o = (int) current_device_rotation(); if (o != 0 && o != 180 && o != -180) glScalef (1/h, 1/h, 1/h); glRotatef(o, 0, 0, 1); } # endif gp->tic += 0.01f; gp->camtic += 0.01f + 0.01f * sin(gp->tic * speed); /* rotate camera around (0,0,0), looking at (0,0,0), up is (0,1,0) */ r = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->camtic/CAMDISTANCE_SPEED) * speed); v1.x = r * sin((gp->camtic/gp->cam_x_speed) * speed); v1.z = r * cos((gp->camtic/gp->cam_x_speed) * speed); v1.y = CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT; v2.x = LOOKAT_R * sin((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed); v2.z = LOOKAT_R * cos((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed); v2.y = (CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT)/10.0; gluLookAt(v1.x,v1.y,v1.z,v2.x,v2.y,v2.x,0.0,1.0,0.0); if (!wire) { glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular); glLightfv(GL_LIGHT0, GL_POSITION, l0_position); glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular); glLightfv(GL_LIGHT1, GL_POSITION, l1_position); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glFrontFace(GL_CW); glMaterialfv(GL_FRONT, GL_SPECULAR, black); glMaterialfv(GL_FRONT, GL_EMISSION, lblue); glMaterialfv(GL_FRONT,GL_AMBIENT,black); glMaterialf(GL_FRONT, GL_SHININESS, 5.0); } /* draw ground grid */ /* glDisable(GL_DEPTH_TEST); */ glDisable(GL_LIGHTING); glColor3f(0.1,0.1,0.6); for (dx= -2; dx<3; dx++) { for (dz= -2; dz<3; dz++) { glPushMatrix(); glTranslatef(dx*30.0f, 0.0f, dz*30.0f); drawpattern(gp); glPopMatrix(); } } /* Set drawing mode for the boxes */ glEnable(GL_DEPTH_TEST); if (!wire) glEnable(GL_TEXTURE_2D); glPushMatrix(); glColor3f(1.0,1.0,1.0); glScalef(20.0,0.25,20.0); glTranslatef(0.0,2.0,0.0); mi->polygon_count += drawfilledbox(gp, wire); glPopMatrix(); glDisable(GL_TEXTURE_2D); glPushMatrix(); glColor3f(0.2,0.5,0.2); glScalef(20.0,20.0,0.25); glTranslatef(0.0,1.0,81.0); mi->polygon_count += drawbox(gp); glPopMatrix(); glPushMatrix(); glColor3f(0.2,0.5,0.2); glScalef(20.0,20.0,0.25); glTranslatef(0.0,1.0,-81.0); mi->polygon_count += drawbox(gp); glPopMatrix(); glPushMatrix(); glColor3f(0.2,0.5,0.2); glScalef(.25,20.0,20.0); glTranslatef(-81.0,1.0,0.0); mi->polygon_count += drawbox(gp); glPopMatrix(); glPushMatrix(); glColor3f(0.2,0.5,0.2); glScalef(.25,20.0,20.0); glTranslatef(81.0,1.0,0.0); mi->polygon_count += drawbox(gp); glPopMatrix(); if (!wire) { glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT, GL_DIFFUSE, dgray); glMaterialfv(GL_FRONT, GL_EMISSION, black); /* turn it off before painting the balls */ } /* move the balls and shrapnel */ updateballs(&gp->bman); glFrontFace(GL_CCW); for (i=0;i<gp->bman.num_balls;i++) { if (gp->bman.balls[i].justcreated) { gp->bman.balls[i].justcreated = FALSE; freetris(&gp->tman[i]); } if (gp->bman.balls[i].bounced) { if (gp->tman[i].vertices == NULL) { createtrisfromball(&gp->tman[i],gp->spherev,gp->spherei,SPHERE_INDICES,&gp->bman.balls[i]); } else { updatetris(&gp->tman[i]); } glDisable(GL_CULL_FACE); mi->polygon_count += drawtriman(&gp->tman[i], wire); if (!wire) glEnable(GL_CULL_FACE); } else { mi->polygon_count += drawball(gp, &gp->bman.balls[i], wire); } } glFlush(); }