added color attribute and scissor clipping. Added debug callback to OpenGL messages
This commit is contained in:
@@ -5,8 +5,8 @@ App App::I; // singleton
|
||||
|
||||
void App::create()
|
||||
{
|
||||
width = 800;
|
||||
height = 800;
|
||||
width = 500;
|
||||
height = 500;
|
||||
}
|
||||
|
||||
void App::update_layout()
|
||||
@@ -99,18 +99,18 @@ void App::load_layout()
|
||||
//YGNodeStyleSetPositionType(y_root, YGPositionTypeRelative);
|
||||
while (child)
|
||||
{
|
||||
printf("Element %s: ", child->Name());
|
||||
auto y_node = YGNodeNew();
|
||||
stack.emplace(y_node, child);
|
||||
auto attr = child->FirstAttribute();
|
||||
std::unique_ptr<Plane> shape;
|
||||
if (strcmp("plane", child->Name()) == 0)
|
||||
{
|
||||
auto shape = std::make_unique<Plane>();
|
||||
//shape->create<5>(100.f, 100.f);
|
||||
shape = std::make_unique<Plane>();
|
||||
shape->create<5>(100.f, 100.f);
|
||||
shape->y_node = y_node;
|
||||
shapes_list.push_back(std::move(shape));
|
||||
YGNodeSetContext(y_node, shape.get());
|
||||
}
|
||||
printf("Element %s: ", child->Name());
|
||||
YGNodeStyleSetWidth(y_node, 0);
|
||||
YGNodeStyleSetWidthPercent(y_node, 100);
|
||||
YGNodeStyleSetHeight(y_node, 0);
|
||||
@@ -222,6 +222,22 @@ void App::load_layout()
|
||||
}
|
||||
break;
|
||||
}
|
||||
case att::kAttribute::Color:
|
||||
{
|
||||
glm::vec4 pad;
|
||||
int n = sscanf(attr->Value(), "%f %f %f %f", &pad.x, &pad.y, &pad.z, &pad.w);
|
||||
if (n == 1)
|
||||
{
|
||||
if (shape)
|
||||
shape->color = glm::vec4(pad.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shape)
|
||||
shape->color = pad;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -229,6 +245,8 @@ void App::load_layout()
|
||||
}
|
||||
int n = YGNodeGetChildCount(y_root);
|
||||
YGNodeInsertChild(y_root, y_node, n);
|
||||
if (shape)
|
||||
shapes_list.push_back(std::move(shape));
|
||||
child = child->NextSiblingElement();
|
||||
printf("\n");
|
||||
}
|
||||
@@ -281,6 +299,25 @@ void App::init()
|
||||
" frag = col;"
|
||||
"}";
|
||||
|
||||
static CONSOLE_SCREEN_BUFFER_INFO info;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
|
||||
// colors: http://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c
|
||||
glDebugMessageCallback([](GLenum source, GLenum type, GLuint id,
|
||||
GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
|
||||
{
|
||||
static std::map<GLenum, int> colors = {
|
||||
{ GL_DEBUG_SEVERITY_NOTIFICATION, 8 },
|
||||
{ GL_DEBUG_SEVERITY_LOW, 8 },
|
||||
{ GL_DEBUG_SEVERITY_MEDIUM, FOREGROUND_GREEN | FOREGROUND_INTENSITY },
|
||||
{ GL_DEBUG_SEVERITY_HIGH, FOREGROUND_RED | FOREGROUND_INTENSITY },
|
||||
};
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors[severity]);
|
||||
printf("%.*s\n", length, message);
|
||||
FlushConsoleInputBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), info.wAttributes);
|
||||
}, nullptr);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
|
||||
load_layout();
|
||||
|
||||
for (auto& s : shapes_list)
|
||||
@@ -306,10 +343,10 @@ void App::init()
|
||||
if (!tex.load("data/uvs.jpg"))
|
||||
printf("error loading image\n");
|
||||
|
||||
glEnable(GL_TEXTURE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glPointSize(5);
|
||||
glLineWidth(4);
|
||||
glLineWidth(2);
|
||||
|
||||
//int n;
|
||||
//glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
||||
@@ -383,15 +420,22 @@ void App::update(float dt)
|
||||
shader_color.use();
|
||||
shader_color.u_vec4("col", { .3f, .3f, .3f, 1 });
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
for (auto& s : shapes_list)
|
||||
{
|
||||
float w = YGNodeLayoutGetWidth(s->y_node);
|
||||
float h = YGNodeLayoutGetHeight(s->y_node);
|
||||
float x = YGNodeLayoutGetLeft(s->y_node);
|
||||
float y = YGNodeLayoutGetTop(s->y_node);
|
||||
auto layout = *reinterpret_cast<glm::vec4*>(YGNodeGetContext(s->y_node));
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
auto y_parent = YGNodeGetParent(s->y_node);
|
||||
if (y_parent && YGNodeGetContext(y_parent))
|
||||
{
|
||||
auto box = *reinterpret_cast<glm::vec4*>(YGNodeGetContext(y_parent));
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(box.x, height - box.y - 1 - box.w, box.z, box.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
//glScissor(10, height - 10 - 1 - 50, 480, 50);
|
||||
|
||||
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
||||
glm::mat4 scale = glm::scale(glm::vec3(layout.zw(), 1.f));
|
||||
@@ -402,6 +446,12 @@ void App::update(float dt)
|
||||
//shader_uv.u_mat4("mvp", mvp);
|
||||
//plane.draw_fill();
|
||||
|
||||
shader_color.u_vec4("col", s->color);
|
||||
shader_color.use();
|
||||
shader_color.u_mat4("mvp", mvp);
|
||||
plane.draw_fill();
|
||||
|
||||
shader_color.u_vec4("col", { 1, 1, 1, 1 });
|
||||
shader_color.use();
|
||||
shader_color.u_mat4("mvp", mvp);
|
||||
plane.draw_stroke();
|
||||
|
||||
Reference in New Issue
Block a user