Sign in to follow this  
Redgeneral

opengl not filling window

Recommended Posts

Redgeneral    122
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

Share this post


Link to post
Share on other sites
Lyost    328
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);

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this