source: anuga_work/development/anugavis/src/anugavis.cc @ 5598

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

Progress on height quantities.

File size: 2.0 KB
Line 
1#ifdef HAVE_CONFIG_H
2#  include "config.h"
3#endif
4
5#include <iostream>
6#include <string>
7#ifdef HAVE_GL_GL_H
8#  include <GL/gl.h>
9#elif HAVE_OPENGL_GL_H
10#  include <OpenGL/gl.h>
11#endif
12#ifdef HAVE_GL_GLU_H
13#  include <GL/glu.h>
14#elif HAVE_OPENGL_GLU_H
15#  include <OpenGL/glu.h>
16#endif
17#include <SDL.h>
18#include "anugavis.hh"
19#include "height_quantity.hh"
20
21using std::string;
22
23AnugaVis::AnugaVis(const string &file_name, int width, int height):
24  screen(NULL), sww_file(file_name){
25  init_SDL(width, height);
26  init_OpenGL(width, height);
27}
28
29AnugaVis::~AnugaVis(void){
30  if(this->screen != NULL) SDL_Quit();
31}
32
33void AnugaVis::add_HeightQuantity(HeightQuantity &height){
34  height.set_dynamic(this->sww_file.nc_inq_varndims_by_name(height.get_name()) \
35                     == 2);
36  this->heights.push_back(height);
37}
38
39void AnugaVis::run(void){
40
41}
42
43void AnugaVis::init_SDL(int width, int height){
44  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
45     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
46     (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) ||
47     (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) ||
48     (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) ||
49     (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) ||
50     ((this->screen = 
51       SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL))
52    throw SDL_GetError();
53  SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser");
54}
55
56void AnugaVis::init_OpenGL(int width, int height){
57  GLfloat lightAmbient[] = {0.0, 0.0, 0.0, 1.0};
58  GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
59  glEnable(GL_DEPTH_TEST);
60  glShadeModel(GL_FLAT);
61  glEnable(GL_NORMALIZE);
62  glMatrixMode(GL_PROJECTION);
63  gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000);
64  glMatrixMode(GL_MODELVIEW);
65  glLoadIdentity();
66  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
67  glEnable(GL_COLOR_MATERIAL);
68  glEnable(GL_LIGHTING);
69  glEnable(GL_LIGHT0);
70  glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
71  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
72}
Note: See TracBrowser for help on using the repository browser.