hockeyman
hockeyman

Reputation: 1183

Update NSOpenGLView size

I want to update my NSOpenGLView window when texture size is changed. Thats OK. I register event when that happens, but I can't resize OpenGLView. Value witch is being changed is w and h.

-(void)initOpenGL {
NSSize size = {w, h};
[self setFrameSize:size];
NSOpenGLContext *glcontext;
glcontext = [self openGLContext];
[glcontext makeCurrentContext];
glMatrixMode(GL_PROJECTION);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);               
glOrtho(0.0, h, 0.0, w, -1.0, 10.0); 
}

When application starts it works OK, but when I do [self initOpenGL] after any of these size changed, OpenGL view is getting black, and not working any more.

Upvotes: 0

Views: 1549

Answers (3)

hockeyman
hockeyman

Reputation: 1183

If anyone will meet this problem just add glLoadIdentity(); at the beginning of OpenGL initialization.

Upvotes: 1

TheAmateurProgrammer
TheAmateurProgrammer

Reputation: 9392

If you're using a NSOpenGLView, then there's a method called reshape which gets called when the view is being reshaped. There, you should call glViewport and update the size accordingly.

Upvotes: 1

andyvn22
andyvn22

Reputation: 14824

You may need to call [glcontext update] and glViewport(0,0,oglWidth,oglHeight) to adjust for the change in view size.

Upvotes: 1

Related Questions