void MapViewer::render() { CHECK_NOTNULL(map); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render_map(); render_objects(false); render_sprites(); render_objects(true); render_gui(); }
int main() { SDL_Window* win; // initialize SDL if(SDL_Init(SDL_INIT_EVERYTHING) != 0) { fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError()); } // initialize window and renderer if(SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &win, &ren) != 0) { fprintf(stderr, "\nUnable to intialize window: %s\n", SDL_GetError()); } init_physics(); // main lopp for(;;) { Uint32 t = SDL_GetTicks() + 1000/60; // physics step update_friction(0); update_drive(); update_turn(); cpSpaceStep(space, 1.0/60.0); debug_physics(); // events SDL_Event e; while(SDL_PollEvent(&e)) { switch(e.type) { case SDL_QUIT: exit(0); break; } } const Uint8* k = SDL_GetKeyboardState(NULL); controls.forward = k[SDL_SCANCODE_UP]; controls.back = k[SDL_SCANCODE_DOWN]; controls.left = k[SDL_SCANCODE_LEFT]; controls.right = k[SDL_SCANCODE_RIGHT]; // render SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); SDL_RenderClear(ren); SDL_SetRenderDrawColor(ren, 0, 0, 0, 255); render_objects(); SDL_RenderPresent(ren); // time if(SDL_GetTicks() < t) { SDL_Delay(t - SDL_GetTicks()); } } return 0; }
void render_draw(r_context_t *c) { c->r_leafcount = 0; /* Find eye cluster for PVS checks. Now in uicommon.c if (!(g->r_lockpvs)) c->r_eyecluster = find_cluster(c->r_eyepos); */ if (g->r_setup_projection) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } /* Set up camera - old way gluLookAt(g->r_eyepos[0], g->r_eyepos[1], g->r_eyepos[2], g->r_eyepos[0]+g->r_movedir[0], g->r_eyepos[1]+g->r_movedir[1], g->r_eyepos[2]+g->r_movedir[2], 0.0, 0.0, 1.0); */ glPushMatrix(); // Rotate the camera in Q3A world coords (x=right, y=ahead, z=up) glRotatef(-(c->r_eye_el)-90.0f, 1.0, 0.0f, 0.0f); glRotatef(c->r_eye_roll, 0.0, 1.0f, 0.0f); glRotatef(-(c->r_eye_az)+90.0f, 0.0, 0.0f, 1.0f); glGetFloatv(GL_MODELVIEW_MATRIX, mtxC); // Invert the camera rotation matrix (orthonormal: inverse = transpose) mtxCli[0]=mtxC[0]; mtxCli[1]=mtxC[4]; mtxCli[2]=mtxC[8]; mtxCli[4]=mtxC[1]; mtxCli[5]=mtxC[5]; mtxCli[6]=mtxC[9]; mtxCli[8]=mtxC[2]; mtxCli[9]=mtxC[6]; mtxCli[10]=mtxC[10]; // (The remaining seven elements never change) c->mtxCli = mtxCli; if (!(g->r_setup_projection)) { /* for CAVE, scale units to feet! */ glScalef(g->r_scale, g->r_scale, g->r_scale); } glTranslatef(-(c->r_eyepos[0]), -(c->r_eyepos[1]), -(c->r_eyepos[2])); render_objects(c); glMatrixMode(GL_MODELVIEW); glPopMatrix(); #if 0 /* Enable for speeds reporting (like g->r_speeds 1) */ printf("faces: %d, leafs: %d\n", facelist.numfaces + translist.numfaces, g->r_leafcount); #endif }