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

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

anugavis: added event loop. Now drawing an empty screen.

File size: 1.8 KB
Line 
1#ifdef HAVE_CONFIG_H
2#  include "config.h"
3#endif
4
5#ifdef HAVE_GL_GL_H
6#  include <GL/gl.h>
7#elif HAVE_OPENGL_GL_H
8#  include <OpenGL/gl.h>
9#endif
10#ifdef HAVE_GL_GLU_H
11#  include <GL/glu.h>
12#elif HAVE_OPENGL_GLU_H
13#  include <OpenGL/glu.h>
14#endif
15#include <netcdf.h>
16#include <SDL.h>
17#include "error.h"
18#include "globals.h"
19
20int AnugaVis_Init(int width, int height, const char *swwFilePath){
21  int ncstatus;
22  int ncdimid;
23  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
24     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
25     (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) ||
26     (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) ||
27     (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) ||
28     (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) ||
29     ((anugavis.screen = 
30       SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL)){
31    AnugaVis_SDLError();
32    return -1;
33  }
34
35  glEnable(GL_DEPTH_TEST);
36  glShadeModel(GL_FLAT);
37  glEnable(GL_NORMALIZE);
38  glMatrixMode(GL_PROJECTION);
39  gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000);
40  glMatrixMode(GL_MODELVIEW);
41  glLoadIdentity();
42
43  if((ncstatus = nc_open(swwFilePath, NC_SHARE,
44                         &anugavis.netcdfId)) != NC_NOERR) goto nc_err;
45  if((ncstatus = nc_inq_dimid(anugavis.netcdfId, "number_of_points",
46                              &ncdimid)) != NC_NOERR) goto nc_err;
47  if((ncstatus = nc_inq_dimlen(anugavis.netcdfId, ncdimid,
48                               &anugavis.number_of_points)) != NC_NOERR)
49    goto nc_err;
50
51  anugavis.heights = NULL;
52  return 0;
53 nc_err:
54  AnugaVis_NetCDFError(ncstatus);
55  SDL_Quit();
56  return -1;
57}
58
59void AnugaVis_DeInit(void){
60  while(anugavis.heights != NULL)
61    AnugaVis_UndefineHeightQuantity(anugavis.heights->name);
62  nc_close(anugavis.netcdfId);
63  SDL_Quit();
64}
Note: See TracBrowser for help on using the repository browser.