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

Last change on this file since 5487 was 5487, checked in by jack, 14 years ago

Started C++-ising the code.

File size: 1.8 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
20using std::string;
21
22AnugaVis::AnugaVis(const string &sww_file, int width, int height):
23  screen(NULL), netcdf(sww_file){
24  init_SDL(width, height);
25  init_OpenGL(width, height);
26}
27
28AnugaVis::~AnugaVis(void){
29  if(this->screen != NULL) SDL_Quit();
30}
31
32void AnugaVis::init_SDL(int width, int height){
33  if((SDL_Init(SDL_INIT_VIDEO) == -1) ||
34     (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5) == -1) ||
35     (SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5) == -1) ||
36     (SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5) == -1) ||
37     (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16) == -1) ||
38     (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1) ||
39     ((this->screen = 
40       SDL_SetVideoMode(width, height, 16, SDL_OPENGL)) == NULL))
41    throw SDL_GetError();
42  SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser");
43}
44
45void AnugaVis::init_OpenGL(int width, int height){
46  GLfloat lightAmbient[] = {0.0, 0.0, 0.0, 1.0};
47  GLfloat lightDiffuse[] = {1.0, 1.0, 1.0, 1.0};
48  glEnable(GL_DEPTH_TEST);
49  glShadeModel(GL_FLAT);
50  glEnable(GL_NORMALIZE);
51  glMatrixMode(GL_PROJECTION);
52  gluPerspective(45.0, ((GLdouble)width)/((GLdouble)height), 0.1, 1000);
53  glMatrixMode(GL_MODELVIEW);
54  glLoadIdentity();
55  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
56  glEnable(GL_COLOR_MATERIAL);
57  glEnable(GL_LIGHTING);
58  glEnable(GL_LIGHT0);
59  glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
60  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
61}
Note: See TracBrowser for help on using the repository browser.