카테고리 없음

[FdF] MiniLibX mlx_destroy_window

Or71nH 2022. 6. 18. 09:50

mlx_new_window 마즈막 mlx_destroy_window

예도 좀 뭔가 많다


int     mlx_destroy_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_to_del)
{
  mlx_win_list_t    first;
  mlx_win_list_t    *win;
  mlx_img_ctx_t	    *ctx;
  mlx_img_ctx_t	    *ctx2;

  first.next = mlx_ptr->win_list; // 그 처번쟤 화면을 기억해둠
  win = &first;
  while (win && win->next)
    {
      if (win->next == win_to_del) // 삭제할 화면주소를 찾음!
	      win->next = win->next->next; // 중간 없에면서 이음
      win = win->next;
    }
  mlx_ptr->win_list = first.next;
  mlx_ptr->win_list = first.next;

  if (win_to_del->pixmgt) // 이거 만들때 1로 만들긴함
    {
      [(id)(win_to_del->winid) selectGLContext];
      ctx = win_to_del->img_list;   // should be null anyway if no pixel management
      /* 아직 img_list에 뭘 넣는걸 본적없다 다음에 나올듯 NULL들어가있음 만들땐*/
      while (ctx)
	{
	  glDeleteBuffers(1, &(ctx->vbuffer));
	  glDeleteTextures(1, &(ctx->texture));
      /*
      clear떄 있던 거임
      그떄는여러가지 다 지웟는데 이번엔 이것반 지우나봄
      https://developer.apple.com/documentation/opengles/1617677-gldeletebuffers/
      참고하면 되는데 이해가 안됨
      */
	  ctx2 = ctx;
	  ctx = ctx->next;
	  free(ctx2);
	}
      [(id)(win_to_del->winid) destroyPixelManagement];
      /* 아 여기서 다없에줌 */
    }
  [(id)(win_to_del->winid) destroyMe];
  free(win_to_del);

  //  printf("destroy window done.\n");
  mlx_do_sync(mlx_ptr); // 이건 mlx_init_loop 파일에 있는 함수
  
  return (0);
}
- (void) selectGLContext
{
  if ([NSOpenGLContext currentContext] != [self openGLContext])
    {
      //      printf("ctx: %p => %p\n", [NSOpenGLContext currentContext], [self openGLContext]);
      [[self openGLContext] makeCurrentContext];
    }
}

# mlx_init_loop

int     mlx_do_sync(mlx_ptr_t *mlx_ptr)
{
  mlx_win_list_t *win;

  win = mlx_ptr->win_list;
  while (win)
    {
      if (win->pixmgt)
	{
	  [(id)(win->winid) selectGLContext];
	  [(id)(win->winid) mlx_gl_draw];
	  glFlush();
	  if (!mlx_ptr->main_loop_active)
	    mlx_int_loop_once();
	}
      win = win->next;
    }
  return (0);
}

// 음 뭔가  NSApp이 모든걸 하는느낌
//https://developer.apple.com/documentation/appkit/nsapp/
void	mlx_int_loop_once()
{
  NSEvent *event;
  NSDate  *thedate;

  thedate = [NSDate dateWithTimeIntervalSinceNow:0.1];
  while (42)
    {
      event = [NSApp nextEventMatchingMask:NSEventMaskAny
		     untilDate:thedate
		     inMode:NSDefaultRunLoopMode
		     dequeue:YES];
      if (event == nil)
	{
	  [thedate release];
	  return ;
	}
      [NSApp sendEvent:event];
      [NSApp updateWindows];
    }
}

음 결과적으로는 삭제해주는데