#ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef HAVE_STDLIB_H # include #endif #ifdef HAVE_GL_GL_H # include #elif HAVE_OPENGL_GL_H # include #endif #ifdef HAVE_GL_GLU_H # include #elif HAVE_OPENGL_GLU_H # include #endif #include #include #include "camera.h" #include "error.h" #include "globals.h" #include "init.h" #include "netcdf_util.h" #include "vector.h" #include "xfunctions.h" int AnugaVis_Init(int width, int height, const char *swwFilePath){ int ncstatus; unsigned int i; GLfloat lightAmbient[] = {0.0, 0.0, 0.0, 1.0}; GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0}; anugavis.current_frame = 0; anugavis.paused = 0; anugavis.x = NULL; anugavis.y = NULL; anugavis.volumes = NULL; anugavis.heights = NULL; if((SDL_Init(SDL_INIT_VIDEO) == -1) || (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) || (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) || (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) || (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) || (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) || ((anugavis.screen = SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL)){ AnugaVis_SDLError(); return -1; } SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser"); glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glEnable(GL_NORMALIZE); glMatrixMode(GL_PROJECTION); gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); if((ncstatus = nc_open(swwFilePath, NC_SHARE, &anugavis.netcdfId)) != NC_NOERR){ SDL_Quit(); return -1; } if((nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_points", &anugavis.number_of_points) != NC_NOERR) || (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_vertices", &anugavis.number_of_vertices) != NC_NOERR) || (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_volumes", &anugavis.number_of_volumes) != NC_NOERR) || (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_timesteps", &anugavis.number_of_timesteps) != NC_NOERR) || ((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points, "AnugaVis_Init()")) == NULL) || ((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points, "AnugaVis_Init()")) == NULL) || ((anugavis.volumes = xmalloc(sizeof(int) * anugavis.number_of_volumes * anugavis.number_of_vertices, "AnugaVis_Init()")) == NULL) || (nc_get_var_float_by_name(anugavis.netcdfId, "x", anugavis.x) != NC_NOERR) || (nc_get_var_float_by_name(anugavis.netcdfId, "y", anugavis.y) != NC_NOERR) || (nc_get_var_int_by_name(anugavis.netcdfId, "volumes", anugavis.volumes) != NC_NOERR)){ AnugaVis_DeInit(); return -1; } for(i = 0 ; i < anugavis.number_of_points ; i++){ anugavis.minX = MIN(anugavis.minX, anugavis.x[i]); anugavis.maxX = MAX(anugavis.maxX, anugavis.x[i]); anugavis.minY = MIN(anugavis.minY, anugavis.y[i]); anugavis.maxY = MAX(anugavis.maxY, anugavis.y[i]); } anugavis.diagonal = sqrt((anugavis.maxX - anugavis.minX) * (anugavis.maxX - anugavis.minX) + (anugavis.maxY - anugavis.minY) * (anugavis.maxY - anugavis.minY)); camera_home(); return 0; } void AnugaVis_DeInit(void){ while(anugavis.heights != NULL) AnugaVis_UndefineHeightQuantity(anugavis.heights->name); nc_close(anugavis.netcdfId); if(anugavis.x != NULL) free(anugavis.x); if(anugavis.y != NULL) free(anugavis.y); if(anugavis.volumes != NULL) free(anugavis.volumes); SDL_Quit(); }