1 #pragma once 2 3 //Renderer - a class encapsulating all neccessary graphics functions, 4 // such as drawing balls, holes, menus, waves and blitting the rendered 5 // graphics to the screen. 6 // There is one global Renderer instance, to which many other classes posess 7 // pointers 8 /* Quantum Minigolf, a computer game illustrating quantum mechanics 9 Copyright (C) 2007 Friedemann Reinhard <friedemann.reinhard@gmail.com> 10 11 This program is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation; either version 2 of the License, or 14 (at your option) any later version. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 27 #include <math.h> 28 #include <stdlib.h> 29 #include <string> 30 #include <SDL.h> 31 #include <SDL_ttf.h> 32 #include <fftw3.h> 33 34 using namespace std; 35 36 #include "quantumminigolf.h" 37 38 class Renderer 39 { 40 public: 41 Renderer(int width, int height, int flag, int holex, int holey, int holer, int rball); 42 ~Renderer(void); 43 44 void RenderTrack(void); 45 void RenderHole(float x, float y, float r); 46 void RenderWave(fftwf_complex *psi); 47 void RenderBall(float posx, float posy); 48 void RenderRacket(float l, float r, int ix, int iy, float rphi); 49 void RenderFlash(void); // show a white surface 50 void RenderExtro(int result, int ypos); // show the "You win" / "You lose" 51 void RenderMenu(bool quantum); 52 53 void Lock(void); 54 void Unlock(void); 55 void Blit(void); 56 57 void SaveFrame(const char *fname); 58 ToggleCmap()59 void ToggleCmap(){cmap = ((cmap == cmapm) ? cmapc : cmapm);} 60 61 SDL_Surface *screen, *V; 62 int width; int height; 63 64 private: 65 SDL_Surface *bBuffer; // the back buffer 66 SDL_Surface *wave; // the wave 67 SDL_Surface *cmapm, *cmapc, *cmap; // monochrome, colored and a pointer to the actual color map 68 SDL_Surface *win; SDL_Surface *lose; 69 SDL_Rect rBuffer; 70 71 // fonts for the menu 72 TTF_Font *fntsml; 73 TTF_Font *fntbg; 74 75 int holex, holey, holer; // position and radius of the hole 76 int rball; // radius of the ball 77 }; 78