opengl not filling window

Started by
3 comments, last by RipTorn 18 years, 9 months ago
Instead of filling the entire window, is it possible to have just the opgenl scene occupying a set rect within the window I tried with mfc as a solution (as suggested before) and got too frustrated. I imgaine it could be done by setting a rect and then setting an hglrc to that rect but I am not sure how. Could anyone help with this? Thank you
Advertisement
You can adjust the values passed to the call to glViewport. The typical values if you want to use the entire window is 0 (leftmost x value in pixels), 0 (topmost y value in pixels), window_size_x (rightmost x value in pixels), window_size_y (bottommost y value in pixels). So change the value of whichever one you need to. However, once you do that, you should call gluPerspective (or an equiviant function). Here's a code exept from a program where I needed to do it for creating a side bar.

glViewport(size_x - sep_x,0,sep_x,size_y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,(size_x - sep_x)/(GLfloat)size_y,.1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_DEPTH_BUFFER_BIT);
Remember to SwapBuffer(..)!!

Maybe..
Thank you, that seems to have worked

Out of curriosity though, does the coding as it stands, draw on the window where there isn't a scene. I.E. window background is set to white and yet it appears the same colour as the opengl

Just wondering if somehow telling it to only draw and refresh the bit with the scene will ease up the system resources. I ask this because the parts without the scene are covered anyway by internal dialogues which handel all the controls.
It's been a very very long time since i did any win32 C++ programming, but in .net at least, the way you would do what you ask is to attach the opengl device to a picture box form inside you window.. not the window itself.
If you are using, say, the visual studio designer to make your forms, then you could just add a picture box in, set it to user drawn, then use the HWND, etc, from that when creating your opengl context, etc.

I guess...

(thoughts anyone?)

yes when you use glViewport you are only restricting rendering to a set area, you are not disabling the rest of that area. It's still part of the back/front buffer.

This topic is closed to new replies.

Advertisement