source: anuga_work/development/anugavis/src/init.c @ 5339

Last change on this file since 5339 was 5339, checked in by jack, 16 years ago

Fixed frame controls

File size: 3.7 KB
Line 
1#ifdef HAVE_CONFIG_H
2#  include "config.h"
3#endif
4
5#ifdef HAVE_STDLIB_H
6#  include <stdlib.h>
7#endif
8#ifdef HAVE_GL_GL_H
9#  include <GL/gl.h>
10#elif HAVE_OPENGL_GL_H
11#  include <OpenGL/gl.h>
12#endif
13#ifdef HAVE_GL_GLU_H
14#  include <GL/glu.h>
15#elif HAVE_OPENGL_GLU_H
16#  include <OpenGL/glu.h>
17#endif
18#include <netcdf.h>
19#include <SDL.h>
20#include "error.h"
21#include "globals.h"
22#include "init.h"
23#include "netcdf_util.h"
24#include "xfunctions.h"
25
26int AnugaVis_Init(int width, int height, const char *swwFilePath){
27  int ncstatus;
28  GLfloat lightAmbient[] = {0.0, 0.0, 0.0, 1.0};
29  GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
30  anugavis.current_frame = 0;
31  anugavis.paused = 0;
32  anugavis.x = NULL;
33  anugavis.y = NULL;
34  anugavis.volumes = NULL;
35
36  anugavis.pitch = 0.0;
37  anugavis.yaw = 0.0;
38  anugavis.track = 0.0;
39  anugavis.strafe = 0.0;
40  /* FIXME derive this from the dataset? */
41  anugavis.eye[0] = 1.0;
42  anugavis.eye[1] = 1.0;
43  anugavis.eye[2] = 40.0;
44  anugavis.focus[0] = 0.0;
45  anugavis.focus[1] = 0.0;
46  anugavis.focus[2] = 0.0;
47  anugavis.heights = NULL;
48  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
49     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
50     (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) ||
51     (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) ||
52     (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) ||
53     (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) ||
54     ((anugavis.screen = 
55       SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL)){
56    AnugaVis_SDLError();
57    return -1;
58  }
59
60  SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser");
61  glEnable(GL_DEPTH_TEST);
62  glShadeModel(GL_FLAT);
63  glEnable(GL_NORMALIZE);
64  glMatrixMode(GL_PROJECTION);
65  gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000);
66  glMatrixMode(GL_MODELVIEW);
67  glLoadIdentity();
68  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
69  glEnable(GL_COLOR_MATERIAL);
70  glEnable(GL_LIGHTING);
71  glEnable(GL_LIGHT0);
72  glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
73  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
74 
75  if((ncstatus = nc_open(swwFilePath, NC_SHARE,
76                         &anugavis.netcdfId)) != NC_NOERR){
77    SDL_Quit();
78    return -1;
79  }
80
81  if((nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_points",
82                            &anugavis.number_of_points) != NC_NOERR) ||
83     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_vertices",
84                            &anugavis.number_of_vertices) != NC_NOERR) ||
85     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_volumes",
86                            &anugavis.number_of_volumes) != NC_NOERR) ||
87     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_timesteps",
88                            &anugavis.number_of_timesteps) != NC_NOERR) ||
89     ((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points,
90                            "AnugaVis_Init()")) == NULL) ||
91     ((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points,
92                            "AnugaVis_Init()")) == NULL) ||
93     ((anugavis.volumes = xmalloc(sizeof(int)
94                                  * anugavis.number_of_volumes
95                                  * anugavis.number_of_vertices,
96                                  "AnugaVis_Init()")) == NULL) ||
97     (nc_get_var_float_by_name(anugavis.netcdfId, "x",
98                               anugavis.x) != NC_NOERR) ||
99     (nc_get_var_float_by_name(anugavis.netcdfId, "y",
100                               anugavis.y) != NC_NOERR) ||
101     (nc_get_var_int_by_name(anugavis.netcdfId, "volumes",
102                             anugavis.volumes) != NC_NOERR)){
103    AnugaVis_DeInit();
104    return -1;
105  }
106  return 0;
107}
108
109void AnugaVis_DeInit(void){
110  while(anugavis.heights != NULL)
111    AnugaVis_UndefineHeightQuantity(anugavis.heights->name);
112  nc_close(anugavis.netcdfId);
113  if(anugavis.x != NULL) free(anugavis.x);
114  if(anugavis.y != NULL) free(anugavis.y);
115  if(anugavis.volumes != NULL) free(anugavis.volumes);
116  SDL_Quit();
117}
Note: See TracBrowser for help on using the repository browser.