/// this will render the "cam" cameraData to the "dest" renderer. // returns 0 on successful rendering. // returns 1 if the dest pointer is NULL. // returns 2 if the cam pointer is NULL. // returns 3 if cam->target is NULL. short camera_render(SDL_Renderer *dest, struct cameraData *cam){ // check to see if dest is invalid if(dest == NULL){ //report the error error("camera_render() was sent an invalid renderer. dest = NULL"); return 1; } // check to see if cam is invalid if(cam == NULL){ //report the error error("camera_render() was sent an invalid cam value. cam = NULL"); return 2; } if(cam->target == NULL){ error("camera_render() was sent a valid camera with an invalid target blockData pointer. cam->target = NULL"); return 3; } /* OLD PRINTING CODE // i and j index into the surface pixel array. // iElevation and jElevation index into the blockData's elevation array. int i, j, iElevation, jElevation; // these store the constant scaling factors used to scale the i and j variables into the iElevation and jElevation variables. float iScale = cam->scale*BLOCK_WIDTH /(float)dest->w; float jScale = cam->scale*BLOCK_HEIGHT/(float)dest->h; // calculate the color for every pixel on the destination surface for(i=0; i<dest->w; i++){ for(j=0; j<dest->h; j++){ // calculate the x and y indexes for the elevation array iElevation = (int)(cam->x + i*iScale); jElevation = (int)(cam->y + j*jScale); // make sure the elevation index is in between if(iElevation>=0 && iElevation<BLOCK_WIDTH && jElevation >= 0 && jElevation < BLOCK_HEIGHT){ set_pixel(dest, i, j, (0xff000000|(int)(cam->target->elevation[iElevation][jElevation]))&(0xff00f000) ); } } } */ // if the target block has not been rendered, render it now. if(cam->target->texture == NULL || cam->target->renderMe) block_render(cam->target, dest); SDL_RenderCopy(dest, cam->target->texture, NULL, NULL); // successful print. return 0; }
static void render(GContext *ctx) { #ifdef BENCHMARK uint16_t start = time_ms(NULL, NULL); #endif pge_isometric_begin(ctx); // Tiles for(int z = 0; z < GRID_DEPTH; z++) { for(int y = 0; y < GRID_HEIGHT; y++) { for(int x = 0; x < GRID_WIDTH; x++) { block_render(s_block_array[vec2i(Vec3(x, y, z))]); } } } for(int i = 0; i < MAX_CLOUDS; i++) { cloud_render(s_cloud_array[i]); } // Selection switch(s_input_mode) { case MODE_X: pge_isometric_draw_rect(Vec3(0, s_cursor.y * BLOCK_SIZE, (s_cursor.z + 1) * BLOCK_SIZE), GSize(GRID_WIDTH * BLOCK_SIZE, BLOCK_SIZE), GColorWhite); break; case MODE_Y: pge_isometric_draw_rect(Vec3(s_cursor.x * BLOCK_SIZE, 0, (s_cursor.z + 1) * BLOCK_SIZE), GSize(BLOCK_SIZE, GRID_HEIGHT * BLOCK_SIZE), GColorWhite); break; case MODE_Z: pge_isometric_draw_box(Vec3(s_cursor.x * BLOCK_SIZE, s_cursor.y * BLOCK_SIZE, BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), (GRID_DEPTH - 1) * BLOCK_SIZE, GColorWhite); break; } pge_isometric_draw_box(Vec3(s_cursor.x * BLOCK_SIZE, s_cursor.y * BLOCK_SIZE, s_cursor.z * BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), BLOCK_SIZE, GColorRed); // Box pge_isometric_draw_box(Vec3(0, 0, 0), GSize(BLOCK_SIZE * GRID_WIDTH, BLOCK_SIZE * GRID_HEIGHT), SKY_HEIGHT, GColorLightGray); pge_isometric_finish(ctx); #ifdef BENCHMARK uint16_t finish = time_ms(NULL, NULL); APP_LOG(APP_LOG_LEVEL_INFO, "Frame time: %d ms", (int)finish - start); #endif }