Skip to content

Screen.h and .cpp

Hannupekka Sormunen edited this page Dec 10, 2018 · 12 revisions

Screen.h

//Header guards for SCREEN_H_
#ifndef SCREEN_H_
#define SCREEN_H

//Include C++ system libraries
#include <fstream>
#include <sstream>
#include <string>

//Include other libraries
#include <SDL.h>

//Create a namespace for this the use of this class
namespace particlefire {

	//Create a class Screen inside namespace ParticleFire.
	class Screen {

		//Private data members of a Screen-class:
	private:
		SDL_Window *m_window;
		SDL_Renderer *m_renderer;
		SDL_Texture *m_texture;
		Uint32 *m_buffer;

		//Protected data members of a Screen-class:
	protected:
		static int screen_width_;
		static int screen_height_;
		static unsigned int target_fps_;

		//Public data members of a Screen-class:
	public:

		//Constructors and destructor of a Screen-class:
	public:
		Screen();//Constructor for Screen-class
		~Screen();//Destructor is used to deallocate processes and variables stored in to heap

		//Private data methods of a Screen-class:
	private:
		bool ReadConfig();//Method for getting settings from a file

		//Public data methods of a Screen-class:
	public:
		bool Init();//Method for initializing SDL-library. Returns true(1) if init was successful, else false(0)
		void UpdateScreen();//Method for updating the window
		void SetPixel(int x, int y, Uint8 red, Uint8  green, Uint8 blue);//Method for setting pixel value on the screen
		void ApplyBoxBlur();//Method for blurring the particles
		bool ProcessEvents();//Method for event processing
		void LimitFPS(int elapsed);//Method for limiting frames per second(FPS)
	};

} /* end of namespace ParticleFire */


#endif /* SCREEN_H */

Constructor

	Screen::Screen() :m_window(NULL), m_renderer(NULL), m_texture(NULL), m_buffer(NULL) {
		//Constructor initializition list is used to set data members to NULL, otherwise SDL can't inform of failure or success when SDL instances are called.

		//Call ReadConfig data method to get settings from the config.cfg-file
		ReadConfig();

		//Allocate pixel buffer arrays in to heap-memory so that they can be accessed throught the program
		m_buffer = new Uint32[screen_width_*screen_height_];
	}

Clone this wiki locally