Changeset 5228


Ignore:
Timestamp:
Apr 22, 2008, 1:36:01 PM (16 years ago)
Author:
jack
Message:

anugavis: Added checking of dynamism in simple height quantities.
anugavis: Added basic OpenGL initialisation. Broke building of DLL.

Location:
anuga_work/development/anugavis
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/anugavis/configure.ac

    r5227 r5228  
    1414
    1515# Checks for libraries.
    16 AX_CHECK_GL
     16AX_CHECK_GLU
    1717AM_PATH_SDL([1.2.12], [], [AC_MSG_ERROR([SDL is required to build.])])
    1818AC_CACHE_CHECK([for SDL library path],
  • anuga_work/development/anugavis/src/anugavis_simple/anugavis_simple.c

    r5220 r5228  
    33
    44int main(int argc, char *argv[]){
    5   if(AnugaVis_Init(640, 480, "") == -1){
    6     printf("AnugaVis_Init() Error: %s", AnugaVis_GetError());
     5  if(argc != 2){
     6    printf("Usage: anugavis_simple sww_file_name\n");
     7    return 1;
     8  }
     9  if(AnugaVis_Init(640, 480, argv[1]) == -1){
     10    printf("AnugaVis_Init() Error: %s\n", AnugaVis_GetError());
     11    return 1;
     12  }
     13  if(AnugaVis_DefineHeightQuantity("elevation", 0, 1, 128, 128, 128) == -1){
     14    printf("AnugaVis_DefineHeightQuantity() Error: %s\n", AnugaVis_GetError());
     15    return 1;
     16  }
     17  if(AnugaVis_DefineHeightQuantity("stage", 0, 1, 0, 0, 128) == -1){
     18    printf("AnugaVis_DefineHeightQuantity() Error: %s\n", AnugaVis_GetError());
    719    return 1;
    820  }
  • anuga_work/development/anugavis/src/libanugavis/Makefile.am

    r5220 r5228  
    1010                         height_quantity.h \
    1111                         init.c
    12 libanugavis_la_CFLAGS = @SDL_CFLAGS@
    13 libanugavis_la_LIBADD = -lSDL
     12libanugavis_la_CFLAGS = @SDL_CFLAGS@ @GLU_CFLAGS@
     13libanugavis_la_LIBADD = -lSDL @GLU_LIBS@
    1414libanugavis_la_LDFLAGS = @SDL_LIBPATH@ -no-undefined -version-info 0:0:0
  • anuga_work/development/anugavis/src/libanugavis/anugavis.h

    r5220 r5228  
    1111 * given offset, scale, and color. Returns 0 on success, -1 on error.
    1212 */
    13 extern int AnugaVis_DefineHeightQuantity(char *name,
     13extern int AnugaVis_DefineHeightQuantity(const char *name,
    1414                                         double offset, double scale,
    1515                                         int red, int green, int blue);
  • anuga_work/development/anugavis/src/libanugavis/error.c

    r5220 r5228  
    11#include <stdarg.h>
     2#include <netcdf.h>
    23#include <SDL.h>
    34#include "anugavis.h"
     
    2324  SDL_ClearError();
    2425}
     26
     27void AnugaVis_NetCDFError(int ncerr){
     28  AnugaVis_SetError("NetCDF Error: %s", nc_strerror(ncerr));
     29}
  • anuga_work/development/anugavis/src/libanugavis/error.h

    r5220 r5228  
    1010void AnugaVis_SDLError(void);
    1111
     12/* Report a NetCDF error.
     13 */
     14void AnugaVis_NetCDFError(int ncerr);
     15
    1216#endif
  • anuga_work/development/anugavis/src/libanugavis/globals.h

    r5220 r5228  
    77typedef struct{
    88  SDL_Surface *screen;
     9  int netcdfId;
    910  struct height_quantity_simple *heights;
    1011} ANUGAVIS;
  • anuga_work/development/anugavis/src/libanugavis/height_quantity.c

    r5220 r5228  
    11#include <stdlib.h>
    22#include <string.h>
     3#include <netcdf.h>
    34#include <SDL.h>
    45#include "anugavis.h"
     
    78#include "height_quantity.h"
    89
    9 int AnugaVis_DefineHeightQuantity(char *name,
     10int AnugaVis_DefineHeightQuantity(const char *name,
    1011                                  double offset, double scale,
    1112                                  int red, int green, int blue){
    1213  struct height_quantity_simple *height;
     14  int ncstatus;
     15  int ncvarid;
     16  int numdims;
     17  /* Check that it's actually in the NetCDF file */
     18  if((ncstatus = nc_inq_varid(anugavis.netcdfId, name, &ncvarid)) != NC_NOERR){
     19    AnugaVis_NetCDFError(ncstatus);
     20    return -1;
     21  }     
     22
    1323  /* Redefining a quantity? */
    1424  for(height = anugavis.heights ; height != NULL ; height = height->next)
     
    2636  }
    2737 
    28   /* TODO: use NetCDF to check if the quantity is dynamic */
     38  /* If the NetCDF variable is 2-dimensional, then it's dynamic. */
     39  if((ncstatus = nc_inq_varndims(anugavis.netcdfId,
     40                                 ncvarid, &numdims)) != NC_NOERR){
     41    AnugaVis_NetCDFError(ncstatus);
     42    return -1;
     43  }
     44  height->dynamic = (numdims == 2);
    2945  height->offset = offset;
    3046  height->scale = scale;
  • anuga_work/development/anugavis/src/libanugavis/init.c

    r5220 r5228  
     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>
    116#include <SDL.h>
    217#include "anugavis.h"
     
    520
    621int AnugaVis_Init(int width, int height, const char *swwFilePath){
     22  int ncstatus;
    723  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
    824     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
     
    1632    return -1;
    1733  }
     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){
     45    AnugaVis_NetCDFError(ncstatus);
     46    SDL_Quit();
     47    return -1;
     48  }
    1849  anugavis.heights = NULL;
    1950  return 0;
     
    2354  while(anugavis.heights != NULL)
    2455    AnugaVis_UndefineHeightQuantity(anugavis.heights->name);
     56  nc_close(anugavis.netcdfId);
    2557  SDL_Quit();
    2658}
Note: See TracChangeset for help on using the changeset viewer.