Jump to content
  • Advertisement
Sign in to follow this  
Gumgo

OpenGL Scaling OpenGL context

This topic is 3697 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

Hi, I was wondering how to scale the OpenGL rendering context. For example, right now I have a 256x256 window and I want to scale it up to 512x512 but keep the actual rendering context size at 256x256 (that makes sense right?), so everything is drawn at double size. How would I go about doing this?

Share this post


Link to post
Share on other sites
Advertisement
You need to do 2 things. Make a function to handle the resize then tell glut the function that handles the resize.

To keep things in proportion you need to do something like this:
void handleResize(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}


To tell glut which function add this: glutReshapeFunc(handleResize); to main.

Share this post


Link to post
Share on other sites
The problem with that is I'm not using glut. Is there another way to do it?

Share this post


Link to post
Share on other sites
What are you using? SDL? Win32? wxWdigets? Whatever it is they'll have an equivalent way of handling window resizing so that code just needs to go in whatever function is called when it happens.

There's no actual GLUT specific code in there ;)

I'm a little confused as to your original request though. Do you want to make the window itself bigger but still render at 256x256 or do you want to render at 512x512 but keep the window at 256x256?

For the first one (which sounds the most likely) you could try something like this, though I can't remember if glViewport actually just affects the screen transformation.

EDIT I just checked and the code I posted earlier wouldn't work :/ glViewport does just perform the screen space transformation. Stupidly enough I've done this before unintentionally and now I really can't think how to do such a simple thing!

Andy

Share this post


Link to post
Share on other sites
Thanks for the responses. Win32, and I meant the first way. Anyway, I'm just rendering 2d so I'll use the ortho function instead of the perspective one. I'll try out that code tomorrow.

EDIT: I was thinking possibly, render to texture and draw that scaled 2x, but I'm guessing there's an easier way (I don't even know how to render to texture =b).

Share this post


Link to post
Share on other sites

case WM_SIZE:
// LOWORD =Width, HIWORD =Height
handleResize (LOWORD (lParam), HIWORD (lParam));
return 0;
break;




You can handle the WM_SIZE message in the windows message loop then, and just pass the two parts of the lParam to the methods that MrPickle supplied.

Andy

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!