Jump to content

  • Log In with Google      Sign In   
  • Create Account


WhiteChocolateMocha

Member Since 25 Nov 2008
Offline Last Active Mar 09 2014 10:20 AM
-----

Topics I've Started

Valve OpenGL Tips and Tricks

09 November 2013 - 09:34 PM

I haven't seen this posted anywhere on the site, so, Valve held a presentation a few months ago on porting their Source engine to Linux. It goes into detail on how to use modern OpenGL and getting the best performance out of it. It's an hour long video - a great wealth of info.

 


GLFW and initial incorrect viewport

09 November 2013 - 08:20 PM

I have a weird phenomena where everything is rendered in the lower left corner of the window. Calling glViewport(0, 0, 1024, 768) doesn't help. Neither does calling glfwSetWindowPos or glfwSetWindowSize. Manually repositioning the window helps, but I shouldn't have to do this. I don't have anything in app that ties window repositioning to OpenGL. Is anyone familiar with this problem and know of a solution?

 

I made a video demonstrating the problem http://www.youtube.com/watch?v=kdwHvqSv42w&feature=youtu.be


Understanding Composition

13 May 2009 - 04:22 AM

Hello, I bought the book Head First - Design Patterns. After reading about the Strategy Pattern I tried to implement it in a OpenGL Window class.
namespace bj{

	class GL{
	private:
		HWND		windowHandle;
		HDC			deviceContext;
		HGLRC		renderContext;
		int			exitCode;

		/* Sets the windows class to use with the window. Returns
		a string containing the name of the window class*/
		std::tr1::function<std::wstring(GL &)> register_class; 

		/* Function that adjusts the size of the window and
		creates the window. This algorithm must set the GL's 
		windowHandle and deviceContexts states.*/
		std::tr1::function<void(GL &, const std::wstring &, int &,
			int&)>
			create_window;

		/* This function describes the pixel format of the 
		renderer and sets up a rendering context. The GL's
		rendering context state must be set. */
		std::tr1::function<void(GL &)> setup_gl;

		/* This function is called when the window is resized.
		It should reset the viewport and projection matrix. */
		std::tr1::function<void(double, double)> resize;

		/* Do any initialization here. */
		std::tr1::function<void(GL &)> initialize;

		// Main run loop. This functor must be set
		std::tr1::function<int(GL &)> run_loop;

	public:
		// Get DC
		HDC get_dc(){return (deviceContext);}

		// Set DC
		void set_dc(HDC dc){deviceContext = dc;}

		// Get RC
		HGLRC get_rc(){return (renderContext);}

		// Set RC
		void set_rc(HGLRC rc){renderContext = rc;}

		// Get Window handle
		HWND get_window(){return (windowHandle);}

		// Set Window handle
		void set_window(HWND window){windowHandle = window;}

		// Reset the register_class functor
		void reset_register_class(
			std::tr1::function<std::wstring(GL &)> register_class){
				this->register_class = register_class;
		}

		// Reset the create_window functor
		void reset_create_window(std::tr1::function<void(GL &, const std::wstring &, int &,
			int&)> create_window){
				this->create_window = create_window;
		}

		// Reset the setup_gl functor
		void reset_setup_gl(std::tr1::function<void(GL &)> setup_gl){
			this->setup_gl = setup_gl;
		}

		// Reset the resize functor
		void reset_resize(std::tr1::function<void(double, double)> resize){
			this->resize = resize;
		}

		// Reset the initialize functor
		void reset_initialize(std::tr1::function<void(GL &)> initialize){
			this->initialize = initialize;
		}

		// Reset the run loop
		void reset_run_loop(std::tr1::function<int(GL &)> run_loop){
			this->run_loop = run_loop;
		}

		// Returns main loop exit code
		int get_exit_code()const{return (exitCode);}


		// Constructors
		GL();

		explicit GL(std::tr1::function<int(GL &)> run_loop);

		// Destructor
		~GL();

		// Executes everything
		int run();

	};

	// Standard function object for registering a window class
	class DefRegisterClass{
	public:
		std::wstring operator()(GL &gl);
		DefRegisterClass();
		DefRegisterClass(WNDPROC win_proc_);

	private:
		WNDPROC win_proc;
	};

	class DefCreateWindow{
	public:
		void operator()(GL &gl, const std::wstring &className, int&
			width, int &height);
	};

	class DefSetupGL{
	public:
		void operator()(GL &gl);
	};

	class DefResize{
	public:
		void operator()(double width, double height);
	};

	class DefInitialize{
	public:
		void operator()(GL &gl);
	};

	// Standard class that contains a static function for handing
	// windows messages.
	class DefWinProc{
	public:
		static LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
	};

	// Converts win32 error messages to strings
	std::string format_message_win32(DWORD errorID);

}	// Namespace bj

#endif	GL_TEMPLATE_HPP


I was wondering if this is the correct way to go about it using the strategy pattern. If anyone could point out anything I did wrong, it would be greatly appreciated. Also just to clear it up, the strategy pattern IS composition?

PARTNERS