I’m writing an object oriented openGL application, which renders some 3D models (which are stored in my own classes with several attributes and methods). One of these object types (with volume rendering shader) require that I render the output to a fixed size texture first (say 256*256), then restore the previous viewport size and stretch this texture over the screen in 2D.
The actual problem is that I can’t get the actual viewport size from inside this object, unless (I guess) I store a reference to the GLEventListener’s GLU object, which I obviously don’t want for each and every model I create.
But I also don’t want to have static variables in the GLEventListener (what if I want an app which has 2 canvases?)
The most important is the viewport dimensions, but I think I’ll also need to reference my custom Camera object. How can I do this without using static somehow?
First, please read http://www.opengl.org/wiki/Common_Mistakes#The_Object_Oriented_Language_Problem
Next I point you to the function
glGetIntegervon the token GL_VIEWPORT.