Notice
Recent Posts
Recent Comments
Link
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Longseabear DevLog

Color struct 만들기 본문

Graphics Project

Color struct 만들기

longseabear 2023. 1. 31. 02:03

평화롭게 Texture 편을 학습하며 Texture를 관리하는 class를 만들고 있었는데, 만들다보니 unity의 Texture2D에 있던 멤버 변수들이 이해가 되는게 아니던가(mipCount 라던지). 이를 경험하고나니 내 코드를 좀 더 unity 처럼 구조적으로 관리하고 싶어졌다.

이를 위해 가장 기본적인 color struct를 만들어봤다. color 구조체에 대한 내용은 unity API 문서를 대충 참고하여 만들어봤다.

Color.h
#pragma once

#define MAKE_COLOR_STATIC_VALUE(color, r,g,b,a) const Color Color::color = {r,g,b,a};
namespace LEapsGL {
    union Color {
        struct { float r, g, b, a; };
        float values[4];

        static const Color black;
        static const Color blue;
        static const Color clear;
        static const Color cyan;
        static const Color gray;
        static const Color green;
        static const Color grey;
        static const Color magenta;
        static const Color red;
        static const Color white;
        static const Color yellow;
    };
    MAKE_COLOR_STATIC_VALUE(black, 0.0f, 0.0f, 0.0f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(blue, 0.0f, 0.0f, 1.0f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(clear, 0.0f, 0.0f, 0.0f, 0.0f);
    MAKE_COLOR_STATIC_VALUE(cyan, 0.0f, 1.0f, 1.0f, 0.0f);
    MAKE_COLOR_STATIC_VALUE(gray, 0.5f, 0.5f, 0.5f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(green, 0.0f, 0.1f, 0.0f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(grey, 0.5f, 0.5f, 0.5f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(magenta, 1.0f, 0.0f, 1.0f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(red, 1.0f, 0.0f, 0.0f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(white, 1.0f, 1.0f, 1.0f, 1.0f);
    MAKE_COLOR_STATIC_VALUE(yellow, 1.0f, 0.92f, 0.016f, 1.0f);
};

c++에서 정적 멤버 변수는 외부에서 정의해줘야함에 주의하자. 내부에서는 선언만 해주자. 이렇게 하면 Color::black 형식으로 접근할 수 있다!

 

재밌는 점은 yello인데, 우리가 알고있는 (1.0f, 1.0f, 0.0f, 1.0f) 가 아니다. Unity API 문서에서 이게 더 yello 스럽단다. (Yellow. RGBA is (1, 0.92, 0.016, 1), but the color is nice to look at! 라고 써있다)

두 차이를 목도해보자.

 

으아아아아ㅏ (0xFFFF00)

으아아아아ㅏ (0xFFEA04)

 

눈 아픔이 감소한다.

'Graphics Project' 카테고리의 다른 글

Voronoi noise 파헤치기  (0) 2024.10.27
나만의 Texture2D class 만들기  (0) 2023.02.01
Shader program wrapper class  (0) 2023.01.28
Opengl 3.3 시작  (0) 2023.01.28