Hi all, I’m kind of new to OpenGL so please bear with me if you will. And excuse my stupidity if it anything I say seem to be such. I’m working on a program where I want to draw a grid in a glut window. However, I want to limit the viewing portion of the grid. I am using this to initialize my world window and viewport:
now the problem is no matter how I change the glViewport function my viewing area still takes up the whole glut window(which basically fills a 50x50 square grid on the entire window.) but what I want is for this grid to be drawn within what my viewport had defined. so any clue where I’m doing it wrong? You help is much appreciated…
Well that’s exactly what I want to do. I want to create a world window that is just 50x50. And have the viewport to take care whatever that is needed to expand this 50x50 window into a 500x500 window. The problem is my actual GLUT window is 600x600 and I want a drawing area of 500x500 within this 600x600 window. But it just keep drawing under the area (or using the viewport) that is set by defult, namely the actual 600x600 window… any idea why?
In the code you have posted I don’t see any obvious problem. It should work as you describe. Therefore the error must exist elsewhere in your code. Are you certain you aren’t resetting the viewport at some other point in time? Are you also certain that the viewport is successfully set in the resize function? Check for gl error codes to see if glViewport failed.
glViewport in resize function? But i don’t resize my window though. Hm… I’ve been looking at this for quite awhile and I still don’t see the error codes… but here’s my program.
Ok, so now its obvious why it isn’t working. The viewport is being reset because you haven’t specified a resize function. At least define a dummy resize function so glut doesn’t call its default resize (reshape) function in which it resets the viewport. You should define more than a dummy resize function, if you properly want to handle resizing, otherwise disable window resizing.