void pie_RemainingPasses(void) { GL_DEBUG("Remaining passes - shadows"); // Draw shadows if (shadows) { pie_DrawShadows(); } // Draw models // TODO, sort list to reduce state changes GL_DEBUG("Remaining passes - opaque models"); for (SHAPE const &shape : shapes) { pie_SetShaderStretchDepth(shape.stretch); pie_Draw3DShape2(shape.shape, shape.frame, shape.colour, shape.teamcolour, shape.flag, shape.flag_data, shape.matrix); } // Draw translucent models last // TODO, sort list by Z order to do translucency correctly GL_DEBUG("Remaining passes - translucent models"); for (SHAPE const &shape : tshapes) { pie_SetShaderStretchDepth(shape.stretch); pie_Draw3DShape2(shape.shape, shape.frame, shape.colour, shape.teamcolour, shape.flag, shape.flag_data, shape.matrix); } pie_SetShaderStretchDepth(0); pie_DeactivateShader(); tshapes.clear(); shapes.clear(); GL_DEBUG("Remaining passes - done"); }
static void pie_DrawRemainingTransShapes(void) { glPushMatrix(); for (unsigned i = 0; i < tshapes.size(); ++i) { glLoadMatrixf(tshapes[i].matrix); pie_Draw3DShape2(tshapes[i].shape, tshapes[i].frame, tshapes[i].colour, tshapes[i].colour, tshapes[i].flag, tshapes[i].flag_data); } glPopMatrix(); tshapes.clear(); }
void pie_RemainingPasses(void) { GL_DEBUG("Remaining passes - shadows"); glEnable(GL_LIGHT0); // Draw shadows if (shadows) { pie_DrawShadows(); } // Draw models // TODO, sort list to reduce state changes GL_DEBUG("Remaining passes - opaque models"); glPushMatrix(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); for (unsigned i = 0; i < shapes.size(); ++i) { pie_Draw3DShape2(shapes[i].shape, shapes[i].frame, shapes[i].colour, shapes[i].teamcolour, shapes[i].flag, shapes[i].flag_data, shapes[i].matrix); } // Draw translucent models last // TODO, sort list by Z order to do translucency correctly GL_DEBUG("Remaining passes - translucent models"); for (unsigned i = 0; i < tshapes.size(); ++i) { pie_Draw3DShape2(tshapes[i].shape, tshapes[i].frame, tshapes[i].colour, tshapes[i].teamcolour, tshapes[i].flag, tshapes[i].flag_data, tshapes[i].matrix); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_LIGHT0); pie_DeactivateShader(); glPopMatrix(); tshapes.resize(0); shapes.resize(0); GL_DEBUG("Remaining passes - done"); }
static void pie_DrawRemainingTransShapes(void) { unsigned int i = 0; glPushMatrix(); for (i = 0; i < nb_tshapes; ++i) { glLoadMatrixf(tshapes[i].matrix); pie_Draw3DShape2(tshapes[i].shape, tshapes[i].frame, tshapes[i].colour, tshapes[i].colour, tshapes[i].specular, tshapes[i].flag, tshapes[i].flag_data); } glPopMatrix(); nb_tshapes = 0; }
void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, int pieFlag, int pieFlagData) { PIELIGHT teamcolour; ASSERT_OR_RETURN(, shape, "Attempting to draw null sprite"); teamcolour = pal_GetTeamColour(team); pieCount++; ASSERT(frame >= 0, "Negative frame %d", frame); ASSERT(team >= 0, "Negative team %d", team); if (drawing_interface || !shadows) { pie_Draw3DShape2(shape, frame, colour, teamcolour, pieFlag, pieFlagData); } else { if (pieFlag & (pie_ADDITIVE | pie_TRANSLUCENT | pie_PREMULTIPLIED) && !(pieFlag & pie_FORCE_IMMEDIATE)) { TranslucentShape tshape; glGetFloatv(GL_MODELVIEW_MATRIX, tshape.matrix); tshape.shape = shape; tshape.frame = frame; tshape.colour = colour; tshape.flag = pieFlag; tshape.flag_data = pieFlagData; tshapes.push_back(tshape); } else { if(pieFlag & pie_SHADOW || pieFlag & pie_STATIC_SHADOW) { float distance; // draw a shadow ShadowcastingShape scshape; glGetFloatv(GL_MODELVIEW_MATRIX, scshape.matrix); distance = scshape.matrix[12] * scshape.matrix[12]; distance += scshape.matrix[13] * scshape.matrix[13]; distance += scshape.matrix[14] * scshape.matrix[14]; // if object is too far in the fog don't generate a shadow. if (distance < SHADOW_END_DISTANCE) { float invmat[9], pos_light0[4]; inverse_matrix( scshape.matrix, invmat ); // Calculate the light position relative to the object glGetLightfv(GL_LIGHT0, GL_POSITION, pos_light0); scshape.light.x = invmat[0] * pos_light0[0] + invmat[3] * pos_light0[1] + invmat[6] * pos_light0[2]; scshape.light.y = invmat[1] * pos_light0[0] + invmat[4] * pos_light0[1] + invmat[7] * pos_light0[2]; scshape.light.z = invmat[2] * pos_light0[0] + invmat[5] * pos_light0[1] + invmat[8] * pos_light0[2]; scshape.shape = shape; scshape.flag = pieFlag; scshape.flag_data = pieFlagData; scshapes.push_back(scshape); } } pie_Draw3DShape2(shape, frame, colour, teamcolour, pieFlag, pieFlagData); } } }
void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, PIELIGHT specular, int pieFlag, int pieFlagData) { PIELIGHT teamcolour; ASSERT_OR_RETURN(, shape, "Attempting to draw null sprite"); teamcolour = pal_GetTeamColour(team); pieCount++; if (frame == 0) { frame = team; } if (drawing_interface || !shadows) { pie_Draw3DShape2(shape, frame, colour, teamcolour, specular, pieFlag, pieFlagData); } else { if (pieFlag & (pie_ADDITIVE | pie_TRANSLUCENT)) { if (tshapes_size <= nb_tshapes) { if (tshapes_size == 0) { tshapes_size = 64; tshapes = (transluscent_shape_t*)malloc(tshapes_size*sizeof(transluscent_shape_t)); memset( tshapes, 0, tshapes_size*sizeof(transluscent_shape_t) ); } else { const unsigned int old_size = tshapes_size; tshapes_size <<= 1; tshapes = (transluscent_shape_t*)realloc(tshapes, tshapes_size*sizeof(transluscent_shape_t)); memset( &tshapes[old_size], 0, (tshapes_size-old_size)*sizeof(transluscent_shape_t) ); } } glGetFloatv(GL_MODELVIEW_MATRIX, tshapes[nb_tshapes].matrix); tshapes[nb_tshapes].shape = shape; tshapes[nb_tshapes].frame = frame; tshapes[nb_tshapes].colour = colour; tshapes[nb_tshapes].specular = specular; tshapes[nb_tshapes].flag = pieFlag; tshapes[nb_tshapes].flag_data = pieFlagData; nb_tshapes++; } else { if(pieFlag & pie_SHADOW || pieFlag & pie_STATIC_SHADOW) { float distance; // draw a shadow if (scshapes_size <= nb_scshapes) { if (scshapes_size == 0) { scshapes_size = 64; scshapes = (shadowcasting_shape_t*)malloc(scshapes_size*sizeof(shadowcasting_shape_t)); memset( scshapes, 0, scshapes_size*sizeof(shadowcasting_shape_t) ); } else { const unsigned int old_size = scshapes_size; scshapes_size <<= 1; scshapes = (shadowcasting_shape_t*)realloc(scshapes, scshapes_size*sizeof(shadowcasting_shape_t)); memset( &scshapes[old_size], 0, (scshapes_size-old_size)*sizeof(shadowcasting_shape_t) ); } } glGetFloatv(GL_MODELVIEW_MATRIX, scshapes[nb_scshapes].matrix); distance = scshapes[nb_scshapes].matrix[12] * scshapes[nb_scshapes].matrix[12]; distance += scshapes[nb_scshapes].matrix[13] * scshapes[nb_scshapes].matrix[13]; distance += scshapes[nb_scshapes].matrix[14] * scshapes[nb_scshapes].matrix[14]; // if object is too far in the fog don't generate a shadow. if (distance < SHADOW_END_DISTANCE) { float invmat[9], pos_light0[4]; inverse_matrix( scshapes[nb_scshapes].matrix, invmat ); // Calculate the light position relative to the object glGetLightfv(GL_LIGHT0, GL_POSITION, pos_light0); scshapes[nb_scshapes].light.x = invmat[0] * pos_light0[0] + invmat[3] * pos_light0[1] + invmat[6] * pos_light0[2]; scshapes[nb_scshapes].light.y = invmat[1] * pos_light0[0] + invmat[4] * pos_light0[1] + invmat[7] * pos_light0[2]; scshapes[nb_scshapes].light.z = invmat[2] * pos_light0[0] + invmat[5] * pos_light0[1] + invmat[8] * pos_light0[2]; scshapes[nb_scshapes].shape = shape; scshapes[nb_scshapes].flag = pieFlag; scshapes[nb_scshapes].flag_data = pieFlagData; nb_scshapes++; } } pie_Draw3DShape2(shape, frame, colour, teamcolour, specular, pieFlag, pieFlagData); } } }