[5487] | 1 | #ifdef HAVE_CONFIG_H |
---|
| 2 | # include "config.h" |
---|
| 3 | #endif |
---|
| 4 | |
---|
| 5 | #include <iostream> |
---|
| 6 | #include <string> |
---|
[5600] | 7 | #include <boost/shared_ptr.hpp> |
---|
[5487] | 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 <SDL.h> |
---|
| 19 | #include "anugavis.hh" |
---|
[5598] | 20 | #include "height_quantity.hh" |
---|
[5600] | 21 | #include "sww_file.hh" |
---|
[5487] | 22 | |
---|
[5600] | 23 | using boost::shared_ptr; |
---|
[5487] | 24 | using std::string; |
---|
| 25 | |
---|
[5488] | 26 | AnugaVis::AnugaVis(const string &file_name, int width, int height): |
---|
[5600] | 27 | screen(NULL), sww_file(new SWWFile(file_name)){ |
---|
[5487] | 28 | init_SDL(width, height); |
---|
| 29 | init_OpenGL(width, height); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | AnugaVis::~AnugaVis(void){ |
---|
| 33 | if(this->screen != NULL) SDL_Quit(); |
---|
| 34 | } |
---|
| 35 | |
---|
[5600] | 36 | void AnugaVis::add_HeightQuantity(shared_ptr<HeightQuantity> &height){ |
---|
| 37 | height->set_SWWFile(this->sww_file); |
---|
[5598] | 38 | this->heights.push_back(height); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | void AnugaVis::run(void){ |
---|
| 42 | |
---|
| 43 | } |
---|
| 44 | |
---|
[5487] | 45 | void AnugaVis::init_SDL(int width, int height){ |
---|
| 46 | if((SDL_Init(SDL_INIT_VIDEO) == -1) || |
---|
| 47 | (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) || |
---|
| 48 | (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) || |
---|
| 49 | (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) || |
---|
| 50 | (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) || |
---|
| 51 | (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) || |
---|
| 52 | ((this->screen = |
---|
| 53 | SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL)) |
---|
| 54 | throw SDL_GetError(); |
---|
| 55 | SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser"); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void AnugaVis::init_OpenGL(int width, int height){ |
---|
| 59 | GLfloat lightAmbient[] = {0.0, 0.0, 0.0, 1.0}; |
---|
| 60 | GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0}; |
---|
| 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 | } |
---|