Scaling OpenGL context

Started by
5 comments, last by NineYearCycle 15 years, 11 months ago
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?
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.
Here to learn :)
The problem with that is I'm not using glut. Is there another way to do it?
I don't know of any other ways, sorry.
Here to learn :)
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

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

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).
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

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

This topic is closed to new replies.

Advertisement