Jump to content
  • Advertisement
Sign in to follow this  
AMike

OpenGL Scaling using glViewport - problems with glScissor

This topic is 3092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :(.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!