Scaling using glViewport - problems with glScissor

Started by
1 comment, last by AMike 14 years, 1 month ago
Hello, in my application I'm using a small OpenGL based 2D-GUI framework to create a 800x480 pixels user interface. The positions and dimensions of the GUI controls are set to absolute pixel values and everything works fine. But now I have the requirement to resize the GUI by a factor of 0.85 (680x408 pixels) in a possibly quickest way. My idea was to leave the GUI setup unchanged and just to set the OpenGL viewport to the new values, thus scaling the GUI to 680x408 pixels without having to change (almost) anything. This approach partly worked and now I'm only having problems with GUI controls which use clipping, which is implemented by glScissor calls. I resized scissor box passed to OpenGL by 0.85, but the clipping still doesn't work like it should. This is the code I'm using.

// set viewport
glViewport(0, 0, 680, 408);

// ---- begin GUI framework code -----

// switch to projection mode
glMatrixMode(GL_PROJECTION);

// store old matrix
glPushMatrix();

// load identity matrix
glLoadIdentity();

// switch to orthogonal projection
glOrthof(0, 800, 0, 480, 0.0, 1.0);

// switch to model view
glMatrixMode(GL_MODELVIEW);

// store old matrix
glPushMatrix();

// load identity matrix
glLoadIdentity();

// do other things
....
	
// enable scissor test
glEnable(GL_SCISSOR_TEST);

// define scissor
//glScissor(controlPosX, controlPosY, controlWidth, controlHeight); // old version 
glScissor(controlPosX*0.85, controlPosY*0.85, controlWidth*0.85, controlHeight*0.85); // new version 
	
// draw control
....

// switch to projection mode
glMatrixMode(GL_PROJECTION);

// restore old projection matrix 
glPopMatrix();

// switch to model view
glMatrixMode(GL_MODELVIEW);

// restore old matrix of model view
glPopMatrix();

// ---- end GUI framework code ----

// swap buffers
....

Has anyone an idea why I'm getting wrong clipping results? Mike
Advertisement
Quote:Original post by AMike
I resized scissor box passed to OpenGL by 0.85, but the clipping still doesn't work like it should.


IIRC, scissor works in window coordinates. It sounds like previously you had world coords and window coords matched up. Since they don't match any more you'll have to back-project your control's bounds via the modelview and viewport matrices to calculate the actual screen coords for the scissor.
Quote:Original post by OrangyTang
IIRC, scissor works in window coordinates. It sounds like previously you had world coords and window coords matched up. Since they don't match any more you'll have to back-project your control's bounds via the modelview and viewport matrices to calculate the actual screen coords for the scissor.


This is why I tried in the first place to adjust the scissor coordinates by multiplying them by 0.85. But to be sure I have projected the control's bounds using gluProject() and the current projection, modelview and viewport matrices and got the same values as if simply multiplying by 0.85. So now I'm stuck again :(.

This topic is closed to new replies.

Advertisement