카테고리 없음

[FdF] MiniLibX mlx_pixel_put

Or71nH 2022. 6. 18. 12:39

이제 mlx_pixel_put이다

인자를 받아서 결과적으로 x,y에 색을 넣어주는 방식같다

음 코드에 일단 currenttext를 만드는데 음...

새 종이 가저오는건가?

void mlx_pixel_put(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, int x, int y, int color)
{
  if (!win_ptr->pixmgt)
    return ;
  [(id)(win_ptr->winid) selectGLContext];
  [(id)(win_ptr->winid) pixelPutColor:color X:x Y:y];
  win_ptr->nb_flush ++;
}

 

- (void) selectGLContext
{
  if ([NSOpenGLContext currentContext] != [self openGLContext])
    {
      //      printf("ctx: %p => %p\n", [NSOpenGLContext currentContext], [self openGLContext]);
      [[self openGLContext] makeCurrentContext];
    }
}
/* 
	makeCurrentContext 라는 함수를 실행하는데 그것으로 
https://developer.apple.com/documentation/appkit/nsopenglcontext/1436212-makecurrentcontext/
*/


- (void) pixelPutColor: (int)color X:(int)x Y:(int)y
{
  pixel_nb ++;

  glBindTexture(GL_TEXTURE_2D, pixel_vbuffer);
  glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)(&color));

  if (pixel_nb >= MAX_PIXEL_NB)
    [self mlx_gl_draw];
}
/*
	glBindTexture
	https://developer.apple.com/documentation/opengles/1617415-glbindtexture/
    glTexSubImage2D
    https://developer.apple.com/documentation/opengles/1617588-gltexsubimage2d/
    var GL_TEXTURE_2D: Int32 { get }
    https://developer.apple.com/documentation/opengles/gl_texture_2d/
    
    pixel_vbuffer 란??
    @interface MlxWin : NSOpenGLView
    {
      NSWindowEvent		*win;
      NSOpenGLContext	*ctx;
      glsl_info_t		glsl;
      int			openglwin;

      int			size_x;
      int			size_y;

      int			pixel_nb;
      GLuint		pixel_vbuffer; // pixel_vbuffer 가 있다
      //  typedef  GLuint; 이건 더이상 자세히 찾을수 없다
      GLuint		pixel_texture;
      unsigned int		*pixtexbuff;
    }
    mlx_ing.h 에
	#define MAX_PIXEL_NB	200000 가있음

*/

이게 색이 어떻게 넣어지는지 모르겟다 음..

예상인데여태 봐왓듯이 변수가 자동적으로 참조되며 GLuint ptxel_vbuffer를 불러오고

그것이 이미지 버퍼인거 같다 즉 종이

glBindTexture에서는 이 있던 종이를  GL_TEXTURE_2D에 복사 붙혀넣은 다음 그곳에 적어주는거 같은데

더이상 살펴 볼수가 없어서 이해를 못하겟다

glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)(&color));
서로 대조하여 볼수 있다
func glTexSubImage2D(
    _ target: GLenum,
    _ level: GLint,
    _ xoffset: GLint,
    _ yoffset: GLint,
    _ width: GLsizei,
    _ height: GLsizei,
    _ format: GLenum,
    _ type: GLenum,
    _ pixels: UnsafeRawPointer!
)
함수에 
종이
래벨???
위치 x
위치 y
크기 1
높이 1
포맷 GL_BGRA => 파랑그린래드 투명도 포맷
타입 GL_INSIGEND_BYTE  GL_TEXTURE_2D랑 같음 
pixels &color

넣어서 하나씩 바꾸는 거같다

사용 방법

#include <stdio.h>  // printf()
#include <stdlib.h> // exit()
#include <mlx.h>
int main(void)
{
	void *mlx_ptr;
	void *win_ptr;
	mlx_ptr = mlx_init();
	win_ptr = mlx_new_window(mlx_ptr, 300, 400, "Work???");
	mlx_clear_window(mlx_ptr, win_ptr);
	int x = 0;
	int y = 0;
	while (x < 100)
	{
		y = 0;
		while (y < 100)
		{
			mlx_pixel_put(mlx_ptr, win_ptr, x,y, 0x03ffffff);
			y++;
		}
	x++;
	}
	mlx_loop(win_ptr);
	return (0);
}